Loading mysql-test/r/subselect.result +21 −0 Original line number Diff line number Diff line Loading @@ -1899,3 +1899,24 @@ select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL ( a C 1 1 drop table t1,t2; CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); insert into t1 values (1,1),(1,2),(2,1),(2,2); insert into t2 values (1,2),(2,2); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); aid bid 1 1 2 1 alter table t2 drop primary key; alter table t2 add key KEY1 (aid, bid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); aid bid 1 1 2 1 alter table t2 drop key KEY1; alter table t2 add primary key (bid, aid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); aid bid 1 1 2 1 drop table t1,t2; mysql-test/t/subselect.test +16 −0 Original line number Diff line number Diff line Loading @@ -1222,3 +1222,19 @@ CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=M insert into t2 values (1,2); select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1); drop table t1,t2; # # Optimized IN with compound index # CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); insert into t1 values (1,1),(1,2),(2,1),(2,2); insert into t2 values (1,2),(2,2); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); alter table t2 drop primary key; alter table t2 add key KEY1 (aid, bid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); alter table t2 drop key KEY1; alter table t2 add primary key (bid, aid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); drop table t1,t2; sql/item_subselect.cc +64 −61 Original line number Diff line number Diff line Loading @@ -1243,13 +1243,15 @@ int subselect_uniquesubquery_engine::exec() DBUG_ENTER("subselect_uniquesubquery_engine::exec"); int error; TABLE *table= tab->table; if ((tab->ref.key_err= (*tab->ref.key_copy)->copy())) for (store_key **copy=tab->ref.key_copy ; *copy ; copy++) { if (tab->ref.key_err= (*copy)->copy()) { table->status= STATUS_NOT_FOUND; error= -1; DBUG_RETURN(1); } else { } if (!table->file->inited) table->file->ha_index_init(tab->ref.key); error= table->file->index_read(table->record[0], Loading @@ -1265,7 +1267,7 @@ int subselect_uniquesubquery_engine::exec() (!cond || cond->val_int()) ? 1 : 0); } } DBUG_RETURN(error != 0); } Loading Loading @@ -1293,13 +1295,15 @@ int subselect_indexsubquery_engine::exec() ((Item_in_subselect *) item)->was_null= 0; } if ((*tab->ref.key_copy) && (tab->ref.key_err= (*tab->ref.key_copy)->copy())) for (store_key **copy=tab->ref.key_copy ; *copy ; copy++) { if (tab->ref.key_err= (*copy)->copy()) { table->status= STATUS_NOT_FOUND; error= -1; DBUG_RETURN(1); } else { } if (!table->file->inited) table->file->ha_index_init(tab->ref.key); error= table->file->index_read(table->record[0], Loading Loading @@ -1344,7 +1348,6 @@ int subselect_indexsubquery_engine::exec() } } } } DBUG_RETURN(error != 0); } Loading Loading
mysql-test/r/subselect.result +21 −0 Original line number Diff line number Diff line Loading @@ -1899,3 +1899,24 @@ select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL ( a C 1 1 drop table t1,t2; CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); insert into t1 values (1,1),(1,2),(2,1),(2,2); insert into t2 values (1,2),(2,2); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); aid bid 1 1 2 1 alter table t2 drop primary key; alter table t2 add key KEY1 (aid, bid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); aid bid 1 1 2 1 alter table t2 drop key KEY1; alter table t2 add primary key (bid, aid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); aid bid 1 1 2 1 drop table t1,t2;
mysql-test/t/subselect.test +16 −0 Original line number Diff line number Diff line Loading @@ -1222,3 +1222,19 @@ CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=M insert into t2 values (1,2); select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1); drop table t1,t2; # # Optimized IN with compound index # CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); insert into t1 values (1,1),(1,2),(2,1),(2,2); insert into t2 values (1,2),(2,2); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); alter table t2 drop primary key; alter table t2 add key KEY1 (aid, bid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); alter table t2 drop key KEY1; alter table t2 add primary key (bid, aid); select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); drop table t1,t2;
sql/item_subselect.cc +64 −61 Original line number Diff line number Diff line Loading @@ -1243,13 +1243,15 @@ int subselect_uniquesubquery_engine::exec() DBUG_ENTER("subselect_uniquesubquery_engine::exec"); int error; TABLE *table= tab->table; if ((tab->ref.key_err= (*tab->ref.key_copy)->copy())) for (store_key **copy=tab->ref.key_copy ; *copy ; copy++) { if (tab->ref.key_err= (*copy)->copy()) { table->status= STATUS_NOT_FOUND; error= -1; DBUG_RETURN(1); } else { } if (!table->file->inited) table->file->ha_index_init(tab->ref.key); error= table->file->index_read(table->record[0], Loading @@ -1265,7 +1267,7 @@ int subselect_uniquesubquery_engine::exec() (!cond || cond->val_int()) ? 1 : 0); } } DBUG_RETURN(error != 0); } Loading Loading @@ -1293,13 +1295,15 @@ int subselect_indexsubquery_engine::exec() ((Item_in_subselect *) item)->was_null= 0; } if ((*tab->ref.key_copy) && (tab->ref.key_err= (*tab->ref.key_copy)->copy())) for (store_key **copy=tab->ref.key_copy ; *copy ; copy++) { if (tab->ref.key_err= (*copy)->copy()) { table->status= STATUS_NOT_FOUND; error= -1; DBUG_RETURN(1); } else { } if (!table->file->inited) table->file->ha_index_init(tab->ref.key); error= table->file->index_read(table->record[0], Loading Loading @@ -1344,7 +1348,6 @@ int subselect_indexsubquery_engine::exec() } } } } DBUG_RETURN(error != 0); } Loading