diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2cbda99e313..3b268a04110 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7946,10 +7946,8 @@ static bool mysql_inplace_alter_table(THD *thd, // Rename altered table if requested. if (alter_ctx->is_table_renamed()) { - // Remove TABLE and TABLE_SHARE for old name from TDC. - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, - alter_ctx->db.str, alter_ctx->table_name.str); - + DBUG_ASSERT(!tdc_share_is_cached(thd, alter_ctx->db.str, + alter_ctx->table_name.str)); if (mysql_rename_table(db_type, &alter_ctx->db, &alter_ctx->table_name, &alter_ctx->new_db, &alter_ctx->new_alias, 0)) { diff --git a/sql/table_cache.cc b/sql/table_cache.cc index ec5fd0ca0c7..bdc15909432 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -776,6 +776,23 @@ void tdc_unlock_share(TDC_element *element) } +int tdc_share_is_cached(THD *thd, const char *db, const char *table_name) +{ + char key[MAX_DBKEY_LENGTH]; + + if (unlikely(fix_thd_pins(thd))) + return -1; + + if (lf_hash_search(&tdc_hash, thd->tdc_hash_pins, (uchar*) key, + tdc_create_key(key, db, table_name))) + { + lf_hash_search_unpin(thd->tdc_hash_pins); + return 1; + } + return 0; +} + + /* Get TABLE_SHARE for a table. diff --git a/sql/table_cache.h b/sql/table_cache.h index 37faab87f0c..cf880b7d9b4 100644 --- a/sql/table_cache.h +++ b/sql/table_cache.h @@ -77,6 +77,7 @@ extern void tdc_purge(bool all); extern TDC_element *tdc_lock_share(THD *thd, const char *db, const char *table_name); extern void tdc_unlock_share(TDC_element *element); +int tdc_share_is_cached(THD *thd, const char *db, const char *table_name); extern TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags, TABLE **out_table= 0); extern void tdc_release_share(TABLE_SHARE *share);