mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
babebf9ceb
The EXISTS transformation has additional switches to catch the known corner cases that appear when transforming an IN predicate into EXISTS. Guarded conditions are used which are deactivated when a NULL value is seen in the outer expression's row. When the inner query block supplies NULL values, however, they are filtered out because no distinction is made between the guarded conditions; guarded NOT x IS NULL conditions in the HAVING clause that filter out NULL values cannot be de-activated in isolation from those that match values or from the outer expression or NULL's. The above problem is handled by making the guarded conditions remember whether they have rejected a NULL value or not, and index access methods are taking this into account as well. The bug consisted of 1) Not resetting the property for every nested loop iteration on the inner query's result. 2) Not propagating the NULL result properly from inner query to IN optimizer. 3) A hack that may or may not have been needed at some point. According to a comment it was aimed to fix #2 by returning NULL when FALSE was actually the result. This caused failures when #2 was properly fixed. The hack is now removed. The fix resolves all three points.
142 lines
4 KiB
Text
142 lines
4 KiB
Text
# General purpose bug fix tests go here : subselect.test too large
|
|
|
|
|
|
--echo #
|
|
--echo # Bug #46791: Assertion failed:(table->key_read==0),function unknown
|
|
--echo # function,file sql_base.cc
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT, b INT, KEY(a));
|
|
INSERT INTO t1 VALUES (1,1),(2,2);
|
|
CREATE TABLE t2 LIKE t1;
|
|
INSERT INTO t2 VALUES (1,1),(2,2);
|
|
CREATE TABLE t3 LIKE t1;
|
|
|
|
--echo # should have 1 impossible where and 2 dependent subqueries
|
|
EXPLAIN
|
|
SELECT 1 FROM t1
|
|
WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3))
|
|
ORDER BY count(*);
|
|
|
|
--echo # should not crash the next statement
|
|
SELECT 1 FROM t1
|
|
WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3))
|
|
ORDER BY count(*);
|
|
|
|
--echo # should not crash: the crash is caused by the previous statement
|
|
SELECT 1;
|
|
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
--echo #
|
|
--echo # Bug #47106: Crash / segfault on adding EXPLAIN to a non-crashing
|
|
--echo # query
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (
|
|
a INT,
|
|
b INT,
|
|
PRIMARY KEY (a),
|
|
KEY b (b)
|
|
);
|
|
INSERT INTO t1 VALUES (1, 1), (2, 1);
|
|
|
|
CREATE TABLE t2 LIKE t1;
|
|
INSERT INTO t2 SELECT * FROM t1;
|
|
|
|
CREATE TABLE t3 LIKE t1;
|
|
INSERT INTO t3 SELECT * FROM t1;
|
|
|
|
--echo # Should not crash.
|
|
--echo # Should have 1 impossible where and 2 dependent subqs.
|
|
EXPLAIN
|
|
SELECT
|
|
(SELECT 1 FROM t1,t2 WHERE t2.b > t3.b)
|
|
FROM t3 WHERE 1 = 0 GROUP BY 1;
|
|
|
|
--echo # should return 0 rows
|
|
SELECT
|
|
(SELECT 1 FROM t1,t2 WHERE t2.b > t3.b)
|
|
FROM t3 WHERE 1 = 0 GROUP BY 1;
|
|
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
--echo End of 5.0 tests.
|
|
|
|
--echo #
|
|
--echo # Bug#54568: create view cause Assertion failed: 0,
|
|
--echo # file .\item_subselect.cc, line 836
|
|
--echo #
|
|
EXPLAIN SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
|
|
DESCRIBE SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
|
|
--echo # None of the below should crash
|
|
CREATE VIEW v1 AS SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
|
|
CREATE VIEW v2 AS SELECT 1 LIKE '%' ESCAPE ( 1 IN ( SELECT 1 ) );
|
|
DROP VIEW v1, v2;
|
|
|
|
--echo #
|
|
--echo # Bug#51070: Query with a NOT IN subquery predicate returns a wrong
|
|
--echo # result set
|
|
--echo #
|
|
CREATE TABLE t1 ( a INT, b INT );
|
|
INSERT INTO t1 VALUES ( 1, NULL ), ( 2, NULL );
|
|
|
|
CREATE TABLE t2 ( c INT, d INT );
|
|
INSERT INTO t2 VALUES ( NULL, 3 ), ( NULL, 4 );
|
|
|
|
CREATE TABLE t3 ( e INT, f INT );
|
|
INSERT INTO t3 VALUES ( NULL, NULL ), ( NULL, NULL );
|
|
|
|
CREATE TABLE t4 ( a INT );
|
|
INSERT INTO t4 VALUES (1), (2), (3);
|
|
|
|
CREATE TABLE t5 ( a INT );
|
|
INSERT INTO t5 VALUES (NULL), (2);
|
|
|
|
--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x
|
|
EXPLAIN
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 );
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 );
|
|
|
|
EXPLAIN
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS NULL;
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS NULL;
|
|
SELECT * FROM t1 WHERE ( a, b ) IN ( SELECT c, d FROM t2 ) IS NULL;
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS UNKNOWN;
|
|
SELECT * FROM t1 WHERE (( a, b ) NOT IN ( SELECT c, d FROM t2 )) IS UNKNOWN;
|
|
|
|
SELECT * FROM t1 WHERE 1 = 1 AND ( a, b ) NOT IN ( SELECT c, d FROM t2 );
|
|
|
|
--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x
|
|
EXPLAIN
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT e, f FROM t3 );
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT e, f FROM t3 );
|
|
|
|
--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x
|
|
EXPLAIN
|
|
SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT a, b FROM t1 );
|
|
SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT a, b FROM t1 );
|
|
|
|
--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x
|
|
EXPLAIN
|
|
SELECT * FROM t3 WHERE ( e, f ) NOT IN ( SELECT c, d FROM t2 );
|
|
SELECT * FROM t3 WHERE ( e, f ) NOT IN ( SELECT c, d FROM t2 );
|
|
|
|
--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x
|
|
EXPLAIN
|
|
SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT e, f FROM t3 );
|
|
SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT e, f FROM t3 );
|
|
|
|
SELECT * FROM t1 WHERE ( a, b ) NOT IN
|
|
( SELECT c, d FROM t2 WHERE c = 1 AND c <> 1 );
|
|
|
|
SELECT * FROM t1 WHERE b NOT IN ( SELECT c FROM t2 WHERE c = 1 );
|
|
|
|
SELECT * FROM t1 WHERE NULL NOT IN ( SELECT c FROM t2 WHERE c = 1 AND c <> 1 );
|
|
|
|
DROP TABLE t1, t2, t3, t4, t5;
|
|
|
|
|
|
--echo #
|
|
--echo # End of 5.1 tests.
|
|
--echo #
|