From f4216c526bcd7b3e68249f4349f856a8dfcc7f73 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Apr 2003 15:55:28 +0300 Subject: [PATCH] Fix for a bug with empty item list in UNION's --- mysql-test/r/union.result | 2 ++ mysql-test/t/union.test | 2 ++ sql/item.cc | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 0edf5df7ae1..7b29a8fbcde 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -273,3 +273,5 @@ SELECT @a:=1 UNION SELECT @a:=@a+1; @a:=1 1 2 +(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a); +Unknown column 'a' in 'field list' diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index d2f35b59f54..70e770cd2d3 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -146,3 +146,5 @@ drop table t1,t2; (select 1) union (select 2) order by 0; SELECT @a:=1 UNION SELECT @a:=@a+1; +--error 1054 +(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a); diff --git a/sql/item.cc b/sql/item.cc index 30f610ea92a..a029219c366 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -701,9 +701,10 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) (last= sl)->get_table_list(), &where, 0)) != not_found_field) break; - if ((refer= find_item_in_list(this, sl->item_list, &counter, - REPORT_EXCEPT_NOT_FOUND)) != - (Item **)not_found_item) + if (sl->item_list.elements && + ((refer= find_item_in_list(this, sl->item_list, &counter, + REPORT_EXCEPT_NOT_FOUND)) != + (Item **)not_found_item)) break; if (sl->master_unit()->first_select()->linkage == DERIVED_TABLE_TYPE)