summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <Sinisa@sinisa.nasamreza.org>2003-02-22 17:02:36 +0200
committerunknown <Sinisa@sinisa.nasamreza.org>2003-02-22 17:02:36 +0200
commit72065f34e674d5dcbb8a6c7d6e96609fbb3ecab7 (patch)
treee0f67843d5ab331138844bbc3eac6abce34b90af
parent7cef5e9b978c7ac1f3c5895eb76b52f71c9bcc50 (diff)
downloadmariadb-git-72065f34e674d5dcbb8a6c7d6e96609fbb3ecab7.tar.gz
Allowing NULL values in UNION's with first SELECT having only NOT NULL
columns.
-rw-r--r--mysql-test/r/union.result27
-rw-r--r--mysql-test/t/union.test17
-rw-r--r--sql/sql_union.cc5
3 files changed, 48 insertions, 1 deletions
diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result
index cb3a8029a87..cf166f47f35 100644
--- a/mysql-test/r/union.result
+++ b/mysql-test/r/union.result
@@ -203,3 +203,30 @@ No tables used
select 1 as a,(select a union select a);
a (select a union select a)
1 1
+drop table if exists t1,t2;
+CREATE TABLE t1 ( id int(3) unsigned default '0') TYPE=MyISAM;
+INSERT INTO t1 (id) VALUES("1");
+CREATE TABLE t2 ( id int(3) unsigned default '0', id_master int(5) default '0', text1 varchar(5) default NULL, text2 varchar(5) default NULL) TYPE=MyISAM;
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("1", "1",
+"foo1", "bar1");
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("2", "1",
+"foo2", "bar2");
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("3", "1", NULL,
+"bar3");
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("4", "1",
+"foo4", "bar4");
+SELECT 1 AS id_master, 1 AS id, NULL AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
+id_master id text1 text2
+1 1 NULL ABCDE
+1 1 bar1
+1 2 bar2
+1 3 NULL bar3
+1 4 bar4
+SELECT 1 AS id_master, 1 AS id, 'ABCDE' AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
+id_master id text1 text2
+1 1 ABCDE ABCDE
+1 1 foo1 bar1
+1 2 foo2 bar2
+1 3 NULL bar3
+1 4 foo4 bar4
+drop table if exists t1,t2;
diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test
index b46f54c5c41..af2dd154974 100644
--- a/mysql-test/t/union.test
+++ b/mysql-test/t/union.test
@@ -107,3 +107,20 @@ drop table t1,t2;
--error 1096
select * union select 1;
select 1 as a,(select a union select a);
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+CREATE TABLE t1 ( id int(3) unsigned default '0') TYPE=MyISAM;
+INSERT INTO t1 (id) VALUES("1");
+CREATE TABLE t2 ( id int(3) unsigned default '0', id_master int(5) default '0', text1 varchar(5) default NULL, text2 varchar(5) default NULL) TYPE=MyISAM;
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("1", "1",
+"foo1", "bar1");
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("2", "1",
+"foo2", "bar2");
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("3", "1", NULL,
+"bar3");
+INSERT INTO t2 (id, id_master, text1, text2) VALUES("4", "1",
+"foo4", "bar4");
+SELECT 1 AS id_master, 1 AS id, NULL AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
+SELECT 1 AS id_master, 1 AS id, 'ABCDE' AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
+drop table if exists t1,t2;
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index a9ccff03649..feaa8371acb 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -146,7 +146,10 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result,
if (setup_tables(first_table) ||
setup_wild(thd, first_table, sl->item_list, 0, sl->with_wild))
goto err;
-
+ List_iterator<Item> it(sl->item_list);
+ Item *item;
+ while((item=it++))
+ item->maybe_null=1;
item_list= sl->item_list;
sl->with_wild= 0;
if (setup_ref_array(thd, &sl->ref_pointer_array,