Commit e3130d22 authored by Monty's avatar Monty

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
parent 8399af81
...@@ -4,3 +4,13 @@ select distinct f1 from v1; ...@@ -4,3 +4,13 @@ select distinct f1 from v1;
f1 f1
drop view v1; drop view v1;
drop table t1; drop table t1;
CREATE TABLE t1 (a INT NOT NULL, UNIQUE(a)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2);
DELETE FROM t1 ORDER BY a LIMIT 1;
SELECT * FROM t1;
a
2
DROP TABLE t1;
CREATE TABLE t1 (a CHAR KEY,b BLOB) ENGINE=InnoDB;
DELETE FROM t1 ORDER BY a LIMIT 1;
DROP TABLE t1;
...@@ -8,3 +8,23 @@ create view v1 as select * from t1 where f2 = 1; ...@@ -8,3 +8,23 @@ create view v1 as select * from t1 where f2 = 1;
select distinct f1 from v1; select distinct f1 from v1;
drop view v1; drop view v1;
drop table t1; drop table t1;
#
# MDEV-22062 Assertion `!table->file->keyread_enabled()' failed in
# close_thread_table
#
CREATE TABLE t1 (a INT NOT NULL, UNIQUE(a)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2);
DELETE FROM t1 ORDER BY a LIMIT 1;
SELECT * FROM t1;
DROP TABLE t1;
#
# MDEV-22237 Assertion `!table->file->keyread_enabled()' failed in
# handler::ha_reset on DELETE
#
CREATE TABLE t1 (a CHAR KEY,b BLOB) ENGINE=InnoDB;
DELETE FROM t1 ORDER BY a LIMIT 1;
DROP TABLE t1;
...@@ -379,8 +379,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ...@@ -379,8 +379,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
tables.table = table; tables.table = table;
tables.alias = table_list->alias; tables.alias = table_list->alias;
if (select_lex->setup_ref_array(thd, order_list->elements) || if (select_lex->setup_ref_array(thd, order_list->elements) ||
setup_order(thd, select_lex->ref_pointer_array, &tables, setup_order(thd, select_lex->ref_pointer_array, &tables,
fields, all_fields, order)) fields, all_fields, order))
{ {
free_underlaid_joins(thd, thd->lex->first_select_lex()); free_underlaid_joins(thd, thd->lex->first_select_lex());
...@@ -547,10 +547,12 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ...@@ -547,10 +547,12 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
else else
{ {
ha_rows scanned_limit= query_plan.scanned_rows; ha_rows scanned_limit= query_plan.scanned_rows;
table->no_keyread= 1;
query_plan.index= get_index_for_order(order, table, select, limit, query_plan.index= get_index_for_order(order, table, select, limit,
&scanned_limit, &scanned_limit,
&query_plan.using_filesort, &query_plan.using_filesort,
&reverse); &reverse);
table->no_keyread= 0;
if (!query_plan.using_filesort) if (!query_plan.using_filesort)
query_plan.scanned_rows= scanned_limit; query_plan.scanned_rows= scanned_limit;
} }
......
...@@ -23584,7 +23584,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, ...@@ -23584,7 +23584,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
If ref_key used index tree reading only ('Using index' in EXPLAIN), If ref_key used index tree reading only ('Using index' in EXPLAIN),
and best_key doesn't, then revert the decision. and best_key doesn't, then revert the decision.
*/ */
if (table->covering_keys.is_set(best_key)) if (table->covering_keys.is_set(best_key) && !table->no_keyread)
table->file->ha_start_keyread(best_key); table->file->ha_start_keyread(best_key);
else else
table->file->ha_end_keyread(); table->file->ha_end_keyread();
...@@ -28568,8 +28568,6 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table, ...@@ -28568,8 +28568,6 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
if (new_used_key_parts != NULL) if (new_used_key_parts != NULL)
*new_used_key_parts= best_key_parts; *new_used_key_parts= best_key_parts;
table->file->ha_end_keyread(); table->file->ha_end_keyread();
if (is_best_covering && !table->no_keyread)
table->file->ha_start_keyread(best_key);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -614,9 +614,11 @@ int mysql_update(THD *thd, ...@@ -614,9 +614,11 @@ int mysql_update(THD *thd,
else else
{ {
ha_rows scanned_limit= query_plan.scanned_rows; ha_rows scanned_limit= query_plan.scanned_rows;
table->no_keyread= 1;
query_plan.index= get_index_for_order(order, table, select, limit, query_plan.index= get_index_for_order(order, table, select, limit,
&scanned_limit, &need_sort, &scanned_limit, &need_sort,
&reverse); &reverse);
table->no_keyread= 0;
if (!need_sort) if (!need_sort)
query_plan.scanned_rows= scanned_limit; query_plan.scanned_rows= scanned_limit;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment