Loading mysql-test/r/func_gconcat.result +15 −9 Original line number Diff line number Diff line Loading @@ -285,15 +285,21 @@ insert into t2 values (1, 5), (2, 4), (3, 3), (3,3); select group_concat(c) from t1; group_concat(c) 2,3,4,5 select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1; grp 5,4,3,2 select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1; grp 5,4,3,2 select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1; grp 2,4,3,5 select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1; a grp 1 2 2 4,3 3 5 select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1; a grp 1 2 2 4,3 3 5 select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1; a grp 1 2 2 4,3 3 5 select a,c,(select group_concat(c order by a) from t2 where a=t1.a) as grp from t1 order by grp; a c grp 3 5 3,3 Loading mysql-test/r/subselect.result +43 −0 Original line number Diff line number Diff line Loading @@ -1912,3 +1912,46 @@ a 1 2 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; CREATE TABLE t1 (howmanyvalues bigint, avalue int); INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4); SELECT howmanyvalues, count(*) from t1 group by howmanyvalues; howmanyvalues count(*) 1 1 2 2 3 3 4 4 SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; howmanyvalues mycount 1 1 2 2 3 3 4 4 CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues); SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues; howmanyvalues mycount 1 1 2 2 3 3 4 4 drop table t1; mysql-test/t/func_gconcat.test +3 −3 Original line number Diff line number Diff line Loading @@ -168,10 +168,10 @@ insert into t1 values (1, 2), (2, 3), (2, 4), (3, 5); create table t2 (a int, c int); insert into t2 values (1, 5), (2, 4), (3, 3), (3,3); select group_concat(c) from t1; select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1; select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1; select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1; select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1; select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1; select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1; # The following returns random results as we are sorting on blob addresses # select group_concat(c order by (select group_concat(c order by a) from t2 where t2.a=t1.a)) as grp from t1; Loading mysql-test/t/subselect.test +25 −0 Original line number Diff line number Diff line Loading @@ -1234,4 +1234,29 @@ select a,b from t1 where match(b) against ('Ball') > 0; select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0); 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; # # resolving fields of grouped outer SELECT # CREATE TABLE t1 (howmanyvalues bigint, avalue int); INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4); SELECT howmanyvalues, count(*) from t1 group by howmanyvalues; SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues); SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues; drop table t1; sql/item.cc +46 −24 Original line number Diff line number Diff line Loading @@ -60,10 +60,10 @@ Item::Item(): */ if (thd->lex->current_select) { SELECT_LEX_NODE::enum_parsing_place place= enum_parsing_place place= thd->lex->current_select->parsing_place; if (place == SELECT_LEX_NODE::SELECT_LIST || place == SELECT_LEX_NODE::IN_HAVING) if (place == SELECT_LIST || place == IN_HAVING) thd->lex->current_select->select_n_having_items++; } } Loading Loading @@ -1233,12 +1233,25 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) table_list= (last= sl)->get_table_list(); if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list) { // it is primary INSERT st_select_lex => skip first table resolving /* it is primary INSERT st_select_lex => skip first table resolving */ table_list= table_list->next; } Item_subselect *prev_subselect_item= prev_unit->item; if ((tmp= find_field_in_tables(thd, this, enum_parsing_place place= prev_subselect_item->parsing_place; /* check table fields only if subquery used somewhere out of HAVING or SELECT list or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, 0)) != not_found_field) { Loading Loading @@ -1906,7 +1919,17 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) // it is primary INSERT st_select_lex => skip first table resolving table_list= table_list->next; } if ((tmp= find_field_in_tables(thd, this, enum_parsing_place place= prev_subselect_item->parsing_place; /* check table fields only if subquery used somewhere out of HAVING or SELECT list or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, 0)) != not_found_field) { Loading @@ -1914,7 +1937,6 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) prev_subselect_item->const_item_cache= 0; break; } // Reference is not found => depend from outer (or just error) prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT; prev_subselect_item->const_item_cache= 0; Loading Loading
mysql-test/r/func_gconcat.result +15 −9 Original line number Diff line number Diff line Loading @@ -285,15 +285,21 @@ insert into t2 values (1, 5), (2, 4), (3, 3), (3,3); select group_concat(c) from t1; group_concat(c) 2,3,4,5 select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1; grp 5,4,3,2 select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1; grp 5,4,3,2 select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1; grp 2,4,3,5 select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1; a grp 1 2 2 4,3 3 5 select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1; a grp 1 2 2 4,3 3 5 select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1; a grp 1 2 2 4,3 3 5 select a,c,(select group_concat(c order by a) from t2 where a=t1.a) as grp from t1 order by grp; a c grp 3 5 3,3 Loading
mysql-test/r/subselect.result +43 −0 Original line number Diff line number Diff line Loading @@ -1912,3 +1912,46 @@ a 1 2 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; CREATE TABLE t1 (howmanyvalues bigint, avalue int); INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4); SELECT howmanyvalues, count(*) from t1 group by howmanyvalues; howmanyvalues count(*) 1 1 2 2 3 3 4 4 SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; howmanyvalues mycount 1 1 2 2 3 3 4 4 CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues); SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues; howmanyvalues mycount 1 1 2 2 3 3 4 4 drop table t1;
mysql-test/t/func_gconcat.test +3 −3 Original line number Diff line number Diff line Loading @@ -168,10 +168,10 @@ insert into t1 values (1, 2), (2, 3), (2, 4), (3, 5); create table t2 (a int, c int); insert into t2 values (1, 5), (2, 4), (3, 3), (3,3); select group_concat(c) from t1; select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1; select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1; select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1; select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1; select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1; select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1; # The following returns random results as we are sorting on blob addresses # select group_concat(c order by (select group_concat(c order by a) from t2 where t2.a=t1.a)) as grp from t1; Loading
mysql-test/t/subselect.test +25 −0 Original line number Diff line number Diff line Loading @@ -1234,4 +1234,29 @@ select a,b from t1 where match(b) against ('Ball') > 0; select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0); 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; # # resolving fields of grouped outer SELECT # CREATE TABLE t1 (howmanyvalues bigint, avalue int); INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4); SELECT howmanyvalues, count(*) from t1 group by howmanyvalues; SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues); SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues; drop table t1;
sql/item.cc +46 −24 Original line number Diff line number Diff line Loading @@ -60,10 +60,10 @@ Item::Item(): */ if (thd->lex->current_select) { SELECT_LEX_NODE::enum_parsing_place place= enum_parsing_place place= thd->lex->current_select->parsing_place; if (place == SELECT_LEX_NODE::SELECT_LIST || place == SELECT_LEX_NODE::IN_HAVING) if (place == SELECT_LIST || place == IN_HAVING) thd->lex->current_select->select_n_having_items++; } } Loading Loading @@ -1233,12 +1233,25 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) table_list= (last= sl)->get_table_list(); if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list) { // it is primary INSERT st_select_lex => skip first table resolving /* it is primary INSERT st_select_lex => skip first table resolving */ table_list= table_list->next; } Item_subselect *prev_subselect_item= prev_unit->item; if ((tmp= find_field_in_tables(thd, this, enum_parsing_place place= prev_subselect_item->parsing_place; /* check table fields only if subquery used somewhere out of HAVING or SELECT list or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, 0)) != not_found_field) { Loading Loading @@ -1906,7 +1919,17 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) // it is primary INSERT st_select_lex => skip first table resolving table_list= table_list->next; } if ((tmp= find_field_in_tables(thd, this, enum_parsing_place place= prev_subselect_item->parsing_place; /* check table fields only if subquery used somewhere out of HAVING or SELECT list or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, 0)) != not_found_field) { Loading @@ -1914,7 +1937,6 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) prev_subselect_item->const_item_cache= 0; break; } // Reference is not found => depend from outer (or just error) prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT; prev_subselect_item->const_item_cache= 0; Loading