16 #include "table_cache.h"
26 #ifdef HAVE_PSI_INTERFACE
27 PSI_mutex_key Table_cache::m_lock_key;
28 PSI_mutex_info Table_cache::m_mutex_keys[]= {
29 { &m_lock_key,
"LOCK_table_cache", 0}
34 extern "C" uchar *table_cache_key(
const uchar *
record,
36 my_bool not_used __attribute__((unused)))
39 *length= share->table_cache_key.length;
40 return (uchar*) share->table_cache_key.str;
60 m_unused_tables= NULL;
63 if (my_hash_init(&m_cache, &my_charset_bin,
64 table_cache_size_per_instance, 0, 0,
65 table_cache_key, (my_hash_free_key) table_cache_free_entry,
79 my_hash_free(&m_cache);
88 #ifdef HAVE_PSI_INTERFACE
95 void Table_cache::check_unused()
99 if (m_unused_tables != NULL)
101 TABLE *cur_link= m_unused_tables;
102 TABLE *start_link= m_unused_tables;
105 if (cur_link != cur_link->next->prev || cur_link != cur_link->prev->next)
107 DBUG_PRINT(
"error",(
"Unused_links aren't linked properly"));
110 }
while (count++ < m_table_count &&
111 (cur_link= cur_link->next) != start_link);
112 if (cur_link != start_link)
113 DBUG_PRINT(
"error",(
"Unused_links aren't connected"));
116 for (uint idx= 0; idx < m_cache.records; idx++)
123 while ((entry= it++))
126 DBUG_ASSERT(entry->db_stat && entry->file);
128 DBUG_ASSERT(! entry->file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN));
131 DBUG_PRINT(
"error",(
"Used table is in share's list of unused tables"));
134 it.init(el->used_tables);
135 while ((entry= it++))
138 DBUG_PRINT(
"error",(
"Unused table is in share's list of used tables"));
143 DBUG_PRINT(
"error",(
"Unused_links doesn't match open_cache: diff: %d",
155 while (m_unused_tables)
157 TABLE *table_to_free= m_unused_tables;
159 intern_close_table(table_to_free);
174 compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions));
176 for (uint idx= 0; idx < m_cache.records; idx++)
183 while ((entry= it++))
185 printf(
"%-14.14s %-32s%6ld%8ld%6d %s\n",
186 entry->s->db.str, entry->s->table_name.str, entry->s->version,
187 entry->in_use->thread_id, entry->db_stat ? 1 : 0,
188 lock_descriptions[(
int)entry->reginfo.lock_type]);
190 it.init(el->free_tables);
191 while ((entry= it++))
194 printf(
"%-14.14s %-32s%6ld%8ld%6d %s\n",
195 entry->s->db.str, entry->s->table_name.str, entry->s->version,
196 0L, entry->db_stat ? 1 : 0,
"Not in use");
200 if (m_unused_tables != NULL)
202 TABLE *start_link= m_unused_tables;
203 TABLE *lnk= m_unused_tables;
206 if (lnk != lnk->next->prev || lnk != lnk->prev->next)
208 printf(
"unused_links isn't linked properly\n");
211 }
while (count++ < m_table_count && (lnk= lnk->next) != start_link);
212 if (lnk != start_link)
213 printf(
"Unused_links aren't connected\n");
217 printf(
"Unused_links (%d) doesn't match table_def_cache: %d\n", count,
233 for (uint
i= 0;
i < table_cache_instances;
i++)
235 if (m_table_cache[
i].
init())
237 for (uint j= 0; j <
i; j++)
251 for (uint
i= 0;
i < table_cache_instances;
i++)
267 for (uint
i= 0;
i < table_cache_instances;
i++)
281 for (uint
i= 0;
i < table_cache_instances;
i++)
282 m_table_cache[
i].lock();
297 for (uint
i= 0;
i < table_cache_instances;
i++)
298 m_table_cache[
i].unlock();
308 for (uint
i= 0;
i < table_cache_instances;
i++)
309 m_table_cache[
i].assert_owner();
338 enum_tdc_remove_table_type remove_type,
355 for (uint
i= 0;
i < table_cache_instances;
i++)
363 if (remove_type == TDC_RT_REMOVE_ALL)
364 DBUG_ASSERT(cache_el[i]->used_tables.is_empty());
365 else if (remove_type == TDC_RT_REMOVE_NOT_OWN ||
366 remove_type == TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE)
369 while ((table= it2++))
371 if (table->in_use != thd)
377 while ((table= it++))
380 intern_close_table(table);
393 for (uint
i= 0;
i < table_cache_instances;
i++)
405 puts(
"DB Table Version Thread Open Lock");
407 for (uint
i= 0;
i < table_cache_instances;
i++)