diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index ef4da19c826f4eb5dfa9519cb333d19abf1ede88..5a8ff20aa33f60800c99d0f43f37edb3a46874ae 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -30,6 +30,8 @@ Unknown column 'a' in 'field list' SELECT 1 as a FROM (SELECT 1) HAVING (SELECT a)=1; a 1 +SELECT 1 FROM (SELECT (SELECT a)); +Unknown column 'a' in 'field list' drop table if exists t1,t2,t3,t4,t5,t6,t7,t8; create table t1 (a int); create table t2 (a int, b int); diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 6d4fc7de30b9b9081c20623b368e5c2ee70dfb35..00f3a4f6e445df96523b12cc7e1d114ccc9dd89a 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -13,6 +13,8 @@ SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1; -- error 1054 SELECT (SELECT 1), a; SELECT 1 as a FROM (SELECT 1) HAVING (SELECT a)=1; +-- error 1054 +SELECT 1 FROM (SELECT (SELECT a)); drop table if exists t1,t2,t3,t4,t5,t6,t7,t8; create table t1 (a int); create table t2 (a int, b int); diff --git a/sql/item.cc b/sql/item.cc index 13433990107fdf218d2cc9c1e0ff019c5138e336..df42b9185ccf82c8defb3975b75cbeaf7ac9fa89 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -472,7 +472,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) REPORT_EXCEPT_NOT_FOUND)) != (Item **)not_found_item) break; - + if (sl->linkage == DERIVED_TABLE_TYPE) + break; // do not look over derived table } if (!tmp) return -1; @@ -887,6 +888,8 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) if ((tmp= find_field_in_tables(thd, this, sl->get_table_list(), 0)) != not_found_field); + if (sl->linkage == DERIVED_TABLE_TYPE) + break; // do not look over derived table } if (!ref)