1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Descending indexes code exposed a gap in fix for MDEV-25858.

Extend the fix for MDEV-25858 to handle non-reverse-ordered ORDER BY:

If test_if_skip_sort_order() decides to use an index to produce rows
in the required ordering, it should disable "Range Checked for Each Record".

The fix needs to be backported to earlier versions.
This commit is contained in:
Sergei Petrunia
2021-12-14 15:35:10 +03:00
committed by Sergei Golubchik
parent 791146b9d2
commit 3a82c256da
3 changed files with 70 additions and 7 deletions

View File

@ -170,7 +170,7 @@ from
dd.d1 desc, dd.d2 desc, dd.id desc limit 1
);
create index for_latest_sort on t2 (d1 desc, d2 desc, id desc);
create index for_latest_sort on t2 (d1, d2, id);
select
t1.id,t2.id
@ -186,6 +186,38 @@ from
dd.d1 desc, dd.d2 desc, dd.id desc limit 1
);
--echo # Now, same as above but use a DESC index
CREATE TABLE t3 (
id int NOT NULL PRIMARY KEY,
id2 int NOT NULL,
d1 datetime,
d2 timestamp NOT NULL,
KEY id2 (id2)
) engine=innodb;
insert into t3 values
(1,2,'2019-03-05 00:00:00','2019-03-06 00:00:00'),
(2,3,'2019-03-05 00:00:00','2019-03-06 00:00:00'),
(3,3,'2019-03-06 00:00:00','2019-03-05 00:00:00');
create index for_latest_sort on t3 (d1 desc, d2 desc, id desc);
select
t1.id,t3.id
from
t1 left join
t3 on t3.id2 = t1.id and
t3.id = (select dd.id
from t3 dd
where
dd.id2 = t1.id and
d1 > '2019-02-06 00:00:00'
order by
dd.d1 desc, dd.d2 desc, dd.id desc limit 1
);
--echo #
--echo # MDEV-27270: Wrong query plan with Range Checked for Each Record and ORDER BY ... LIMIT
--echo #
@ -207,7 +239,8 @@ from
order by
dd.d1, dd.d2, dd.id limit 1
);
drop table t1,t2;
drop table t1,t2,t3;
--echo # End of 10.2 tests