Commit 2087d47a authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-22462: Item_in_subselect::create_single_in_to_exists_cond(JOIN *, Item...

MDEV-22462: Item_in_subselect::create_single_in_to_exists_cond(JOIN *, Item **, Item **): Assertion `false' failed.

Item_in_subselect::create_single_in_to_exists_cond() should handle the
case where the subquery is a table-less select but it is not a result
of a UNION.

(Table-less subqueries like "(SELECT 1)" are "substituted" with their select
list, but table-less subqueries with WHERE or HAVING clause, like
"(SELECT 1 WHERE ...)" are not substituted. They are handled with regular
execution path)
parent 8c8a6ed3
...@@ -2721,7 +2721,15 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -2721,7 +2721,15 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT a FROM t1 WHERE (a, a) IN (SELECT 1, 2) AND a = (SELECT MIN(b) FROM t2); SELECT a FROM t1 WHERE (a, a) IN (SELECT 1, 2) AND a = (SELECT MIN(b) FROM t2);
a a
DROP TABLE t1,t2; DROP TABLE t1,t2;
# End of 10.2 tests #
# MDEV-22462: Item_in_subselect::create_single_in_to_exists_cond(JOIN *, Item **, Item **): Assertion `false' failed.
#
select 1 from dual where 1 in (select 5 from dual where 1);
1
create table t1 (a int);
insert into t1 values (1),(2),(3);
update t1 set a = 2 where a in (select a from dual where a = a);
drop table t1;
# #
# MDEV-24925: Server crashes in Item_subselect::init_expr_cache_tracker # MDEV-24925: Server crashes in Item_subselect::init_expr_cache_tracker
# #
...@@ -2793,3 +2801,4 @@ FROM (t1 JOIN t1 AS ref_t1 ON ...@@ -2793,3 +2801,4 @@ FROM (t1 JOIN t1 AS ref_t1 ON
(t1.i1 > (SELECT ref_t1.i1 AS c0 FROM t1 b ORDER BY -c0))); (t1.i1 > (SELECT ref_t1.i1 AS c0 FROM t1 b ORDER BY -c0)));
ERROR 21000: Subquery returns more than 1 row ERROR 21000: Subquery returns more than 1 row
DROP TABLE t1; DROP TABLE t1;
# End of 10.2 tests
...@@ -2236,7 +2236,17 @@ SELECT a FROM t1 WHERE (a, a) IN (SELECT 1, 2) AND a = (SELECT MIN(b) FROM t2); ...@@ -2236,7 +2236,17 @@ SELECT a FROM t1 WHERE (a, a) IN (SELECT 1, 2) AND a = (SELECT MIN(b) FROM t2);
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo # End of 10.2 tests --echo #
--echo # MDEV-22462: Item_in_subselect::create_single_in_to_exists_cond(JOIN *, Item **, Item **): Assertion `false' failed.
--echo #
select 1 from dual where 1 in (select 5 from dual where 1);
create table t1 (a int);
insert into t1 values (1),(2),(3);
update t1 set a = 2 where a in (select a from dual where a = a);
drop table t1;
--echo # --echo #
--echo # MDEV-24925: Server crashes in Item_subselect::init_expr_cache_tracker --echo # MDEV-24925: Server crashes in Item_subselect::init_expr_cache_tracker
...@@ -2296,3 +2306,4 @@ FROM (t1 JOIN t1 AS ref_t1 ON ...@@ -2296,3 +2306,4 @@ FROM (t1 JOIN t1 AS ref_t1 ON
DROP TABLE t1; DROP TABLE t1;
--echo # End of 10.2 tests
...@@ -2249,7 +2249,8 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join, ...@@ -2249,7 +2249,8 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
*/ */
Item *item= (Item*) select_lex->item_list.head(); Item *item= (Item*) select_lex->item_list.head();
if (select_lex->table_list.elements) if (select_lex->table_list.elements ||
!(select_lex->master_unit()->is_union()))
{ {
Item *having= item; Item *having= item;
Item *orig_item= item; Item *orig_item= item;
...@@ -2297,8 +2298,8 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join, ...@@ -2297,8 +2298,8 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
} }
else else
{ {
if (select_lex->master_unit()->is_union()) DBUG_ASSERT(select_lex->master_unit()->is_union());
{
Item *new_having= Item *new_having=
func->create(thd, expr, func->create(thd, expr,
new (thd->mem_root) Item_ref_null_helper(thd, new (thd->mem_root) Item_ref_null_helper(thd,
...@@ -2320,9 +2321,6 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join, ...@@ -2320,9 +2321,6 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
DBUG_RETURN(true); DBUG_RETURN(true);
*having_item= new_having; *having_item= new_having;
} }
else
DBUG_ASSERT(false);
}
} }
DBUG_RETURN(false); DBUG_RETURN(false);
......
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