From daf333abcfc056b9fc85ec8883ef9e949b0ad8d4 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 17 Jun 2019 11:20:31 +0300 Subject: [PATCH] Rename of stat table tried to rename open table. When compiling with -DEXTRA_DEBUG and run main.stat_tables_missing on go the warning: Warning: Table: ./mysql/column_stats is open on rename old_table This happened because rename_table_in_stat_tables() re-open the table that was to be renamed. Fixed by moving update of stat tables after all renames has been made. --- sql/sql_table.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 41687de5c8e..f2be573d984 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9157,11 +9157,6 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, close_all_tables_for_name(thd, table->s, HA_EXTRA_PREPARE_FOR_RENAME, NULL); - (void) rename_table_in_stat_tables(thd, &alter_ctx->db, - &alter_ctx->table_name, - &alter_ctx->new_db, - &alter_ctx->new_alias); - if (mysql_rename_table(old_db_type, &alter_ctx->db, &alter_ctx->table_name, &alter_ctx->new_db, &alter_ctx->new_alias, 0)) error= -1; @@ -9178,6 +9173,12 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, NO_FK_CHECKS); error= -1; } + /* Update stat tables last. This is to be able to handle rename of a stat table */ + if (error == 0) + (void) rename_table_in_stat_tables(thd, &alter_ctx->db, + &alter_ctx->table_name, + &alter_ctx->new_db, + &alter_ctx->new_alias); } if (likely(!error))