From 95ec38c5b10117aeb8ea0c24e4ba63aa8e9f3eee Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Thu, 29 Jul 2010 01:02:43 +0400 Subject: [PATCH] Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c on DELETE statement Single-table delete ordered by a field that has a hash-type index may cause an assertion failure or a crash. An optimization added by the fix for the bug 36569 forced the optimizer to use ORDER BY-compatible indices when applicable. However, the existence of unsorted indices (HASH index algorithm for some engines such as MEMORY/HEAP, NDB) was ignored. The test_if_order_by_key function has been modified to skip unsorted indices. --- mysql-test/r/heap_hash.result | 11 +++++++++++ mysql-test/t/heap_hash.test | 17 +++++++++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/heap_hash.result b/mysql-test/r/heap_hash.result index 7cc76611fb8..e3a3e0e9740 100644 --- a/mysql-test/r/heap_hash.result +++ b/mysql-test/r/heap_hash.result @@ -382,3 +382,14 @@ INSERT INTO t1 VALUES('A ', 'A '); ERROR 23000: Duplicate entry 'A -A ' for key 'key1' DROP TABLE t1; End of 5.0 tests +# +# Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c +# on DELETE statement +# +CREATE TABLE t1 (col_int_nokey INT, +col_int_key INT, +INDEX(col_int_key) USING HASH) ENGINE = HEAP; +INSERT INTO t1 (col_int_nokey, col_int_key) VALUES (3, 0), (4, 0), (3, 1); +DELETE FROM t1 WHERE col_int_nokey = 5 ORDER BY col_int_key LIMIT 2; +DROP TABLE t1; +End of 5.5 tests diff --git a/mysql-test/t/heap_hash.test b/mysql-test/t/heap_hash.test index 1e3491f89a9..748347021fc 100644 --- a/mysql-test/t/heap_hash.test +++ b/mysql-test/t/heap_hash.test @@ -284,3 +284,20 @@ INSERT INTO t1 VALUES('A ', 'A '); DROP TABLE t1; --echo End of 5.0 tests + +--echo # +--echo # Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c +--echo # on DELETE statement +--echo # + +CREATE TABLE t1 (col_int_nokey INT, + col_int_key INT, + INDEX(col_int_key) USING HASH) ENGINE = HEAP; +INSERT INTO t1 (col_int_nokey, col_int_key) VALUES (3, 0), (4, 0), (3, 1); + +DELETE FROM t1 WHERE col_int_nokey = 5 ORDER BY col_int_key LIMIT 2; + +DROP TABLE t1; + +--echo End of 5.5 tests + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e18486d718a..9c9a436cc24 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13244,7 +13244,7 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, DBUG_RETURN(0); } - if (key_part->field != field) + if (key_part->field != field || !field->part_of_sortkey.is_set(idx)) DBUG_RETURN(0); /* set flag to 1 if we can use read-next on key, else to -1 */