diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 2bf1ae61e11..4beda9d9ba2 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -704,7 +704,7 @@ TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name, continue; } share = it->second.get(); - if (!share->m_open_in_progress) + if (share->error || !share->m_open_in_progress) return process_found_table_share(thd, share, open_view); DEBUG_SYNC(thd, "get_share_before_COND_open_wait"); @@ -844,6 +844,13 @@ TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name, */ if (open_table_err) { share->error = true; // Allow waiters to detect the error + /* + release the lock and sleep for a short period to let the waiters + go away, and the remove the table share from cache. + */ + mysql_mutex_unlock(&LOCK_open); + my_sleep(50); + mysql_mutex_lock(&LOCK_open); share->decrement_ref_count(); table_def_cache->erase(to_string(share->table_cache_key)); #if defined(ENABLED_DEBUG_SYNC)