Commit 8a1b6e16 authored by unknown's avatar unknown

added check of cardinality to IN/ALL/ANY subquery transformer

(BUG#1638)


mysql-test/r/subselect.result:
  test for BUG#1638
mysql-test/t/subselect.test:
  test for BUG#1638
sql/item_subselect.cc:
  always check cardinality first
parent c3bfbe07
......@@ -1457,3 +1457,10 @@ dbid name
-1 Valid
-1 Valid 2
drop table t1,t2,t3,t4;
CREATE TABLE t1 (id int(11) default NULL) TYPE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES (1),(5);
CREATE TABLE t2 (id int(11) default NULL) TYPE=MyISAM CHARSET=latin1;
INSERT INTO t2 VALUES (2),(6);
select * from t1 where (1,2,6) in (select * from t2);
ERROR 21000: Operand should contain 3 column(s)
DROP TABLE t1,t2;
......@@ -981,3 +981,14 @@ INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, '
select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid;
drop table t1,t2,t3,t4;
#
# cardinality check
#
CREATE TABLE t1 (id int(11) default NULL) TYPE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES (1),(5);
CREATE TABLE t2 (id int(11) default NULL) TYPE=MyISAM CHARSET=latin1;
INSERT INTO t2 VALUES (2),(6);
-- error 1240
select * from t1 where (1,2,6) in (select * from t2);
DROP TABLE t1,t2;
......@@ -514,6 +514,12 @@ Item_in_subselect::single_value_transformer(JOIN *join,
THD *thd= join->thd;
thd->where= "scalar IN/ALL/ANY subquery";
if (select_lex->item_list.elements > 1)
{
my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
DBUG_RETURN(RES_ERROR);
}
if ((abort_on_null || (upper_not && upper_not->top_level())) &&
!select_lex->master_unit()->dependent &&
(func == &Item_bool_func2::gt_creator ||
......@@ -606,11 +612,6 @@ Item_in_subselect::single_value_transformer(JOIN *join,
select_lex->dependent= 1;
Item *item;
if (select_lex->item_list.elements > 1)
{
my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
DBUG_RETURN(RES_ERROR);
}
item= (Item*) select_lex->item_list.head();
......@@ -710,6 +711,12 @@ Item_in_subselect::row_value_transformer(JOIN *join,
SELECT_LEX *select_lex= join->select_lex;
if (select_lex->item_list.elements != left_expr->cols())
{
my_error(ER_OPERAND_COLUMNS, MYF(0), left_expr->cols());
DBUG_RETURN(RES_ERROR);
}
if (!substitution)
{
//first call for this unit
......
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