Skip to content

Commit 25870f4

Browse files
committed
MDEV-18668 Server crash or ASAN use-after-poison in Item_equal_iterator /
st_select_lex::pushdown_from_having_into_where upon query with impossible WHERE condition Do not push from HAVING into impossible WHERE
1 parent 31deef0 commit 25870f4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

mysql-test/main/having_cond_pushdown.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,3 +1906,15 @@ EXPLAIN
19061906
DROP TABLE t1,t2;
19071907
DROP VIEW v1;
19081908
DROP FUNCTION f1;
1909+
#
1910+
# MDEV-18668: pushdown from HAVING into impossible WHERE
1911+
#
1912+
CREATE TABLE t1 (a INT, b INT);
1913+
INSERT INTO t1 VALUES (1,1),(2,2);
1914+
SELECT a FROM t1 WHERE b = 1 AND b = 2 GROUP BY a HAVING a <= 3;
1915+
a
1916+
EXPLAIN
1917+
SELECT a FROM t1 WHERE b = 1 AND b = 2 GROUP BY a HAVING a <= 3;
1918+
id select_type table type possible_keys key key_len ref rows Extra
1919+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1920+
DROP TABLE t1;

mysql-test/main/having_cond_pushdown.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,16 @@ eval $no_pushdown explain format=json $query;
473473
DROP TABLE t1,t2;
474474
DROP VIEW v1;
475475
DROP FUNCTION f1;
476+
477+
--echo #
478+
--echo # MDEV-18668: pushdown from HAVING into impossible WHERE
479+
--echo #
480+
481+
CREATE TABLE t1 (a INT, b INT);
482+
INSERT INTO t1 VALUES (1,1),(2,2);
483+
484+
SELECT a FROM t1 WHERE b = 1 AND b = 2 GROUP BY a HAVING a <= 3;
485+
EXPLAIN
486+
SELECT a FROM t1 WHERE b = 1 AND b = 2 GROUP BY a HAVING a <= 3;
487+
488+
DROP TABLE t1;

sql/sql_select.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,8 +1929,11 @@ JOIN::optimize_inner()
19291929
DBUG_RETURN(1);
19301930
}
19311931

1932+
/* Do not push into WHERE from HAVING if cond_value == Item::COND_FALSE */
1933+
19321934
if (thd->lex->sql_command == SQLCOM_SELECT &&
1933-
optimizer_flag(thd, OPTIMIZER_SWITCH_COND_PUSHDOWN_FROM_HAVING))
1935+
optimizer_flag(thd, OPTIMIZER_SWITCH_COND_PUSHDOWN_FROM_HAVING) &&
1936+
cond_value != Item::COND_FALSE)
19341937
{
19351938
having=
19361939
select_lex->pushdown_from_having_into_where(thd, having);
@@ -15380,6 +15383,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels,
1538015383
@param cond condition to process
1538115384
@param cond_equal multiple equalities to take into consideration
1538215385
@param table_join_idx index to tables determining field preference
15386+
@param do_substitution if false: do not do any field substitution
1538315387

1538415388
@note
1538515389
At the first glance full sort of fields in multiple equality

0 commit comments

Comments
 (0)