summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorGeorgi Kodinov <kgeorge@mysql.com>2008-07-23 14:25:00 +0300
committerGeorgi Kodinov <kgeorge@mysql.com>2008-07-23 14:25:00 +0300
commitdd85aa78ba8fbdd992139223aff9ef051f80694a (patch)
treeea66f61dad46c8910d1b367ad135c0f17b1ca94d /mysql-test
parentf5bbcba96f763d58dfd2d3e03d5c4dfd0b5f0eec (diff)
downloadmariadb-git-dd85aa78ba8fbdd992139223aff9ef051f80694a.tar.gz
Bug#37830 : ORDER BY ASC/DESC - no difference
Range scan in descending order for c <= <col> <= c type of ranges was ignoring the DESC flag. However some engines like InnoDB have the primary key parts as a suffix for every secondary key. When such primary key suffix is used for ordering ignoring the DESC is not valid. But we generally would like to do this because it's faster. Fixed by performing only reverse scan if the primary key is used. Removed some dead code in the process. mysql-test/r/innodb_mysql.result: Bug#37830 : test case mysql-test/t/innodb_mysql.test: Bug#37830 : test case sql/opt_range.cc: Bug#37830 : - preserve and use used_key_parts to distinguish when a primary key suffix is used - removed some dead code sql/opt_range.h: Bug#37830 : - preserve used_key_parts - dead code removed sql/sql_select.cc: Bug#37830 : Do only reverse order traversal if the primary key suffix is used.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/innodb_mysql.result15
-rw-r--r--mysql-test/t/innodb_mysql.test18
2 files changed, 33 insertions, 0 deletions
diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result
index b487cfd9a4b..47fa331c9ab 100644
--- a/mysql-test/r/innodb_mysql.result
+++ b/mysql-test/r/innodb_mysql.result
@@ -1246,4 +1246,19 @@ set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
set global innodb_commit_concurrency=0;
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
+CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
+ENGINE=InnoDB;
+INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
+INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
+EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range t1_b t1_b 5 NULL 4 Using where
+SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+a b c
+8 1 1
+7 1 1
+6 1 1
+5 1 1
+4 1 1
+DROP TABLE t1;
End of 5.0 tests
diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test
index 59ee7c274bb..e15d1aee08a 100644
--- a/mysql-test/t/innodb_mysql.test
+++ b/mysql-test/t/innodb_mysql.test
@@ -996,4 +996,22 @@ set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
set global innodb_commit_concurrency=0;
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
+#
+# Bug #37830: ORDER BY ASC/DESC - no difference
+#
+
+CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
+ ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
+INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
+
+# should be range access
+EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+
+# should produce '8 7 6 5 4' for a
+SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+
+DROP TABLE t1;
+
--echo End of 5.0 tests