diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-12-21 23:51:49 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2020-04-03 13:01:21 +0400 |
commit | 4197014ba0ba8cb895f3b49b7fdf8bbfe9fca826 (patch) | |
tree | 67a37972e8cc492ce5bcd349855eb1d8df439f2e | |
parent | 7a947614fbf8b925ae3df70ec8df80c745eafd4c (diff) | |
download | mariadb-git-4197014ba0ba8cb895f3b49b7fdf8bbfe9fca826.tar.gz |
Yet less TDC hash lookups
Let auto repair table and truncate table routines flush TABLE_SHARE
directly.
Part of MDEV-17882 - Cleanup refresh version
-rw-r--r-- | sql/sql_base.cc | 4 | ||||
-rw-r--r-- | sql/sql_truncate.cc | 11 | ||||
-rw-r--r-- | sql/table_cache.cc | 27 | ||||
-rw-r--r-- | sql/table_cache.h | 1 |
4 files changed, 22 insertions, 21 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 664071a27f5..dfff349eb76 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2942,9 +2942,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list) result= FALSE; } - tdc_release_share(share); - /* Remove the repaired share from the table cache. */ - tdc_remove_table(thd, table_list->db.str, table_list->table_name.str); + tdc_remove_referenced_share(thd, share); end_free: my_free(entry); return result; diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index 1d2ec66eae6..a745293ec31 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -336,7 +336,10 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, } #endif - tdc_release_share(share); + if (!versioned) + tdc_remove_referenced_share(thd, share); + else + tdc_release_share(share); if (hton == view_pseudo_hton) { @@ -372,12 +375,6 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, if (*hton_can_recreate) close_all_tables_for_name(thd, table->s, HA_EXTRA_NOT_USED, NULL); } - else - { - /* Table is already locked exclusively. Remove cached instances. */ - tdc_remove_table(thd, table_ref->db.str, table_ref->table_name.str); - } - DBUG_RETURN(FALSE); } diff --git a/sql/table_cache.cc b/sql/table_cache.cc index 82c60359e88..62ccfba7e7d 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -996,6 +996,20 @@ void tdc_release_share(TABLE_SHARE *share) } +void tdc_remove_referenced_share(THD *thd, TABLE_SHARE *share) +{ + DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, share->db.str, + share->table_name.str, + MDL_EXCLUSIVE)); + share->tdc->flush_unused(false); + mysql_mutex_lock(&share->tdc->LOCK_table_share); + share->tdc->wait_for_refs(1); + DBUG_ASSERT(share->tdc->all_tables.is_empty()); + share->tdc->ref_count--; + tdc_delete_share_from_hash(share->tdc); +} + + /** Removes all TABLE instances and corresponding TABLE_SHARE @@ -1009,7 +1023,6 @@ void tdc_release_share(TABLE_SHARE *share) void tdc_remove_table(THD *thd, const char *db, const char *table_name) { - Share_free_tables::List purge_tables; TDC_element *element; DBUG_ENTER("tdc_remove_table"); DBUG_PRINT("enter", ("name: %s", table_name)); @@ -1042,18 +1055,10 @@ void tdc_remove_table(THD *thd, const char *db, const char *table_name) mysql_mutex_unlock(&LOCK_unused_shares); element->ref_count++; - - tc_remove_all_unused_tables(element, &purge_tables); mysql_mutex_unlock(&element->LOCK_table_share); - while (auto table= purge_tables.pop_front()) - intern_close_table(table); - - mysql_mutex_lock(&element->LOCK_table_share); - element->wait_for_refs(1); - DBUG_ASSERT(element->all_tables.is_empty()); - element->ref_count--; - tdc_delete_share_from_hash(element); + /* We have to relock the mutex to avoid code duplication. Sigh. */ + tdc_remove_referenced_share(thd, element->share); DBUG_VOID_RETURN; } diff --git a/sql/table_cache.h b/sql/table_cache.h index bffb782849c..433df5e0328 100644 --- a/sql/table_cache.h +++ b/sql/table_cache.h @@ -77,6 +77,7 @@ 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); +void tdc_remove_referenced_share(THD *thd, TABLE_SHARE *share); void tdc_remove_table(THD *thd, const char *db, const char *table_name); extern int tdc_wait_for_old_version(THD *thd, const char *db, |