1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-29363: Constant subquery causing a crash in pushdown optimization

The crash is caused by the attempt to refix the constant subquery during
pushdown from HAVING into WHERE optimization.

Every condition that is going to be pushed into WHERE clause is first
cleaned up, then refixed. Constant subqueries are not cleaned or refixed
because they will remain the same after refixing, so this complicated
procedure can be omitted for them (introduced in MDEV-21184).
Constant subqueries are marked with flag IMMUTABLE_FL, that helps to miss
the cleanup stage for them. Also they are marked as fixed, so refixing is
also not done for them.
Because of the multiple equality propagation several references to the same
constant subquery can exist in the condition that is going to be pushed
into WHERE. Before this patch, the problem appeared in the following way.
After the first reference to the constant subquery is processed, the flag
IMMUTABLE_FL for the constant subquery is disabled.
So, when the second reference to this constant subquery is processed, the
flag is already disabled and the subquery goes through the procedure of
cleaning and refixing. That causes a crash.

To solve this problem, IMMUTABLE_FL should be disabled only after all
references to the constant subquery are processed, so after the whole
condition that is going to be pushed is cleaned up and refixed.

Approved by Igor Babaev <igor@maridb.com>
This commit is contained in:
Galina Shalygina
2024-06-18 19:40:05 +02:00
parent a4ef05d0d5
commit 6cb896a639
5 changed files with 194 additions and 3 deletions

View File

@ -1498,3 +1498,64 @@ SELECT a FROM t1 GROUP BY a HAVING NOT a;
DROP TABLE t1;
--echo End of 10.4 tests
--echo #
--echo # MDEV-29363: Constant subquery causing a crash in pushdown optimization
--echo #
CREATE TABLE t1 (a INT, b INT, c INT);
INSERT INTO t1 VALUES (3, 3, 4), (NULL, NULL, 2);
let $q=
SELECT a,b,c FROM t1 GROUP BY a,b,c
HAVING a = (SELECT MIN(b) AS min_b FROM t1) and (a = b or a = c);
eval EXPLAIN FORMAT=JSON $q;
eval $q;
let $q=
SELECT a FROM t1 GROUP BY a,b
HAVING a = (SELECT MIN(a) AS min_a FROM t1) AND (a = 3 or a > b);
eval EXPLAIN FORMAT=JSON $q;
eval $q;
DROP TABLE t1;
--echo #
--echo # MDEV-32424: Pushdown: server crashes at JOIN::save_explain_data()
--echo # (fixed by the patch for MDEV-29363)
--echo #
CREATE TABLE t1 (a INT, b INT, c INT);
INSERT INTO t1 VALUES (1, 1, 3), (3, 2, 3);
SELECT a,b,c FROM t1 GROUP BY a,b,c
HAVING a = (SELECT MIN(b) AS min_b FROM t1) and a IN (b, c);
DROP TABLE t1;
--echo #
--echo # MDEV-32293: Pushdown: server crashes at check_simple_equality()
--echo # (fixed by the patch for MDEV-29363)
--echo #
CREATE VIEW v1 AS SELECT 1 AS a;
SELECT * FROM v1 GROUP BY a HAVING a = 'b' AND a = (a IS NULL);
DROP VIEW v1;
--echo #
--echo # MDEV-32304: Pushdown: server crashes at Item_field::used_tables()
--echo # (fixed by the patch for MDEV-29363)
--echo #
CREATE VIEW v1 AS SELECT 1 AS a;
SELECT * FROM v1
GROUP BY a HAVING a = (a IS NULL OR a IS NULL);
DROP VIEW v1;
--echo End of 10.5 tests