Skip to content

Commit 4197014

Browse files
committed
Yet less TDC hash lookups
Let auto repair table and truncate table routines flush TABLE_SHARE directly. Part of MDEV-17882 - Cleanup refresh version
1 parent 7a94761 commit 4197014

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

sql/sql_base.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,9 +2942,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
29422942
result= FALSE;
29432943
}
29442944

2945-
tdc_release_share(share);
2946-
/* Remove the repaired share from the table cache. */
2947-
tdc_remove_table(thd, table_list->db.str, table_list->table_name.str);
2945+
tdc_remove_referenced_share(thd, share);
29482946
end_free:
29492947
my_free(entry);
29502948
return result;

sql/sql_truncate.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref,
336336
}
337337
#endif
338338

339-
tdc_release_share(share);
339+
if (!versioned)
340+
tdc_remove_referenced_share(thd, share);
341+
else
342+
tdc_release_share(share);
340343

341344
if (hton == view_pseudo_hton)
342345
{
@@ -372,12 +375,6 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref,
372375
if (*hton_can_recreate)
373376
close_all_tables_for_name(thd, table->s, HA_EXTRA_NOT_USED, NULL);
374377
}
375-
else
376-
{
377-
/* Table is already locked exclusively. Remove cached instances. */
378-
tdc_remove_table(thd, table_ref->db.str, table_ref->table_name.str);
379-
}
380-
381378
DBUG_RETURN(FALSE);
382379
}
383380

sql/table_cache.cc

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,20 @@ void tdc_release_share(TABLE_SHARE *share)
996996
}
997997

998998

999+
void tdc_remove_referenced_share(THD *thd, TABLE_SHARE *share)
1000+
{
1001+
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, share->db.str,
1002+
share->table_name.str,
1003+
MDL_EXCLUSIVE));
1004+
share->tdc->flush_unused(false);
1005+
mysql_mutex_lock(&share->tdc->LOCK_table_share);
1006+
share->tdc->wait_for_refs(1);
1007+
DBUG_ASSERT(share->tdc->all_tables.is_empty());
1008+
share->tdc->ref_count--;
1009+
tdc_delete_share_from_hash(share->tdc);
1010+
}
1011+
1012+
9991013
/**
10001014
Removes all TABLE instances and corresponding TABLE_SHARE
10011015
@@ -1009,7 +1023,6 @@ void tdc_release_share(TABLE_SHARE *share)
10091023

10101024
void tdc_remove_table(THD *thd, const char *db, const char *table_name)
10111025
{
1012-
Share_free_tables::List purge_tables;
10131026
TDC_element *element;
10141027
DBUG_ENTER("tdc_remove_table");
10151028
DBUG_PRINT("enter", ("name: %s", table_name));
@@ -1042,18 +1055,10 @@ void tdc_remove_table(THD *thd, const char *db, const char *table_name)
10421055
mysql_mutex_unlock(&LOCK_unused_shares);
10431056

10441057
element->ref_count++;
1045-
1046-
tc_remove_all_unused_tables(element, &purge_tables);
10471058
mysql_mutex_unlock(&element->LOCK_table_share);
10481059

1049-
while (auto table= purge_tables.pop_front())
1050-
intern_close_table(table);
1051-
1052-
mysql_mutex_lock(&element->LOCK_table_share);
1053-
element->wait_for_refs(1);
1054-
DBUG_ASSERT(element->all_tables.is_empty());
1055-
element->ref_count--;
1056-
tdc_delete_share_from_hash(element);
1060+
/* We have to relock the mutex to avoid code duplication. Sigh. */
1061+
tdc_remove_referenced_share(thd, element->share);
10571062
DBUG_VOID_RETURN;
10581063
}
10591064

sql/table_cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ int tdc_share_is_cached(THD *thd, const char *db, const char *table_name);
7777
extern TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
7878
TABLE **out_table= 0);
7979
extern void tdc_release_share(TABLE_SHARE *share);
80+
void tdc_remove_referenced_share(THD *thd, TABLE_SHARE *share);
8081
void tdc_remove_table(THD *thd, const char *db, const char *table_name);
8182

8283
extern int tdc_wait_for_old_version(THD *thd, const char *db,

0 commit comments

Comments
 (0)