mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug #31001: ORDER BY DESC in InnoDB not working
The optimizer sets index traversal in reverse order only if there are used key parts that are not compared to a constant. However using the primary key as an ORDER BY suffix rendered the check incomplete : going in reverse order must still be used even if all the parts of the secondary key are compared to a constant. Fixed by relaxing the check and set reverse traversal even when all the secondary index keyparts are compared to a const. Also account for the case when all the primary keys are compared to a constant.
This commit is contained in:
@ -937,4 +937,27 @@ SELECT c,b FROM t1 GROUP BY c,b;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Bug #31001: ORDER BY DESC in InnoDB not working
|
||||
#
|
||||
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
|
||||
INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
|
||||
|
||||
#The two queries below should produce different results, but they don't.
|
||||
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
|
||||
SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
|
||||
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
|
||||
SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
|
||||
|
||||
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
|
||||
SELECT * FROM t1 ORDER BY b ASC, a ASC;
|
||||
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
|
||||
SELECT * FROM t1 ORDER BY b DESC, a DESC;
|
||||
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
|
||||
SELECT * FROM t1 ORDER BY b ASC, a DESC;
|
||||
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
|
||||
SELECT * FROM t1 ORDER BY b DESC, a ASC;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
Reference in New Issue
Block a user