diff options
author | unknown <bell@sanja.is.com.ua> | 2004-09-17 19:08:46 +0300 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2004-09-17 19:08:46 +0300 |
commit | 580f12cc048cac99e5594ce94ab0b2ca63cad41a (patch) | |
tree | 022a3cf7464979f652d1c7ab9f1cd44108d5a639 | |
parent | f177c76fb226f70be426175f3d53eed557096ba4 (diff) | |
download | mariadb-git-580f12cc048cac99e5594ce94ab0b2ca63cad41a.tar.gz |
fixed error handling if creating derived table failed
single row subquery always can return NULL (no rows found) (BUG#5590)
mysql-test/r/subselect.result:
maybe_null flag returning by subquwery for temporary table creation
mysql-test/t/subselect.test:
maybe_null flag returning by subquwery for temporary table creation
sql/item.cc:
storing maybe_null in type holder
sql/item_subselect.cc:
single row subquery always can return NULL (no rows found)
sql/sql_derived.cc:
fixed error handling if creating derived table failed
-rw-r--r-- | mysql-test/r/subselect.result | 15 | ||||
-rw-r--r-- | mysql-test/t/subselect.test | 13 | ||||
-rw-r--r-- | sql/item.cc | 1 | ||||
-rw-r--r-- | sql/item_subselect.cc | 1 | ||||
-rw-r--r-- | sql/sql_derived.cc | 3 |
5 files changed, 30 insertions, 3 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 7826f5e452d..8bcf7f9bff2 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1084,7 +1084,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` bigint(20) NOT NULL default '0', - `(SELECT a)` bigint(20) NOT NULL default '0' + `(SELECT a)` bigint(20) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a; @@ -1102,7 +1102,7 @@ a SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` bigint(20) NOT NULL default '0' + `a` bigint(20) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 (a int); @@ -1976,3 +1976,14 @@ create table t1 (x int); select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; (select b.x from t1 as b where b.x=a.x) drop table t1; +CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`)); +INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400); +CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ; +INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a'); +SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; +ERROR 42S22: Unknown column 'b.sc' in 'field list' +SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; +ac +700 +NULL +drop tables t1,t2; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 2dc28479ee9..5e3aa4064e4 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1270,3 +1270,16 @@ drop table t1; create table t1 (x int); select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; drop table t1; + +# +# Test of correct maybe_null flag returning by subquwery for temporary table +# creation +# +CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`)); +INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400); +CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ; +INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a'); +-- error 1054 +SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; +SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; +drop tables t1,t2; diff --git a/sql/item.cc b/sql/item.cc index 2ae0fb598ec..457360e63d3 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2486,6 +2486,7 @@ Item_type_holder::Item_type_holder(THD *thd, Item *item) else field_example= 0; max_length= real_length(item); + maybe_null= item->maybe_null; collation.set(item->collation); } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 3ddf9a1c6bf..3dbf4eae55b 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -401,7 +401,6 @@ void Item_singlerow_subselect::fix_length_and_dec() engine->fix_length_and_dec(row); value= *row; } - maybe_null= engine->may_be_null(); } uint Item_singlerow_subselect::cols() diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 05ad2094372..906ef646f47 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -224,7 +224,10 @@ static int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, } } else + { free_tmp_table(thd, table); + thd->lex->unit.cleanup(); + } exit: delete derived_result; |