My Project
Public Member Functions | Static Public Member Functions
Table_cache Class Reference

#include <table_cache.h>

List of all members.

Public Member Functions

bool init ()
void destroy ()
void lock ()
void unlock ()
void assert_owner ()
TABLEget_table (THD *thd, my_hash_value_type hash_value, const char *key, uint key_length, TABLE_SHARE **share)
void release_table (THD *thd, TABLE *table)
bool add_used_table (THD *thd, TABLE *table)
void remove_table (TABLE *table)
uint cached_tables () const
void free_all_unused_tables ()
void print_tables ()

Static Public Member Functions

static void init_psi_keys ()

Detailed Description

Cache for open TABLE objects.

The idea behind this cache is that most statements don't need to go to a central table definition cache to get a TABLE object and therefore don't need to lock LOCK_open mutex. Instead they only need to go to one Table_cache instance (the specific instance is determined by thread id) and only lock the mutex protecting this cache. DDL statements that need to remove all TABLE objects from all caches need to lock mutexes for all Table_cache instances, but they are rare.

This significantly increases scalability in some scenarios.


Member Function Documentation

bool Table_cache::add_used_table ( THD *  thd,
TABLE table 
) [inline]

Add newly created TABLE object which is going to be used right away to the table cache.

Note:
Caller should own lock on the table cache.
Sets TABLE::in_use member as side effect.
Return values:
false- success.
true- failure.
void Table_cache::assert_owner ( ) [inline]

Assert that caller owns lock on the table cache.

uint Table_cache::cached_tables ( ) const [inline]

Get number of TABLE instances in the cache.

Destroy instance of table cache.

Free all unused TABLE objects in the table cache.

TABLE * Table_cache::get_table ( THD *  thd,
my_hash_value_type  hash_value,
const char *  key,
uint  key_length,
TABLE_SHARE **  share 
) [inline]

Get an unused TABLE instance from the table cache.

Parameters:
thdThread context.
hash_valueHash value for the key identifying table.
keyKey identifying table.
key_lengthLength of key for the table.
[out]shareNULL - if table cache doesn't contain any information about the table (i.e. doesn't have neither used nor unused TABLE objects for it). Pointer to TABLE_SHARE for the table otherwise.
Note:
Caller should own lock on the table cache.
Sets TABLE::in_use member as side effect.
Return values:
non-NULL- pointer to unused TABLE object, "share" out-parameter contains pointer to TABLE_SHARE for this table.
NULL- no unused TABLE object was found, "share" parameter contains pointer to TABLE_SHARE for this table if there are used TABLE objects in cache and NULL otherwise.
bool Table_cache::init ( void  )

Initialize instance of table cache.

Return values:
false- success.
true- failure.
void Table_cache::init_psi_keys ( ) [static]

Init P_S instrumentation key for mutex protecting Table_cache instance.

void Table_cache::lock ( void  ) [inline]

Acquire lock on table cache instance.

Print debug information for the contents of the table cache.

void Table_cache::release_table ( THD *  thd,
TABLE table 
) [inline]

Put used TABLE instance back to the table cache and mark it as unused.

Note:
Caller should own lock on the table cache.
Sets TABLE::in_use member as side effect.
void Table_cache::remove_table ( TABLE table) [inline]

Prepare used or unused TABLE instance for destruction by removing it from the table cache.

Note:
Caller should own lock on the table cache.
void Table_cache::unlock ( void  ) [inline]

Release lock on table cache instance.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines