Loading mysql-test/r/subselect.result +9 −1 Original line number Diff line number Diff line Loading @@ -1966,5 +1966,13 @@ howmanyvalues mycount 3 3 4 4 SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues; ERROR 42S22: Unknown column 'a.avalue' in 'where clause' howmanyvalues mycount 1 1 2 1 3 1 4 1 drop table t1; create table t1 (x int); select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; (select b.x from t1 as b where b.x=a.x) drop table t1; mysql-test/t/subselect.test +4 −1 Original line number Diff line number Diff line Loading @@ -1264,6 +1264,9 @@ SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.how 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; SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; -- error 1054 SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues; drop table t1; create table t1 (x int); select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; drop table t1; sql/item.cc +4 −6 Original line number Diff line number Diff line Loading @@ -1271,11 +1271,10 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) 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) or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || if ((place != IN_HAVING || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, Loading Loading @@ -1954,8 +1953,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) or SELECT list or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || if ((place != IN_HAVING || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, Loading sql/item_subselect.cc +0 −3 Original line number Diff line number Diff line Loading @@ -934,9 +934,6 @@ Item_in_subselect::row_value_transformer(JOIN *join) } select_lex->uncacheable|= UNCACHEABLE_DEPENDENT; select_lex->setup_ref_array(thd, select_lex->order_list.elements + select_lex->group_list.elements); { uint n= left_expr->cols(); List_iterator_fast<Item> li(select_lex->item_list); Loading sql/sql_base.cc +5 −1 Original line number Diff line number Diff line Loading @@ -2142,8 +2142,12 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, case sensitive. In cases where they are not case sensitive, they are always in lower case. item_field->field_name and item_field->table_name can be 0x0 if item is not fix fielded yet. */ if (!my_strcasecmp(system_charset_info, item_field->field_name, if (item_field->field_name && item_field->table_name && !my_strcasecmp(system_charset_info, item_field->field_name, field_name) && !strcmp(item_field->table_name, table_name) && (!db_name || (item_field->db_name && Loading Loading
mysql-test/r/subselect.result +9 −1 Original line number Diff line number Diff line Loading @@ -1966,5 +1966,13 @@ howmanyvalues mycount 3 3 4 4 SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues; ERROR 42S22: Unknown column 'a.avalue' in 'where clause' howmanyvalues mycount 1 1 2 1 3 1 4 1 drop table t1; create table t1 (x int); select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; (select b.x from t1 as b where b.x=a.x) drop table t1;
mysql-test/t/subselect.test +4 −1 Original line number Diff line number Diff line Loading @@ -1264,6 +1264,9 @@ SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.how 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; SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; -- error 1054 SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues; drop table t1; create table t1 (x int); select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; drop table t1;
sql/item.cc +4 −6 Original line number Diff line number Diff line Loading @@ -1271,11 +1271,10 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) 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) or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || if ((place != IN_HAVING || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, Loading Loading @@ -1954,8 +1953,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) or SELECT list or outer SELECT do not use groupping (i.e. tables are accessable) */ if (((place != IN_HAVING && place != SELECT_LIST) || if ((place != IN_HAVING || (sl->with_sum_func == 0 && sl->group_list.elements == 0)) && (tmp= find_field_in_tables(thd, this, table_list, &where, Loading
sql/item_subselect.cc +0 −3 Original line number Diff line number Diff line Loading @@ -934,9 +934,6 @@ Item_in_subselect::row_value_transformer(JOIN *join) } select_lex->uncacheable|= UNCACHEABLE_DEPENDENT; select_lex->setup_ref_array(thd, select_lex->order_list.elements + select_lex->group_list.elements); { uint n= left_expr->cols(); List_iterator_fast<Item> li(select_lex->item_list); Loading
sql/sql_base.cc +5 −1 Original line number Diff line number Diff line Loading @@ -2142,8 +2142,12 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, case sensitive. In cases where they are not case sensitive, they are always in lower case. item_field->field_name and item_field->table_name can be 0x0 if item is not fix fielded yet. */ if (!my_strcasecmp(system_charset_info, item_field->field_name, if (item_field->field_name && item_field->table_name && !my_strcasecmp(system_charset_info, item_field->field_name, field_name) && !strcmp(item_field->table_name, table_name) && (!db_name || (item_field->db_name && Loading