Browse Source

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
pull/1510/head
Monty 6 years ago
parent
commit
e3130d22e1
  1. 10
      mysql-test/main/keyread.result
  2. 20
      mysql-test/main/keyread.test
  3. 6
      sql/sql_delete.cc
  4. 4
      sql/sql_select.cc
  5. 2
      sql/sql_update.cc

10
mysql-test/main/keyread.result

@ -4,3 +4,13 @@ select distinct f1 from v1;
f1
drop view v1;
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;

20
mysql-test/main/keyread.test

@ -8,3 +8,23 @@ create view v1 as select * from t1 where f2 = 1;
select distinct f1 from v1;
drop view v1;
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;

6
sql/sql_delete.cc

@ -379,8 +379,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
tables.table = table;
tables.alias = table_list->alias;
if (select_lex->setup_ref_array(thd, order_list->elements) ||
setup_order(thd, select_lex->ref_pointer_array, &tables,
if (select_lex->setup_ref_array(thd, order_list->elements) ||
setup_order(thd, select_lex->ref_pointer_array, &tables,
fields, all_fields, order))
{
free_underlaid_joins(thd, thd->lex->first_select_lex());
@ -547,10 +547,12 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
else
{
ha_rows scanned_limit= query_plan.scanned_rows;
table->no_keyread= 1;
query_plan.index= get_index_for_order(order, table, select, limit,
&scanned_limit,
&query_plan.using_filesort,
&reverse);
table->no_keyread= 0;
if (!query_plan.using_filesort)
query_plan.scanned_rows= scanned_limit;
}

4
sql/sql_select.cc

@ -23584,7 +23584,7 @@ check_reverse_order:
If ref_key used index tree reading only ('Using index' in EXPLAIN),
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);
else
table->file->ha_end_keyread();
@ -28568,8 +28568,6 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
if (new_used_key_parts != NULL)
*new_used_key_parts= best_key_parts;
table->file->ha_end_keyread();
if (is_best_covering && !table->no_keyread)
table->file->ha_start_keyread(best_key);
DBUG_RETURN(TRUE);
}

2
sql/sql_update.cc

@ -614,9 +614,11 @@ int mysql_update(THD *thd,
else
{
ha_rows scanned_limit= query_plan.scanned_rows;
table->no_keyread= 1;
query_plan.index= get_index_for_order(order, table, select, limit,
&scanned_limit, &need_sort,
&reverse);
table->no_keyread= 0;
if (!need_sort)
query_plan.scanned_rows= scanned_limit;

Loading…
Cancel
Save