From b22285e4821b49546de9b88990bbc9c453dc14b2 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 19 Jan 2021 08:02:37 -0800 Subject: MDEV-16940 Server crashes in unsafe_key_update upon attempt to update view through 2nd execution of SP This bug caused a server crash on the second call of any stored procedure that contained an UPDATE statement over a multi-table view reporting an error message at the prepare stage. On the first call of the stored procedure after reporting an error at the preparation stage of the UPDATE statement finished without calling the function SELECT_LEX::save_prep_leaf_tables() for the SELECT used as the definition of the view. This left the SELECT_LEX structure used by the UPDATE statement in an inconsistent state for second call of the stored procedure. Approved by Oleksandr Byelkin --- sql/sql_update.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sql/sql_update.cc') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 7454d16d55d..01743a6751e 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1398,6 +1398,9 @@ bool Multiupdate_prelocking_strategy::handle_end(THD *thd) if (select_lex->handle_derived(thd->lex, DT_MERGE)) DBUG_RETURN(1); + if (thd->lex->save_prep_leaf_tables()) + DBUG_RETURN(1); + List *fields= &lex->select_lex.item_list; if (setup_fields_with_no_wrap(thd, Ref_ptr_array(), *fields, MARK_COLUMNS_WRITE, 0, 0)) -- cgit v1.2.1 From 1398160a719394cff3e7e4ee214f51375e8825a1 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 26 Jan 2021 14:41:23 +0300 Subject: MDEV-24522 Assertion `inited==NONE' fails upon UPDATE on versioned table with unique blob Cause: no table->update_handler cloned at the moment of vers_insert_history_row(). update_handler is needed because there can't be several inited indexes at once in the same handler. First index is inited by QUICK_RANGE_SELECT::reset(). Then when history row is inserted check_duplicate_long_entry_key() is done and it requires another index. --- sql/sql_update.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sql/sql_update.cc') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 7230c9c5f60..d64a96f5070 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1108,6 +1108,7 @@ update_begin: { store_record(table, record[2]); table->mark_columns_per_binlog_row_image(); + table->clone_handler_for_update(); error= vers_insert_history_row(table); restore_record(table, record[2]); if (unlikely(error)) @@ -2599,6 +2600,7 @@ error: if (has_vers_fields && table->versioned(VERS_TIMESTAMP)) { store_record(table, record[2]); + table->clone_handler_for_update(); if (unlikely(error= vers_insert_history_row(table))) { restore_record(table, record[2]); -- cgit v1.2.1