From 1a74d12da674d49304ffdc62e100ba8d19f90f13 Mon Sep 17 00:00:00 2001 From: halfspawn Date: Tue, 26 Sep 2017 11:52:31 +0200 Subject: MDEV-12874 UPDATE statements with the same source and target --- sql/sql_update.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'sql') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index a0c1f3598b5..c6959509a08 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -278,6 +278,7 @@ int mysql_update(THD *thd, killed_state killed_status= NOT_KILLED; Update_plan query_plan(thd->mem_root); Explain_update *explain; + TABLE_LIST *update_source_table; query_plan.index= MAX_KEY; query_plan.using_filesort= FALSE; DBUG_ENTER("mysql_update"); @@ -290,9 +291,11 @@ int mysql_update(THD *thd, if (mysql_handle_derived(thd->lex, DT_INIT)) DBUG_RETURN(1); - if (table_list->is_multitable()) + if (((update_source_table=unique_table(thd, table_list, + table_list->next_global, 0)) || + table_list->is_multitable())) { - DBUG_ASSERT(table_list->view != 0); + DBUG_ASSERT(update_source_table || table_list->view != 0); DBUG_PRINT("info", ("Switch to multi-update")); /* pass counter value */ thd->lex->table_count= table_count; @@ -1540,16 +1543,6 @@ int mysql_multi_update_prepare(THD *thd) } DBUG_PRINT("info", ("table: %s want_privilege: %u", tl->alias, (uint) table->grant.want_privilege)); - if (tl->lock_type != TL_READ && - tl->lock_type != TL_READ_NO_INSERT) - { - TABLE_LIST *duplicate; - if ((duplicate= unique_table(thd, tl, table_list, 0))) - { - update_non_unique_table_error(table_list, "UPDATE", duplicate); - DBUG_RETURN(TRUE); - } - } } /* Set exclude_from_table_unique_test value back to FALSE. It is needed for -- cgit v1.2.1