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

Fixed MDEV-13994 Bad join results with orderby_uses_equalities=on.

This patch effectively blocks the optimization that uses multiple
equalities for ORDER BY to remove tmp table in the case when
the first table happens to be the result of materialization of
a semi-join nest. Currently there is no code at the execution level
that would support the optimization in this case.
This commit is contained in:
Igor Babaev
2017-11-10 13:58:00 -08:00
parent 589b0b3655
commit dcbf2823c7
5 changed files with 241 additions and 1 deletions

View File

@ -61,3 +61,50 @@ from t1
where key1<3 or key2<3;
drop table t0, t1;
--echo #
--echo # MDEV-14071: wrong results with orderby_uses_equalities=on
--echo # (duplicate of MDEV-13994)
--echo #
CREATE TABLE t1 (i int, j int, z int,PRIMARY KEY (i,j), KEY (z)) ENGINE=InnoDB;
CREATE TABLE t2 (i int, j int, PRIMARY KEY (i,j)) ENGINE=InnoDB;
CREATE TABLE t3 (j int, n varchar(5), PRIMARY KEY (j)) ENGINE=InnoDB;
INSERT INTO t1 VALUES
(127,0,1),(188,0,1),(206,0,1),(218,0,1),(292,0,1),(338,0,1),(375,0,1),
(381,0,1),(409,0,1),(466,0,1),(469,0,1),(498,0,1),(656,0,1);
INSERT INTO t1 VALUES
(77,4,0),(86,7,0),(96,6,0),(96,7,0),(99,9,0),(99,10,0),(99,11,0),(104,4,0),
(106,5,0),(148,6,0),(177,6,0),(181,5,0),(188,8,0),(218,8,0),(253,7,0),
(268,4,0),(338,4,0),(409,7,0),(466,8,0),(469,8,0),(498,8,0),(656,8,0);
INSERT INTO t2 VALUES
(127,7),(188,8),(188,9),(206,6),(218,8),(218,9),(292,7),(338,4),(338,5),
(375,6),(381,5),(409,7),(409,8),(466,8),(466,9),(469,8),(469,9),(498,8),
(498,9),(656,8),(656,9);
INSERT INTO t3 VALUES
(4,'four'),(5,'five'),(6,'six'),(7,'seven'),(8,'eight'),(9,'nine');
let $q1=
SELECT i,n
FROM t1 INNER JOIN t2 USING (i,j) LEFT JOIN t3 USING (j)
WHERE i IN (SELECT i FROM t1 WHERE z=1) AND z=0 ORDER BY i;
let $q2=
SELECT i,n
FROM t1 x INNER JOIN t2 USING (i,j) LEFT JOIN t3 USING (j)
WHERE EXISTS (SELECT * FROM t1 WHERE i=x.i AND z=1) AND z=0 ORDER BY i;
SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='orderby_uses_equalities=off';
eval $q1;
eval $q2;
SET optimizer_switch='orderby_uses_equalities=on';
eval $q1;
eval $q2;
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1,t2,t3;