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

Implement ORDER BY DESC optimization, which reads values in descending

order directly from the index instead of using a filesort.
This commit is contained in:
tim@white.box
2001-06-28 03:06:23 -04:00
parent 85388703c4
commit 5ed2cf7dbe
8 changed files with 263 additions and 6 deletions

View File

@ -250,7 +250,7 @@ fi
[ -z "$COLUMNS" ] && COLUMNS=80
E=`$EXPR $COLUMNS - 8`
#DASH72=`expr substr '------------------------------------------------------------------------' 1 $E`
#DASH72=`$EXPR substr '------------------------------------------------------------------------' 1 $E`
DASH72=`$ECHO '------------------------------------------------------------------------'|$CUT -c 1-$E`
# on source dist, we pick up freshly build executables
@ -667,7 +667,7 @@ run_testcase ()
slave_init_script=$TESTDIR/$tname-slave.sh
slave_master_info_file=$TESTDIR/$tname-slave-master-info.opt
SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
if [ -n $SKIP_TEST ] ; then
if [ -n "$SKIP_TEST" ] ; then
SKIP_THIS_TEST=`$EXPR \( $tname : "$SKIP_TEST" \) != 0`
if [ x$SKIP_THIS_TEST = x1 ] ;
then

View File

@ -111,3 +111,59 @@ DateOfAction TransactionID
member_id nickname voornaam
1
2
table type possible_keys key key_len ref rows Extra
t1 index NULL a 20 NULL 10 Using index
a b c
1 NULL NULL
1 NULL b
1 1 NULL
1 1 b
1 1 b
2 0 a
2 0 b
2 1 a
2 1 b
2 1 c
table type possible_keys key key_len ref rows Extra
t1 index NULL a 20 NULL 10 Using index
a b c
2 1 c
2 1 b
2 1 a
2 0 b
2 0 a
1 1 b
1 1 b
1 1 NULL
1 NULL b
1 NULL NULL
table type possible_keys key key_len ref rows Extra
t1 range a a 20 NULL 2 where used; Using index
a b c
1 1 b
1 1 b
table type possible_keys key key_len ref rows Extra
t1 range a a 4 NULL 5 where used; Using index
a b c
1 1 b
1 1 b
1 1 NULL
table type possible_keys key key_len ref rows Extra
t1 range a a 9 NULL 7 where used; Using index
a b c
2 1 c
2 1 b
2 1 a
2 0 b
2 0 a
1 1 b
1 1 b
1 1 NULL
table type possible_keys key key_len ref rows Extra
t1 range a a 4 NULL 4 where used; Using index
a b c
1 1 b
1 1 b
1 1 NULL
1 NULL b
1 NULL NULL

View File

@ -205,3 +205,25 @@ select member_id, nickname, voornaam FROM members
ORDER by lastchange_datum DESC LIMIT 2;
drop table members;
create table t1 (a int not null, b int, c varchar(10), key (a, b, c));
insert into t1 values (1, NULL, NULL), (1, NULL, 'b'), (1, 1, NULL), (1, 1, 'b'), (1, 1, 'b'), (2, 0, 'a'), (2, 0, 'b'), (2, 1, 'a'), (2, 1, 'b'), (2, 1, 'c');
explain select * from t1 order by a, b, c;
select * from t1 order by a, b, c;
explain select * from t1 order by a desc, b desc, c desc;
select * from t1 order by a desc, b desc, c desc;
# test multiple ranges, NO_MAX_RANGE and EQ_RANGE
explain select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc;
select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc;
# test NEAR_MAX, NO_MIN_RANGE
explain select * from t1 where a < 2 and b <= 1 order by a desc, b desc;
select * from t1 where a < 2 and b <= 1 order by a desc, b desc;
# test HA_READ_AFTER_KEY (at the end of the file), NEAR_MIN
explain select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc;
select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc;
# test HA_READ_AFTER_KEY (in the middle of the file)
explain select * from t1 where a between 0 and 1 order by a desc, b desc;
select * from t1 where a between 0 and 1 order by a desc, b desc;
drop table t1;
/* vim:set ft=sql sw=2 noet: */