Commit f11bcefa authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

fixed error handling if creating derived table failed

single row subquery always can return NULL (no rows found) (BUG#5590)
parent d2474ee2
...@@ -1084,7 +1084,7 @@ SHOW CREATE TABLE t1; ...@@ -1084,7 +1084,7 @@ SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL default '0', `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 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a; CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
...@@ -1102,7 +1102,7 @@ a ...@@ -1102,7 +1102,7 @@ a
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL default '0' `a` bigint(20) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
...@@ -1976,3 +1976,14 @@ create table t1 (x 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 (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) (select b.x from t1 as b where b.x=a.x)
drop table t1; 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;
...@@ -1270,3 +1270,16 @@ drop table t1; ...@@ -1270,3 +1270,16 @@ drop table t1;
create table t1 (x int); 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 (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; 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;
...@@ -2486,6 +2486,7 @@ Item_type_holder::Item_type_holder(THD *thd, Item *item) ...@@ -2486,6 +2486,7 @@ Item_type_holder::Item_type_holder(THD *thd, Item *item)
else else
field_example= 0; field_example= 0;
max_length= real_length(item); max_length= real_length(item);
maybe_null= item->maybe_null;
collation.set(item->collation); collation.set(item->collation);
} }
......
...@@ -401,7 +401,6 @@ void Item_singlerow_subselect::fix_length_and_dec() ...@@ -401,7 +401,6 @@ void Item_singlerow_subselect::fix_length_and_dec()
engine->fix_length_and_dec(row); engine->fix_length_and_dec(row);
value= *row; value= *row;
} }
maybe_null= engine->may_be_null();
} }
uint Item_singlerow_subselect::cols() uint Item_singlerow_subselect::cols()
......
...@@ -224,7 +224,10 @@ static int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, ...@@ -224,7 +224,10 @@ static int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
} }
} }
else else
{
free_tmp_table(thd, table); free_tmp_table(thd, table);
thd->lex->unit.cleanup();
}
exit: exit:
delete derived_result; delete derived_result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment