diff options
-rw-r--r-- | mysql-test/r/subselect.result | 10 | ||||
-rw-r--r-- | mysql-test/t/subselect.test | 5 | ||||
-rw-r--r-- | sql/item.cc | 10 | ||||
-rw-r--r-- | sql/item_subselect.cc | 3 | ||||
-rw-r--r-- | sql/sql_base.cc | 6 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
6 files changed, 24 insertions, 12 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index ff5c9dfe813..7826f5e452d 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -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; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 7fcd0565ae7..2dc28479ee9 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -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; diff --git a/sql/item.cc b/sql/item.cc index e9ef3b6a763..d6ed65589f7 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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, @@ -1952,8 +1951,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, diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 8d140efac5f..3ddf9a1c6bf 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -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); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index ac5008717e6..f938847ce68 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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 && diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f3eed672231..454fab1a88d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8466,6 +8466,8 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, } } else if ((pos->type() == Item::FUNC_ITEM || + pos->type() == Item::SUBSELECT_ITEM || + pos->type() == Item::CACHE_ITEM || pos->type() == Item::COND_ITEM) && !pos->with_sum_func) { // Save for send fields |