Skip to content

Commit 2dd4e50

Browse files
committed
MDEV-15555: select from DUAL where false yielding wrong result when in a IN
For the query having an IN subquery with no tables, we were converting the subquery with an expression between the left part and the select list of the subquery . This can give incorrect results when we have a condition in the subquery with a dual table (as this is treated as a no table). The fix is that we don't do this conversion when we have conds in the subquery with a dual table.
1 parent 69bc3c1 commit 2dd4e50

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

mysql-test/r/subselect4.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,5 +2498,16 @@ FROM t2 WHERE b <= 'quux' GROUP BY field;
24982498
field COUNT(DISTINCT c)
24992499
0 1
25002500
drop table t1,t2;
2501+
#
2502+
# MDEV-15555: select from DUAL where false yielding wrong result when in a IN
2503+
#
2504+
explain
2505+
SELECT 2 IN (SELECT 2 from DUAL WHERE 1 != 1);
2506+
id select_type table type possible_keys key key_len ref rows Extra
2507+
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2508+
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2509+
SELECT 2 IN (SELECT 2 from DUAL WHERE 1 != 1);
2510+
2 IN (SELECT 2 from DUAL WHERE 1 != 1)
2511+
0
25012512
SET optimizer_switch= @@global.optimizer_switch;
25022513
set @@tmp_table_size= @@global.tmp_table_size;

mysql-test/t/subselect4.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,5 +2035,13 @@ SELECT ( SELECT COUNT(*) FROM t1 WHERE a = c ) AS field, COUNT(DISTINCT c)
20352035
FROM t2 WHERE b <= 'quux' GROUP BY field;
20362036
drop table t1,t2;
20372037

2038+
--echo #
2039+
--echo # MDEV-15555: select from DUAL where false yielding wrong result when in a IN
2040+
--echo #
2041+
2042+
explain
2043+
SELECT 2 IN (SELECT 2 from DUAL WHERE 1 != 1);
2044+
SELECT 2 IN (SELECT 2 from DUAL WHERE 1 != 1);
2045+
20382046
SET optimizer_switch= @@global.optimizer_switch;
20392047
set @@tmp_table_size= @@global.tmp_table_size;

sql/item_subselect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ Item_in_subselect::single_value_transformer(JOIN *join)
17461746
Item* join_having= join->having ? join->having : join->tmp_having;
17471747
if (!(join_having || select_lex->with_sum_func ||
17481748
select_lex->group_list.elements) &&
1749-
select_lex->table_list.elements == 0 &&
1749+
select_lex->table_list.elements == 0 && !join->conds &&
17501750
!select_lex->master_unit()->is_union())
17511751
{
17521752
Item *where_item= (Item*) select_lex->item_list.head();

0 commit comments

Comments
 (0)