From da04109de292f1fad852490351a288876c05c633 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Mon, 10 Sep 2007 16:26:51 +0400 Subject: [PATCH 1/3] BUG#30385: Server crash when deleting with ORDER BY and LIMIT in get_index_for_order(), don't walk over the end of the index key parts when matching index description and needed ordering. --- mysql-test/r/delete.result | 11 +++++++++++ mysql-test/t/delete.test | 13 +++++++++++++ sql/opt_range.cc | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result index a5c22e66569..5dd37e6b98d 100644 --- a/mysql-test/r/delete.result +++ b/mysql-test/r/delete.result @@ -193,4 +193,15 @@ select @a; @a 1 drop table t1; +CREATE TABLE t1 ( +`date` date , +`time` time , +`seq` int(10) unsigned NOT NULL auto_increment, +PRIMARY KEY (`seq`), +KEY `seq` (`seq`), +KEY `time` (`time`), +KEY `date` (`date`) +); +DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1; +drop table t1; End of 4.1 tests diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index 301b2cdbb99..fdbb96e0c2f 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -184,4 +184,17 @@ delete from t1 where (@a:= f1) order by f1 limit 1; select @a; drop table t1; +# BUG#30385 "Server crash when deleting with order by and limit" +CREATE TABLE t1 ( + `date` date , + `time` time , + `seq` int(10) unsigned NOT NULL auto_increment, + PRIMARY KEY (`seq`), + KEY `seq` (`seq`), + KEY `time` (`time`), + KEY `date` (`date`) +); +DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1; +drop table t1; + --echo End of 4.1 tests diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 01b366077b0..a8ba609f9dc 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -825,6 +825,7 @@ uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit) if (!(table->keys_in_use_for_query.is_set(idx))) continue; KEY_PART_INFO *keyinfo= table->key_info[idx].key_part; + uint n_parts= table->key_info[idx].key_parts; uint partno= 0; /* @@ -834,7 +835,7 @@ uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit) */ if (!(table->file->index_flags(idx, 0, 1) & HA_READ_ORDER)) continue; - for (ord= order; ord; ord= ord->next, partno++) + for (ord= order; ord && partno < n_parts; ord= ord->next, partno++) { Item *item= order->item[0]; if (!(item->type() == Item::FIELD_ITEM && From 6f702a4b428493aac89199e70cbe60083233e616 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Tue, 11 Sep 2007 02:41:42 +0400 Subject: [PATCH 2/3] Post-merge fixes --- mysql-test/t/delete.test | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index df8c529407e..8a03cb6c715 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -187,7 +187,6 @@ DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1; drop table t1; --echo End of 4.1 tests -# End of 4.1 tests # # Test of multi-delete where we are not scanning the first table From 06f12f66e8f6e36609a22925049e9b527ef248bf Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Wed, 12 Sep 2007 01:52:27 +0400 Subject: [PATCH 3/3] Post-merge fixes --- mysql-test/r/delete.result | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result index a3ba61c9046..5084498c01c 100644 --- a/mysql-test/r/delete.result +++ b/mysql-test/r/delete.result @@ -195,7 +195,6 @@ KEY `date` (`date`) DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1; drop table t1; End of 4.1 tests -End of 4.1 tests CREATE TABLE t1 (a int not null,b int not null); CREATE TABLE t2 (a int not null, b int not null, primary key (a,b)); CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));