[MDEV-27302] Backward index scan is not reflected in EXPLAIN output Created: 2021-12-17  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: N/A
Fix Version/s: 10.11

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: optimizer-easy

Issue Links:
Relates
relates to MDEV-13756 Implement descending index: KEY (a DE... Closed

 Description   

MySQL's version of desc indexes implementation includes the indication of the backward scan in EXPLAIN:

MySQL 8.0.23

EXPLAIN SELECT * FROM t1 ORDER BY a ASC, b DESC;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	index	NULL	a_desc_b_asc	10	NULL	2	100.00	Backward index scan; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` desc
FLUSH STATUS;
SELECT * FROM t1 ORDER BY a ASC, b DESC;
a	b
1	2
2	1
SHOW STATUS LIKE 'Handler_read_prev';
Variable_name	Value
Handler_read_prev	2

MariaDB's currently doesn't:

preview-10.8-MDEV-13756-desc-indexes d6fa6e0a

EXPLAIN EXTENDED SELECT * FROM t1 ORDER BY a ASC, b DESC;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	index	NULL	a_desc_b_asc	10	NULL	2	100.00	Using index
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` desc
FLUSH STATUS;
SELECT * FROM t1 ORDER BY a ASC, b DESC;
a	b
1	2
2	1
SHOW STATUS LIKE 'Handler_read_prev';
Variable_name	Value
Handler_read_prev	2

As discussed elsewhere, it apparently should.



 Comments   
Comment by Sergei Petrunia [ 2022-02-20 ]

Note: MySQL 8 doesn't print "Backward index scan" for UPDATE/DELETE statements: https://bugs.mysql.com/bug.php?id=106521

Generated at Thu Feb 08 09:51:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.