mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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;
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
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');
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
-- 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');
|
||||||
|
12
sql/item.cc
12
sql/item.cc
@ -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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user