summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <Sinisa@sinisa.nasamreza.org>2002-12-17 20:15:15 +0200
committerunknown <Sinisa@sinisa.nasamreza.org>2002-12-17 20:15:15 +0200
commit28eaef797401bbdd9f2f4e75a80f6c97628e0354 (patch)
tree8bfc3e448a5e9403d2385457506b73f19634a3af
parentfddbc989a4c42a58f5986fb158145763ce47107a (diff)
downloadmariadb-git-28eaef797401bbdd9f2f4e75a80f6c97628e0354.tar.gz
A fix for a bug in fix_fields in case like this:
select .. UNION select some_column; This is exhibited in sub-selects and derived tables.
-rw-r--r--mysql-test/r/derived.result2
-rw-r--r--mysql-test/t/derived.test2
-rw-r--r--sql/sql_base.cc8
3 files changed, 12 insertions, 0 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result
index 03e00b206b2..c4475cf7357 100644
--- a/mysql-test/r/derived.result
+++ b/mysql-test/r/derived.result
@@ -123,3 +123,5 @@ SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
select * from (select 1 as a) b left join (select 2 as a) c using(a);
a a
1 NULL
+SELECT * FROM (SELECT 1 UNION SELECT a) b;
+Unknown column 'a' in 'field list'
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index 5f63cea3c11..8f4ab57d6e5 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -43,3 +43,5 @@ explain select count(*) from t1 as tt1, (select * from t1) as tt2;
drop table if exists t1;
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
select * from (select 1 as a) b left join (select 2 as a) c using(a);
+--error 1054
+SELECT * FROM (SELECT 1 UNION SELECT a) b;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 87cc0d616a9..ce6133392c6 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1735,6 +1735,14 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
bool allow_rowid= tables && !tables->next; // Only one table
for (; tables ; tables=tables->next)
{
+ if (!tables->table)
+ {
+ if (report_error)
+ my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0),
+ item->full_name(),thd->where);
+ return (Field*) not_found_field;
+ }
+
Field *field=find_field_in_table(thd,tables->table,name,length,
grant_option &&
!thd->master_access, allow_rowid);