Commit 5ed2cf7d authored by tim@white.box's avatar tim@white.box
Browse files

Implement ORDER BY DESC optimization, which reads values in descending

order directly from the index instead of using a filesort.
parent 85388703
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -368,3 +368,5 @@ libmysqld/hash_filo.cc
libmysqld/sql_unions.cc
libmysqld/stacktrace.c
sql/share/mysql
.gdbinit
.vimrc
+1 −0
Original line number Diff line number Diff line
@@ -20,3 +20,4 @@ tim@threads.polyesthetic.msg
tim@work.mysql.com
tonu@hundin.mysql.fi
tonu@x3.internalnet
tim@white.box
+2 −2
Original line number Diff line number Diff line
@@ -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
+56 −0
Original line number Diff line number Diff line
@@ -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
+22 −0
Original line number Diff line number Diff line
@@ -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: */
Loading