Skip to content

Commit e3130d2

Browse files
committed
Fixed some assert crashes related to keyread.
- MDEV-22062 Assertion `!table->file->keyread_enabled()' failed in close_thread_table() - MDEV-22077 table->no_keyread .. failed in join_read_first() - MDEV-22237 Assertion `!table->file->keyread_enabled()' failed in handler::ha_reset on DELETE
1 parent 8399af8 commit e3130d2

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

mysql-test/main/keyread.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ select distinct f1 from v1;
44
f1
55
drop view v1;
66
drop table t1;
7+
CREATE TABLE t1 (a INT NOT NULL, UNIQUE(a)) ENGINE=InnoDB;
8+
INSERT INTO t1 VALUES (1),(2);
9+
DELETE FROM t1 ORDER BY a LIMIT 1;
10+
SELECT * FROM t1;
11+
a
12+
2
13+
DROP TABLE t1;
14+
CREATE TABLE t1 (a CHAR KEY,b BLOB) ENGINE=InnoDB;
15+
DELETE FROM t1 ORDER BY a LIMIT 1;
16+
DROP TABLE t1;

mysql-test/main/keyread.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,23 @@ create view v1 as select * from t1 where f2 = 1;
88
select distinct f1 from v1;
99
drop view v1;
1010
drop table t1;
11+
12+
#
13+
# MDEV-22062 Assertion `!table->file->keyread_enabled()' failed in
14+
# close_thread_table
15+
#
16+
17+
CREATE TABLE t1 (a INT NOT NULL, UNIQUE(a)) ENGINE=InnoDB;
18+
INSERT INTO t1 VALUES (1),(2);
19+
DELETE FROM t1 ORDER BY a LIMIT 1;
20+
SELECT * FROM t1;
21+
DROP TABLE t1;
22+
23+
#
24+
# MDEV-22237 Assertion `!table->file->keyread_enabled()' failed in
25+
# handler::ha_reset on DELETE
26+
#
27+
28+
CREATE TABLE t1 (a CHAR KEY,b BLOB) ENGINE=InnoDB;
29+
DELETE FROM t1 ORDER BY a LIMIT 1;
30+
DROP TABLE t1;

sql/sql_delete.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
379379
tables.table = table;
380380
tables.alias = table_list->alias;
381381

382-
if (select_lex->setup_ref_array(thd, order_list->elements) ||
383-
setup_order(thd, select_lex->ref_pointer_array, &tables,
382+
if (select_lex->setup_ref_array(thd, order_list->elements) ||
383+
setup_order(thd, select_lex->ref_pointer_array, &tables,
384384
fields, all_fields, order))
385385
{
386386
free_underlaid_joins(thd, thd->lex->first_select_lex());
@@ -547,10 +547,12 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
547547
else
548548
{
549549
ha_rows scanned_limit= query_plan.scanned_rows;
550+
table->no_keyread= 1;
550551
query_plan.index= get_index_for_order(order, table, select, limit,
551552
&scanned_limit,
552553
&query_plan.using_filesort,
553554
&reverse);
555+
table->no_keyread= 0;
554556
if (!query_plan.using_filesort)
555557
query_plan.scanned_rows= scanned_limit;
556558
}

sql/sql_select.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23584,7 +23584,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
2358423584
If ref_key used index tree reading only ('Using index' in EXPLAIN),
2358523585
and best_key doesn't, then revert the decision.
2358623586
*/
23587-
if (table->covering_keys.is_set(best_key))
23587+
if (table->covering_keys.is_set(best_key) && !table->no_keyread)
2358823588
table->file->ha_start_keyread(best_key);
2358923589
else
2359023590
table->file->ha_end_keyread();
@@ -28568,8 +28568,6 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
2856828568
if (new_used_key_parts != NULL)
2856928569
*new_used_key_parts= best_key_parts;
2857028570
table->file->ha_end_keyread();
28571-
if (is_best_covering && !table->no_keyread)
28572-
table->file->ha_start_keyread(best_key);
2857328571
DBUG_RETURN(TRUE);
2857428572
}
2857528573

sql/sql_update.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,11 @@ int mysql_update(THD *thd,
614614
else
615615
{
616616
ha_rows scanned_limit= query_plan.scanned_rows;
617+
table->no_keyread= 1;
617618
query_plan.index= get_index_for_order(order, table, select, limit,
618619
&scanned_limit, &need_sort,
619620
&reverse);
621+
table->no_keyread= 0;
620622
if (!need_sort)
621623
query_plan.scanned_rows= scanned_limit;
622624

0 commit comments

Comments
 (0)