mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-31279 Crash when lateral derived is guaranteed to return no rows
Consider this query SELECT t1.* FROM t1, (SELECT t2.b FROM t2 WHERE NOT EXISTS (SELECT 1 FROM t3) GROUP BY b) sq where sq.b = t1.a; If SELECT 1 FROM t3 is expensive, for example t3 has > thd->variables.expensive_subquery_limit, first evaluation is deferred to mysql_derived_fill(). There it is noted that, in the above case NOT EXISTS (SELECT 1 FROM t3) is constant and false. This causes the join variable zero_result_cause to be set to "Impossible WHERE noticed after reading const tables" and the handler for this join is never "opened" via handler::ha_open. When mysql_derived_fill() is called for the next group of results, this unopened handler is not taken into account. reviewed by Igor Babaev (igor@mariadb.com)
This commit is contained in:
@ -483,4 +483,22 @@ SELECT * FROM t1 JOIN t2 WHERE (t1.a, t2.b) IN (SELECT * FROM v);
|
||||
DROP VIEW v;
|
||||
DROP TABLE t1, t2, t3;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-31279 Crash when lateral derived is guaranteed to return no rows
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES ('1'),('2');
|
||||
CREATE TABLE t2 (b INT, KEY(b)) ENGINE=MyISAM;
|
||||
ALTER TABLE t2 DISABLE KEYS;
|
||||
INSERT INTO t2 VALUES (1),(2),(3);
|
||||
ALTER TABLE t2 ENABLE KEYS;
|
||||
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
|
||||
INSERT INTO t3 (c) SELECT seq FROM seq_1_to_101;
|
||||
|
||||
SELECT * FROM t1 WHERE t1.a IN (SELECT b FROM
|
||||
(SELECT t2.b FROM t2 WHERE NOT EXISTS (SELECT 1 FROM t3) GROUP BY b) sq);
|
||||
|
||||
DROP TABLE t1, t2, t3;
|
||||
|
||||
--echo # End of 10.4 tests
|
||||
|
Reference in New Issue
Block a user