Details
Description
After a HAVING condition is pushed into WHERE, and_new_conditions_to_optimized_cond() walks it with is_simplified_cond_processor. Item_func::is_simplified_cond_processor() is const_item() && !val_bool(), so it evaluates every constant sub-item, including ones the expression never reaches at runtime. EXP(1000) as an unreached branch of COALESCE/IF raises ER_DATA_OUT_OF_RANGE and aborts the query, while the same condition in WHERE works. On 13.2 the constant CONCAT('x','y') is also evaluated as a boolean and produces a warning (not on 10.11).
--echo # HAVING pushdown evaluates constant sub-arguments: spurious warning, ER_DATA_OUT_OF_RANGE
|
--disable_abort_on_error
|
CREATE TABLE t (a INT, b VARCHAR(10)); |
INSERT INTO t VALUES (1, 'xy'), (2, 'z'); |
SELECT a FROM t WHERE COALESCE(b, EXP(1000)) = 'xy'; |
--echo # BUG if error
|
SELECT a FROM t GROUP BY a, b HAVING COALESCE(b, EXP(1000)) = 'xy'; |
--echo # BUG if error
|
SELECT a FROM t GROUP BY a, b HAVING IF(a > 0, b, EXP(1000)) = 'xy'; |
--echo # BUG if warning
|
SELECT a FROM t GROUP BY a, b HAVING b = CONCAT('x', 'y'); |
DROP TABLE t; |
10.11.21 source revision: 4eee147752ab2d8bdb5af2a7a816bf6974f08a51
|
SELECT a FROM t WHERE COALESCE(b, EXP(1000)) = 'xy';
|
a
|
1
|
# BUG if error
|
SELECT a FROM t GROUP BY a, b HAVING COALESCE(b, EXP(1000)) = 'xy';
|
ERROR 22003: DOUBLE value is out of range in 'exp(1000)'
|
# BUG if error
|
SELECT a FROM t GROUP BY a, b HAVING IF(a > 0, b, EXP(1000)) = 'xy';
|
ERROR 22003: DOUBLE value is out of range in 'exp(1000)'
|
# BUG if warning
|
SELECT a FROM t GROUP BY a, b HAVING b = CONCAT('x', 'y');
|
a
|
1
|
13.2, last query:
SELECT a FROM t GROUP BY a, b HAVING b = CONCAT('x', 'y');
|
a
|
1
|
Warnings:
|
Warning 1292 Truncated incorrect BOOLEAN value: 'xy'
|
Attachments
Issue Links
- relates to
-
MDEV-19245 Impossible WHERE should be noticed earlier after HAVING pushdown
-
- Closed
-