My Project
Public Member Functions | Public Attributes
TABLE_SHARE Struct Reference

#include <table.h>

List of all members.

Public Member Functions

handlertondb_type () const
void set_table_cache_key (char *key_buff, uint key_length)
void set_table_cache_key (char *key_buff, const char *key, uint key_length)
bool honor_global_locks ()
ulonglong get_table_def_version ()
bool has_old_version () const
enum enum_table_ref_type get_table_ref_type () const
ulonglong get_table_ref_version () const
bool visit_subgraph (Wait_for_flush *waiting_ticket, MDL_wait_for_graph_visitor *gvisitor)
bool wait_for_old_version (THD *thd, struct timespec *abstime, uint deadlock_weight)
void destroy ()

Public Attributes

TABLE_CATEGORY table_category
HASH name_hash
MEM_ROOT mem_root
TYPELIB keynames
TYPELIB fieldnames
TYPELIB * intervals
mysql_mutex_t LOCK_ha_data
TABLE_SHAREnext
TABLE_SHARE ** prev
Table_cache_element ** cache_element
Field ** field
Field ** found_next_number_field
KEYkey_info
uint * blob_field
uchar * default_values
LEX_STRING comment
const CHARSET_INFO * table_charset
MY_BITMAP all_set
LEX_STRING table_cache_key
LEX_STRING db
LEX_STRING table_name
LEX_STRING path
LEX_STRING normalized_path
LEX_STRING connect_string
key_map keys_in_use
key_map keys_for_keyread
ha_rows min_rows
ha_rows max_rows
ulong avg_row_length
ulong version
ulong mysql_version
ulong reclength
plugin_ref db_plugin
enum row_type row_type
enum tmp_table_type tmp_table
uint ref_count
uint key_block_size
uint stats_sample_pages
enum_stats_auto_recalc stats_auto_recalc
uint null_bytes
uint last_null_bit_pos
uint fields
uint rec_buff_length
uint keys
uint key_parts
uint max_key_length
uint max_unique_length
uint total_key_length
uint uniques
uint null_fields
uint blob_fields
uint varchar_fields
uint db_create_options
uint db_options_in_use
uint db_record_offset
uint rowid_field_offset
uint primary_key
uint next_number_index
uint next_number_key_offset
uint next_number_keypart
uint error
uint open_errno
uint errarg
uint column_bitmap_size
uchar frm_version
bool null_field_first
bool system
bool crypted
bool db_low_byte_first
bool crashed
bool is_view
Table_id table_map_id
int cached_row_logging_check
enum ha_storage_media default_storage_media
char * tablespace
const TABLE_FIELD_DEFtable_field_def_cache
Handler_shareha_share
PSI_table_share * m_psi
Wait_for_flush_list m_flush_tickets
const File_parserview_def

Detailed Description

This structure is shared between different table objects. There is one instance of table share per one table in the database.


Member Function Documentation

Release resources and free memory occupied by the table share.

Release resources (plugins) used by the share and free its memory. TABLE_SHARE is self-contained -- it's stored in its own MEM_ROOT. Free this MEM_ROOT.

enum enum_table_ref_type TABLE_SHARE::get_table_ref_type ( ) const [inline]

Convert unrelated members of TABLE_SHARE to one enum representing its type.

Todo:
perhaps we need to have a member instead of a function.
ulonglong TABLE_SHARE::get_table_ref_version ( ) const [inline]

Return a table metadata version. for base tables and views, we return table_map_id. It is assigned from a global counter incremented for each new table loaded into the table definition cache (TDC). for temporary tables it's table_map_id again. But for temporary tables table_map_id is assigned from thd->query_id. The latter is assigned from a thread local counter incremented for every new SQL statement. Since temporary tables are thread-local, each temporary table gets a unique id. for everything else (e.g. information schema tables), the version id is zero.

This choice of version id is a large compromise to have a working prepared statement validation in 5.1. In future version ids will be persistent, as described in WL#4180.

Let's try to explain why and how this limited solution allows to validate prepared statements.

Firstly, sets (in mathematical sense) of version numbers never intersect for different table types. Therefore, version id of a temporary table is never compared with a version id of a view, and vice versa.

Secondly, for base tables and views, we know that each DDL flushes the respective share from the TDC. This ensures that whenever a table is altered or dropped and recreated, it gets a new version id. Unfortunately, since elements of the TDC are also flushed on LRU basis, this choice of version ids leads to false positives. E.g. when the TDC size is too small, we may have a SELECT FROM INFORMATION_SCHEMA.TABLES flush all its elements, which in turn will lead to a validation error and a subsequent reprepare of all prepared statements. This is considered acceptable, since as long as prepared statements are automatically reprepared, spurious invalidation is only a performance hit. Besides, no better simple solution exists.

For temporary tables, using thd->query_id ensures that if a temporary table was altered or recreated, a new version id is assigned. This suits validation needs very well and will perhaps never change.

Metadata of information schema tables never changes. Thus we can safely assume 0 for a good enough version id.

Finally, by taking into account table type, we always track that a change has taken place when a view is replaced with a base table, a base table is replaced with a temporary table and so on.

See also:
TABLE_LIST::is_table_ref_id_equal()
bool TABLE_SHARE::has_old_version ( ) const [inline]

Is this table share being expelled from the table definition cache?

bool TABLE_SHARE::visit_subgraph ( Wait_for_flush wait_for_flush,
MDL_wait_for_graph_visitor gvisitor 
)

Traverse portion of wait-for graph which is reachable through this table share in search for deadlocks.

Parameters:
waiting_ticketTicket representing wait for this share.
dvisitorDeadlock detection visitor.
Return values:
TRUEA deadlock is found. A victim is remembered by the visitor.
FALSENo deadlocks, it's OK to begin wait.
bool TABLE_SHARE::wait_for_old_version ( THD *  thd,
struct timespec *  abstime,
uint  deadlock_weight 
)

Wait until the subject share is removed from the table definition cache and make sure it's destroyed.

Parameters:
mdl_contextMDL context for thread which is going to wait.
abstimeTimeout for waiting as absolute time value.
deadlock_weightWeight of this wait for deadlock detector.
Precondition:
LOCK_open is write locked, the share is used (has non-zero reference count), is marked for flush and this connection does not reference the share. LOCK_open will be unlocked temporarily during execution.
Return values:
FALSE- Success.
TRUE- Error (OOM, deadlock, timeout, etc...).

Member Data Documentation

Array of table_cache_instances pointers to elements of table caches respresenting this table in each of Table_cache instances. Allocated along with the share itself in alloc_table_share(). Each element of the array is protected by Table_cache::m_lock in the corresponding Table_cache. False sharing should not be a problem in this case as elements of this array are supposed to be updated rarely.

Main handler's share

List of tickets representing threads waiting for the share to be flushed.

PSI_table_share* TABLE_SHARE::m_psi

Instrumentation for this table share.

Category of this table.

Cache the checked structure of this table.

The pointer data is used to describe the structure that a instance of the table must have. Each element of the array specifies a field that must exist on the table.

The pointer is cached in order to perform the check only once -- when the table is loaded from the disk.

TABLE_SHARE version, if changed the TABLE_SHARE must be reopened. NOTE: The TABLE_SHARE will not be reopened during LOCK TABLES in close_thread_tables!!!

For shares representing views File_parser object with view definition read from .FRM file.


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