24#ifndef TABLE_CACHE_INCLUDED
25#define TABLE_CACHE_INCLUDED
34#include <unordered_map>
108 std::unordered_map<std::string, std::unique_ptr<Table_cache_element>>
m_cache;
145#ifdef HAVE_PSI_INTERFACE
337 if (
table->triggers &&
table->triggers->has_load_been_finalized())
356 if (
table->triggers &&
table->triggers->has_load_been_finalized())
399 DBUG_PRINT(
"info", (
"table_open_cache_triggers_overflows: %llu",
423 assert(
table->in_use == thd);
440 const std::string
key(
table->s->table_cache_key.str,
441 table->s->table_cache_key.length);
445 m_cache.emplace(
key, std::unique_ptr<Table_cache_element>(el));
477 if (
table->triggers &&
table->triggers->has_load_been_finalized())
487 if (
table->triggers &&
table->triggers->has_load_been_finalized())
492 const std::string
key(
table->s->table_cache_key.str,
493 table->s->table_cache_key.length);
536 const std::string key_str(
key, key_length);
537 const auto el_it =
m_cache.find(key_str);
538 if (el_it ==
m_cache.end())
return nullptr;
571 assert(!
table->in_use);
606 assert(
table->in_use);
610 assert(!
table->s->has_old_version());
612 table->in_use =
nullptr;
617 if (
table->triggers &&
table->triggers->has_load_been_finalized())
637 : share(share_arg), current_cache_index(0), current_table(
nullptr) {
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
An insertion policy class for I_P_List which can be used when fast push_back() operation is required.
Definition: sql_plist.h:260
Iterator for I_P_List.
Definition: sql_plist.h:168
Element counting policy class for I_P_List to be used in cases when no element counting should be don...
Definition: sql_plist.h:209
Intrusive parameterized list.
Definition: sql_plist.h:75
void remove(T *a)
Definition: sql_plist.h:124
bool is_empty() const
Definition: sql_plist.h:90
T * front()
Definition: sql_plist.h:133
T * pop_front()
Definition: sql_plist.h:135
void push_front(T *a)
Definition: sql_plist.h:91
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
my_thread_id thread_id() const
Definition: sql_class.h:2558
struct System_status_var status_var
Definition: sql_class.h:1152
Element that represents the table in the specific table cache.
Definition: table_cache.h:265
TABLE_SHARE * get_share() const
Definition: table_cache.h:290
Table_cache_element(TABLE_SHARE *share_arg)
Definition: table_cache.h:288
TABLE_list used_tables
Definition: table_cache.h:275
I_P_List< TABLE, I_P_List_adapter< TABLE, &TABLE::cache_next, &TABLE::cache_prev > > TABLE_list
Definition: table_cache.h:273
TABLE_list free_tables_slim
List of unused TABLE objects that do not have fully-loaded triggers; either because there were no tri...
Definition: table_cache.h:282
TABLE_list free_tables_full_triggers
List of unused TABLE objects with fully-loaded triggers.
Definition: table_cache.h:284
TABLE_SHARE * share
Definition: table_cache.h:285
Iterator which allows to go through all used TABLE instances for the table in all table caches.
Definition: table_cache.h:302
const TABLE_SHARE * share
Definition: table_cache.h:303
Table_cache_iterator(const TABLE_SHARE *share_arg)
Construct iterator over all used TABLE objects for the table share.
Definition: table_cache.h:636
uint current_cache_index
Definition: table_cache.h:304
void move_to_next_table()
Helper that moves iterator to the next used TABLE for the table share.
Definition: table_cache.h:644
TABLE * current_table
Definition: table_cache.h:305
void rewind()
Definition: table_cache.h:680
TABLE * operator++(int)
Get current used TABLE instance and move iterator to the next one.
Definition: table_cache.h:660
Container class for all table cache instances in the system.
Definition: table_cache.h:206
Table_cache m_table_cache[MAX_TABLE_CACHES]
An array of Table_cache instances.
Definition: table_cache.h:251
uint cached_tables()
Get total number of used and unused TABLE objects in all table caches.
Definition: table_cache.cc:234
void unlock_all_and_tdc()
Release locks on all instances of table cache and table definition cache.
Definition: table_cache.cc:259
void print_tables()
Print debug information for the contents of all table cache instances.
Definition: table_cache.cc:391
void lock_all_and_tdc()
Acquire locks on all instances of table cache and table definition cache (i.e.
Definition: table_cache.cc:248
void assert_owner_all_and_tdc()
Assert that caller owns locks on all instances of table cache and table definition cache.
Definition: table_cache.cc:289
bool init()
Initialize all instances of table cache to be used by server.
Definition: table_cache.cc:209
uint cache_index(Table_cache *cache) const
Get index for the table cache in container.
Definition: table_cache.h:223
void assert_owner_all()
Assert that caller owns locks on all instances of table cache.
Definition: table_cache.cc:279
void free_all_unused_tables()
Free all unused TABLE objects in all table cache instances.
Definition: table_cache.cc:379
static const int MAX_TABLE_CACHES
Maximum supported number of table cache instances.
Definition: table_cache.h:209
Table_cache * get_cache(THD *thd)
Get instance of table cache to be used by particular connection.
Definition: table_cache.h:218
void free_table(THD *thd, enum_tdc_remove_table_type remove_type, TABLE_SHARE *share)
Remove and free all or some (depending on parameter) TABLE objects for the table from all table cache...
Definition: table_cache.cc:306
static const int DEFAULT_MAX_TABLE_CACHES
Default number of table cache instances.
Definition: table_cache.h:212
void assert_owner(THD *thd)
Assert that caller owns lock on the table cache.
Definition: table_cache.cc:270
void destroy()
Destroy all instances of table cache which were used by server.
Definition: table_cache.cc:223
Cache for open TABLE objects.
Definition: table_cache.h:74
void lock()
Acquire lock on table cache instance.
Definition: table_cache.h:167
std::atomic< uint > m_table_triggers_count
Total number of TABLE instances in this table cache with fully-loaded triggers (both in use and unuse...
Definition: table_cache.h:143
bool add_used_table(THD *thd, TABLE *table)
Add newly created TABLE object which is going to be used right away to the table cache.
Definition: table_cache.h:418
void unlock()
Release lock on table cache instance.
Definition: table_cache.h:169
TABLE * get_table(THD *thd, const char *key, size_t key_length, bool is_update, TABLE_SHARE **share)
Get an unused TABLE instance from the table cache.
Definition: table_cache.h:528
uint loaded_triggers_tables() const
Definition: table_cache.h:195
bool init()
Initialize instance of table cache.
Definition: table_cache.cc:55
void release_table(THD *thd, TABLE *table)
Put used TABLE instance back to the table cache and mark it as unused.
Definition: table_cache.h:600
std::unordered_map< std::string, std::unique_ptr< Table_cache_element > > m_cache
The hash of Table_cache_element objects, each table/table share that has any TABLE object in the Tabl...
Definition: table_cache.h:108
void destroy()
Destroy instance of table cache.
Definition: table_cache.cc:65
void notify_triggers_load()
Notify the table cache that we have finalized loading and parsing triggers for one of its TABLE objec...
Definition: table_cache.h:193
mysql_mutex_t m_lock
The table cache lock protects the following data:
Definition: table_cache.h:99
uint m_table_count
Total number of TABLE instances for tables in this particular table cache (both in use by threads and...
Definition: table_cache.h:124
void assert_owner()
Assert that caller owns lock on the table cache.
Definition: table_cache.h:171
void free_all_unused_tables()
Free all unused TABLE objects in the table cache.
Definition: table_cache.cc:135
void check_unused()
Definition: table_cache.h:154
TABLE * m_unused_tables
List that contains all TABLE instances for tables in this particular table cache that are in not use ...
Definition: table_cache.h:116
void link_unused_table(TABLE *table)
Add table to the tail of unused tables list for table cache (i.e.
Definition: table_cache.h:327
static PSI_mutex_info m_mutex_keys[]
Definition: table_cache.h:147
static void init_psi_keys()
Init P_S instrumentation key for mutex protecting Table_cache instance.
Definition: table_cache.cc:69
void unlink_unused_table(TABLE *table)
Remove table from the unused tables list for the table cache.
Definition: table_cache.h:347
uint cached_tables() const
Get number of TABLE instances in the cache.
Definition: table_cache.h:182
static PSI_mutex_key m_lock_key
Definition: table_cache.h:146
void print_tables()
Print debug information for the contents of the table cache.
Definition: table_cache.cc:150
I_P_List< TABLE, I_P_List_adapter< TABLE, &TABLE::triggers_lru_next, &TABLE::triggers_lru_prev >, I_P_List_null_counter, I_P_List_fast_push_back< TABLE > > m_unused_triggers_lru
LRU-organized list containing all TABLE instances with fully-loaded triggers in this table cache whic...
Definition: table_cache.h:135
void remove_table(TABLE *table)
Prepare used or unused TABLE instance for destruction by removing it from the table cache.
Definition: table_cache.h:466
void free_unused_tables_if_necessary(THD *thd)
Free unused TABLE instances if total number of TABLE objects in table cache has exceeded table_cache_...
Definition: table_cache.h:369
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
mysql_mutex_t LOCK_open
LOCK_open protects the following variables/objects:
Definition: sql_base.cc:275
void intern_close_table(TABLE *table)
Definition: sql_base.cc:1189
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
#define mysql_mutex_assert_owner(M)
Wrapper, to use safe_mutex_assert_owner with instrumented mutexes.
Definition: mysql_mutex.h:112
This file includes constants used by all storage engines.
@ HA_EXTRA_IS_ATTACHED_CHILDREN
Definition: my_base.h:400
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
ABI for instrumented mutexes.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
struct result result
Definition: result.h:34
Instrumentation helpers for mutexes.
Instrumentation helpers for mutexes.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
enum_tdc_remove_table_type
Definition: sql_base.h:102
Hook class which via its methods specifies which members of T should be used for participating in a i...
Definition: sql_plist.h:198
Mutex information.
Definition: psi_mutex_bits.h:73
ulonglong table_open_cache_overflows
Definition: system_variables.h:557
ulonglong table_open_cache_triggers_overflows
Definition: system_variables.h:560
This structure is shared between different table objects.
Definition: table.h:704
Table_cache_element ** cache_element
Array of table_cache_instances pointers to elements of table caches respresenting this table in each ...
Definition: table.h:749
TABLE ** triggers_lru_prev
Definition: table.h:1446
TABLE * next
Definition: table.h:1424
TABLE * triggers_lru_next
Links for the LRU list of unused TABLE objects with fully loaded triggers in the specific instance of...
Definition: table.h:1446
TABLE * prev
Definition: table.h:1424
std::atomic_uint64_t table_open_cache_overflows
Definition: aggregated_stats_buffer.h:60
To facilitate calculating values of status variables aggregated per all THDs in real-time,...
Definition: aggregated_stats.h:39
aggregated_stats_buffer & get_shard(my_thread_id thread_id)
Definition: aggregated_stats.h:42
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
ulong table_cache_instances
Definition: table_cache.h:55
struct aggregated_stats global_aggregated_stats
Definition: mysqld.cc:1550
Table_cache_manager table_cache_manager
Container for all table cache instances in the system.
Definition: table_cache.cc:40
ulong table_cache_triggers_per_instance
Definition: table_cache.h:56
ulong table_cache_size_per_instance
Definition: mysqld.cc:1350
ulong table_cache_triggers
Definition: table_cache.h:56