mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fix bug lp:1002079
Analysis: The optimizer detects an empty result through constant table optimization. Then it calls return_zero_rows(), which in turns calls inderctly Item_maxmin_subselect::no_rows_in_result(). The latter method set "value=0", however "value" is pointer to Item_cache, and not just an integer value. All of the Item_[maxmin | singlerow]_subselect::val_XXX methods does: if (forced_const) return value->val_real(); which of course crashes when value is a NULL pointer. Solution: When the optimizer discovers an empty result set, set Item_singlerow_subselect::value to a FALSE constant Item instead of NULL.
This commit is contained in:
@ -5174,6 +5174,21 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE
|
||||
|
||||
drop table t1,t2;
|
||||
|
||||
--echo #
|
||||
--echo # LP BUG#1002079 Server crashes in Item_singlerow_subselect::val_int with constant table,
|
||||
--echo # HAVING, UNION in subquery
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES (7),(0);
|
||||
CREATE TABLE t2 (b INT);
|
||||
|
||||
EXPLAIN
|
||||
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
|
||||
|
||||
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
|
||||
|
||||
drop table t1,t2;
|
||||
|
||||
--echo # return optimizer switch changed in the beginning of this test
|
||||
set optimizer_switch=@subselect_tmp;
|
||||
|
Reference in New Issue
Block a user