Commit 65e12f2f authored by unknown's avatar unknown

fixed derived table visibility scope for derived tables with union


mysql-test/r/derived.result:
  test of error messages
mysql-test/t/derived.test:
   SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b;
parent fddbc989
SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b;
Unknown column 'a' in 'field list'
SELECT 1 as a FROM (SELECT a UNION SELECT 1) b;
Unknown column 'a' in 'field list'
drop table if exists t1,t2,t3; drop table if exists t1,t2,t3;
CREATE TABLE t1 (a int not null, b char (10) not null); CREATE TABLE t1 (a int not null, b char (10) not null);
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
......
-- error 1054
SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b;
-- error 1054
SELECT 1 as a FROM (SELECT a UNION SELECT 1) b;
drop table if exists t1,t2,t3; drop table if exists t1,t2,t3;
CREATE TABLE t1 (a int not null, b char (10) not null); CREATE TABLE t1 (a int not null, b char (10) not null);
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
......
...@@ -573,7 +573,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -573,7 +573,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
Item **refer= (Item **)not_found_item; Item **refer= (Item **)not_found_item;
// Prevent using outer fields in subselects, that is not supported now // Prevent using outer fields in subselects, that is not supported now
SELECT_LEX *cursel=(SELECT_LEX *) thd->lex.current_select; SELECT_LEX *cursel=(SELECT_LEX *) thd->lex.current_select;
if (cursel->linkage != DERIVED_TABLE_TYPE) if (cursel->master_unit()->first_select()->linkage !=
DERIVED_TABLE_TYPE)
for (SELECT_LEX *sl=cursel->outer_select(); for (SELECT_LEX *sl=cursel->outer_select();
sl; sl;
sl= sl->outer_select()) sl= sl->outer_select())
...@@ -586,7 +587,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -586,7 +587,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
REPORT_EXCEPT_NOT_FOUND)) != REPORT_EXCEPT_NOT_FOUND)) !=
(Item **)not_found_item) (Item **)not_found_item)
break; break;
if (sl->linkage == DERIVED_TABLE_TYPE) if (sl->master_unit()->first_select()->linkage ==
DERIVED_TABLE_TYPE)
break; // do not look over derived table break; // do not look over derived table
} }
if (!tmp) if (!tmp)
...@@ -1024,7 +1026,8 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) ...@@ -1024,7 +1026,8 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
if ((ref= find_item_in_list(this, if ((ref= find_item_in_list(this,
*(thd->lex.current_select->get_item_list()), *(thd->lex.current_select->get_item_list()),
((sl && ((sl &&
thd->lex.current_select->linkage != thd->lex.current_select->master_unit()->
first_select()->linkage !=
DERIVED_TABLE_TYPE) ? DERIVED_TABLE_TYPE) ?
REPORT_EXCEPT_NOT_FOUND : REPORT_EXCEPT_NOT_FOUND :
REPORT_ALL_ERRORS))) == REPORT_ALL_ERRORS))) ==
...@@ -1050,7 +1053,8 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) ...@@ -1050,7 +1053,8 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
if ((tmp= find_field_in_tables(thd, this, if ((tmp= find_field_in_tables(thd, this,
sl->get_table_list(), sl->get_table_list(),
0)) != not_found_field); 0)) != not_found_field);
if (sl->linkage == DERIVED_TABLE_TYPE) if (sl->master_unit()->first_select()->linkage ==
DERIVED_TABLE_TYPE)
break; // do not look over derived table break; // do not look over derived table
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment