My Project
Classes | Defines | Functions | Variables
Data Dictionary

Classes

class  MDL_deadlock_handler
class  MDL_deadlock_discovery_repair_handler

Defines

#define WRONG_GRANT   (Field*) -1

Functions

uint get_table_def_key (const TABLE_LIST *table_list, const char **key)
uchar * table_def_key (const uchar *record, size_t *length, my_bool not_used __attribute__((unused)))
bool table_def_init (void)
void table_def_start_shutdown (void)
void table_def_free (void)
uint cached_table_definitions (void)
TABLE_SHAREget_table_share (THD *thd, TABLE_LIST *table_list, const char *key, uint key_length, uint db_flags, int *error, my_hash_value_type hash_value)
void release_table_share (TABLE_SHARE *share)
TABLE_SHAREget_cached_table_share (const char *db, const char *table_name)
OPEN_TABLE_LISTlist_open_tables (THD *thd, const char *db, const char *wild)
void intern_close_table (TABLE *table)
void free_io_cache (TABLE *table)
bool close_cached_tables (THD *thd, TABLE_LIST *tables, bool wait_for_refresh, ulong timeout)
bool close_cached_connection_tables (THD *thd, LEX_STRING *connection)
void mark_tmp_table_for_reuse (TABLE *table)
void close_all_tables_for_name (THD *thd, TABLE_SHARE *share, bool remove_from_locked_tables, TABLE *skip_table)
void close_thread_tables (THD *thd)
void close_thread_table (THD *thd, TABLE **table_ptr)
bool close_temporary_tables (THD *thd)
TABLE_LISTfind_table_in_list (TABLE_LIST *table, TABLE_LIST *TABLE_LIST::*link, const char *db_name, const char *table_name)
TABLE_LISTunique_table (THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, bool check_alias)
void update_non_unique_table_error (TABLE_LIST *update, const char *operation, TABLE_LIST *duplicate)
TABLEfind_temporary_table (THD *thd, const char *db, const char *table_name)
TABLEfind_temporary_table (THD *thd, const TABLE_LIST *tl)
TABLEfind_temporary_table (THD *thd, const char *table_key, uint table_key_length)
int drop_temporary_table (THD *thd, TABLE_LIST *table_list, bool *is_trans)
void close_temporary_table (THD *thd, TABLE *table, bool free_share, bool delete_table)
void close_temporary (TABLE *table, bool free_share, bool delete_table)
bool rename_temporary_table (THD *thd, TABLE *table, const char *db, const char *table_name)
bool wait_while_table_is_used (THD *thd, TABLE *table, enum ha_extra_function function)
void drop_open_table (THD *thd, TABLE *table, const char *db_name, const char *table_name)
bool check_if_table_exists (THD *thd, TABLE_LIST *table, bool *exists)
bool open_table (THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
TABLEfind_locked_table (TABLE *list, const char *db, const char *table_name)
TABLEfind_table_for_mdl_upgrade (THD *thd, const char *db, const char *table_name, bool no_error)
void assign_new_table_id (TABLE_SHARE *share)
bool tdc_open_view (THD *thd, TABLE_LIST *table_list, const char *alias, const char *cache_key, uint cache_key_length, uint flags)
thr_lock_type read_lock_type_for_table (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool routine_modifies_data)
uchar * schema_set_get_key (const uchar *record, size_t *length, my_bool not_used __attribute__((unused)))
bool lock_table_names (THD *thd, TABLE_LIST *tables_start, TABLE_LIST *tables_end, ulong lock_wait_timeout, uint flags)
bool open_tables (THD *thd, TABLE_LIST **start, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
TABLEopen_n_lock_single_table (THD *thd, TABLE_LIST *table_l, thr_lock_type lock_type, uint flags, Prelocking_strategy *prelocking_strategy)
 Open and lock one table.
TABLEopen_ltable (THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type, uint lock_flags)
bool open_and_lock_tables (THD *thd, TABLE_LIST *tables, bool derived, uint flags, Prelocking_strategy *prelocking_strategy)
bool open_normal_and_derived_tables (THD *thd, TABLE_LIST *tables, uint flags)
bool lock_tables (THD *thd, TABLE_LIST *tables, uint count, uint flags)
void close_tables_for_reopen (THD *thd, TABLE_LIST **tables, const MDL_savepoint &start_of_statement_svp)
TABLEopen_table_uncached (THD *thd, const char *path, const char *db, const char *table_name, bool add_to_temporary_tables_list, bool open_in_engine)
bool rm_temporary_table (handlerton *base, const char *path)
bool open_temporary_table (THD *thd, TABLE_LIST *tl)
bool open_temporary_tables (THD *thd, TABLE_LIST *tl_list)
Fieldfind_field_in_table (THD *thd, TABLE *table, const char *name, uint length, bool allow_rowid, uint *cached_field_index_ptr)
Fieldfind_field_in_table_ref (THD *thd, TABLE_LIST *table_list, const char *name, uint length, const char *item_name, const char *db_name, const char *table_name, Item **ref, bool check_privileges, bool allow_rowid, uint *cached_field_index_ptr, bool register_tree_change, TABLE_LIST **actual_table)
Fieldfind_field_in_table_sef (TABLE *table, const char *name)
Fieldfind_field_in_tables (THD *thd, Item_ident *item, TABLE_LIST *first_table, TABLE_LIST *last_table, Item **ref, find_item_error_report_type report_error, bool check_privileges, bool register_tree_change)
Item ** find_item_in_list (Item *find, List< Item > &items, uint *counter, find_item_error_report_type report_error, enum_resolution_type *resolution)
int setup_wild (THD *thd, TABLE_LIST *tables, List< Item > &fields, List< Item > *sum_func_list, uint wild_num)
bool setup_fields (THD *thd, Ref_ptr_array ref_pointer_array, List< Item > &fields, enum_mark_columns mark_used_columns, List< Item > *sum_func_list, bool allow_sum_func)
TABLE_LIST ** make_leaves_list (TABLE_LIST **list, TABLE_LIST *tables)
bool setup_tables (THD *thd, Name_resolution_context *context, List< TABLE_LIST > *from_clause, TABLE_LIST *tables, TABLE_LIST **leaves, bool select_insert)
bool setup_tables_and_check_access (THD *thd, Name_resolution_context *context, List< TABLE_LIST > *from_clause, TABLE_LIST *tables, TABLE_LIST **leaves, bool select_insert, ulong want_access_first, ulong want_access)
bool insert_fields (THD *thd, Name_resolution_context *context, const char *db_name, const char *table_name, List_iterator< Item > *it, bool any_privileges)
int setup_conds (THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, Item **conds)
bool fill_record (THD *thd, List< Item > &fields, List< Item > &values, bool ignore_errors, MY_BITMAP *bitmap)
bool fill_record_n_invoke_before_triggers (THD *thd, List< Item > &fields, List< Item > &values, bool ignore_errors, Table_triggers_list *triggers, enum trg_event_type event)
bool fill_record (THD *thd, Field **ptr, List< Item > &values, bool ignore_errors, MY_BITMAP *bitmap)
bool fill_record_n_invoke_before_triggers (THD *thd, Field **ptr, List< Item > &values, bool ignore_errors, Table_triggers_list *triggers, enum trg_event_type event)
my_bool mysql_rm_tmp_tables (void)
void tdc_flush_unused_tables ()
void tdc_remove_table (THD *thd, enum_tdc_remove_table_type remove_type, const char *db, const char *table_name, bool has_lock)
int setup_ftfuncs (SELECT_LEX *select_lex)
int init_ftfuncs (THD *thd, SELECT_LEX *select_lex, bool no_order)
bool is_equal (const LEX_STRING *a, const LEX_STRING *b)
bool open_system_tables_for_read (THD *thd, TABLE_LIST *table_list, Open_tables_backup *backup)
void close_system_tables (THD *thd, Open_tables_backup *backup)
void close_mysql_tables (THD *thd)
TABLEopen_system_table_for_update (THD *thd, TABLE_LIST *one_table)
TABLEopen_log_table (THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup)
void close_log_table (THD *thd, Open_tables_backup *backup)
virtual bool MDL_deadlock_handler::handle_condition (THD *thd, uint sql_errno, const char *sqlstate, Sql_condition::enum_warning_level level, const char *msg, Sql_condition **cond_hdl)
 Open_table_context::Open_table_context (THD *thd, uint flags)
bool Open_table_context::request_backoff_action (enum_open_table_action action_arg, TABLE_LIST *table)
bool Open_table_context::recover_from_failed_open ()
virtual bool DML_prelocking_strategy::handle_routine (THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking)
virtual bool DML_prelocking_strategy::handle_table (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
virtual bool DML_prelocking_strategy::handle_view (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
virtual bool Alter_table_prelocking_strategy::handle_routine (THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking)
virtual bool Alter_table_prelocking_strategy::handle_table (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
virtual bool Alter_table_prelocking_strategy::handle_view (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)

Variables

mysql_mutex_t LOCK_open
HASH table_def_cache
Fieldnot_found_field = (Field*) 0x1
Fieldview_ref_found = (Field*) 0x2
Item ** not_found_item = (Item**) 0x1

Function Documentation

bool check_if_table_exists ( THD *  thd,
TABLE_LIST table,
bool *  exists 
)

Check that table exists in table definition cache, on disk or in some storage engine.

Parameters:
thdThread context
tableTable list element
[out]existsOut parameter which is set to TRUE if table exists and to FALSE otherwise.
Note:
This function acquires LOCK_open internally.
If there is no .FRM file for the table but it exists in one of engines (e.g. it was created on another node of NDB cluster) this function will fetch and create proper .FRM file for it.
Return values:
TRUESome error occurred
FALSENo error. 'exists' out parameter set accordingly.
void close_all_tables_for_name ( THD *  thd,
TABLE_SHARE share,
bool  remove_from_locked_tables,
TABLE skip_table 
)

Close all open instances of the table but keep the MDL lock.

Works both under LOCK TABLES and in the normal mode. Removes all closed instances of the table from the table cache.

Parameters:
thdthread handle
[in]sharetable share, but is just a handy way to access the table cache key
[in]remove_from_locked_tablesTRUE if the table is being dropped or renamed. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list.
[in]skip_tableTABLE instance that should be kept open.
Precondition:
Must be called with an X MDL lock on the table.
bool close_cached_connection_tables ( THD *  thd,
LEX_STRING *  connection 
)

Close all tables which match specified connection string or if specified string is NULL, then any table with a connection string.

void close_log_table ( THD *  thd,
Open_tables_backup *  backup 
)

Close a log table. The last table opened by open_log_table() is closed, then the thread context is restored.

Parameters:
thdThe current thread
backup[in] the context to restore.
void close_mysql_tables ( THD *  thd)

A helper function to close a mysql.* table opened in an auxiliary THD during bootstrap or in the main connection, when we know that there are no locks held by the connection due to a preceding implicit commit.

This function assumes that there is no statement transaction started for the operation itself, since mysql.* tables are not transactional and when they are used the binlog is off (DDL binlogging is always statement-based.

We need this function since we'd like to not just close the system table, but also release the metadata lock on it.

Note, that in LOCK TABLES mode this function does not release the metadata lock. But in this mode the table can be opened only if it is locked explicitly with LOCK TABLES.

void close_tables_for_reopen ( THD *  thd,
TABLE_LIST **  tables,
const MDL_savepoint start_of_statement_svp 
)

Prepare statement for reopening of tables and recalculation of set of prelocked tables.

Parameters:
[in]thdThread context.
[in,out]tablesList of tables which we were trying to open and lock.
[in]start_of_statement_svpMDL savepoint which represents the set of metadata locks which the current transaction managed to acquire before execution of the current statement and to which we should revert before trying to reopen tables. NULL if no metadata locks were held and thus all metadata locks should be released.
void drop_open_table ( THD *  thd,
TABLE table,
const char *  db_name,
const char *  table_name 
)

Close a and drop a just created table in CREATE TABLE ... SELECT.

Parameters:
thdThread handle
tableTABLE object for the table to be dropped
db_nameName of database for this table
table_nameName of this table

This routine assumes that the table to be closed is open only by the calling thread, so we needn't wait until other threads close the table. It also assumes that the table is first in thd->open_ables and a data lock on it, if any, has been released. To sum up, it's tuned to work with CREATE TABLE ... SELECT and CREATE TABLE .. SELECT only. Note, that currently CREATE TABLE ... SELECT is not supported under LOCK TABLES. This function, still, can be called in prelocked mode, e.g. if we do CREATE TABLE .. SELECT f1();

int drop_temporary_table ( THD *  thd,
TABLE_LIST table_list,
bool *  is_trans 
)

Drop a temporary table.

Try to locate the table in the list of thd->temporary_tables. If the table is found:

  • if the table is being used by some outer statement, fail.
  • if the table is locked with LOCK TABLES or by prelocking, unlock it and remove it from the list of locked tables (THD::lock). Currently only transactional temporary tables are locked.
  • Close the temporary table, remove its .FRM
  • remove the table from the list of temporary tables

This function is used to drop user temporary tables, as well as internal tables created in CREATE TEMPORARY TABLE ... SELECT or ALTER TABLE. Even though part of the work done by this function is redundant when the table is internal, as long as we link both internal and user temporary tables into the same thd->temporary_tables list, it's impossible to tell here whether we're dealing with an internal or a user temporary table.

In is_trans out-parameter, we return the type of the table: either transactional (e.g. innodb) as TRUE or non-transactional (e.g. myisam) as FALSE.

This function assumes that table to be dropped was pre-opened using table list provided.

Return values:
0the table was found and dropped successfully.
1the table was not found in the list of temporary tables of this thread
-1the table is in use by a outer query
bool fill_record ( THD *  thd,
Field **  ptr,
List< Item > &  values,
bool  ignore_errors,
MY_BITMAP *  bitmap 
)

Fill field buffer with values from Field list.

Parameters:
thdthread handler
ptrpointer on pointer to record
valueslist of fields
ignore_errorsTrue if we should ignore errors
bitmapBitmap over fields to fill
Note:
fill_record() may set table->auto_increment_field_not_null and a caller should make sure that it is reset after their last call to this function.
Returns:
Operation status
Return values:
falseOK
trueError occured
TABLE* find_locked_table ( TABLE list,
const char *  db,
const char *  table_name 
)

Find table in the list of open tables.

Parameters:
listList of TABLE objects to be inspected.
dbDatabase name
table_nameTable name
Returns:
Pointer to the TABLE object found, 0 if no table found.
TABLE* find_table_for_mdl_upgrade ( THD *  thd,
const char *  db,
const char *  table_name,
bool  no_error 
)

Find instance of TABLE with upgradable or exclusive metadata lock from the list of open tables, emit error if no such table found.

Parameters:
thdThread context
dbDatabase name.
table_nameName of table.
no_errorDon't emit error if no suitable TABLE instance were found.
Note:
This function checks if the connection holds a global IX metadata lock. If no such lock is found, it is not safe to upgrade the lock and ER_TABLE_NOT_LOCKED_FOR_WRITE will be reported.
Returns:
Pointer to TABLE instance with MDL_SHARED_UPGRADABLE MDL_SHARED_NO_WRITE, MDL_SHARED_NO_READ_WRITE, or MDL_EXCLUSIVE metadata lock, NULL otherwise.
TABLE* find_temporary_table ( THD *  thd,
const char *  db,
const char *  table_name 
)

Find temporary table specified by database and table names in the THD::temporary_tables list.

Returns:
TABLE instance if a temporary table has been found; NULL otherwise.
TABLE* find_temporary_table ( THD *  thd,
const TABLE_LIST tl 
)

Find a temporary table specified by TABLE_LIST instance in the THD::temporary_tables list.

Returns:
TABLE instance if a temporary table has been found; NULL otherwise.
TABLE* find_temporary_table ( THD *  thd,
const char *  table_key,
uint  table_key_length 
)

Find a temporary table specified by a key in the THD::temporary_tables list.

Returns:
TABLE instance if a temporary table has been found; NULL otherwise.
uint get_table_def_key ( const TABLE_LIST table_list,
const char **  key 
)

Get table cache key for a table list element.

Parameters:
table_list[in]Table list element.
key[out]On return points to table cache key for the table.
Note:
Unlike create_table_def_key() call this function doesn't construct key in a buffer provider by caller. Instead it relies on the fact that table list element for which key is requested has properly initialized MDL_request object and the fact that table definition cache key is suffix of key used in MDL subsystem. So to get table definition key it simply needs to return pointer to appropriate part of MDL_key object nested in this table list element. Indeed, this means that lifetime of key produced by this call is limited by the lifetime of table list element which it got as parameter.
Returns:
Length of key.
bool DML_prelocking_strategy::handle_routine ( THD *  thd,
Query_tables_list *  prelocking_ctx,
Sroutine_hash_entry rt,
sp_head sp,
bool *  need_prelocking 
) [virtual]

Defines how prelocking algorithm for DML statements should handle routines:

  • For CALL statements we do unrolling (i.e. open and lock tables for each sub-statement individually). So for such statements prelocking is enabled only if stored functions are used in parameter list and only for period during which we calculate values of parameters. Thus in this strategy we ignore procedure which is directly called by such statement and extend the prelocking set only with tables/functions used by SF called from the parameter list.
  • For any other statement any routine which is directly or indirectly called by statement is going to be executed in prelocked mode. So in this case we simply add all tables and routines used by it to the prelocking set.
Parameters:
[in]thdThread context.
[in]prelocking_ctxPrelocking context of the statement.
[in]rtPrelocking set element describing routine.
[in]spRoutine body.
[out]need_prelockingSet to TRUE if method detects that prelocking required, not changed otherwise.
Return values:
FALSESuccess.
TRUEFailure (OOM).

Implements Prelocking_strategy.

bool Alter_table_prelocking_strategy::handle_routine ( THD *  thd,
Query_tables_list *  prelocking_ctx,
Sroutine_hash_entry rt,
sp_head sp,
bool *  need_prelocking 
) [virtual]

Defines how prelocking algorithm for ALTER TABLE statement should handle routines - do nothing as this statement is not supposed to call routines.

We still can end up in this method when someone tries to define a foreign key referencing a view, and not just a simple view, but one that uses stored routines.

Implements Prelocking_strategy.

bool DML_prelocking_strategy::handle_table ( THD *  thd,
Query_tables_list *  prelocking_ctx,
TABLE_LIST table_list,
bool *  need_prelocking 
) [virtual]

Defines how prelocking algorithm for DML statements should handle table list elements:

  • If table has triggers we should add all tables and routines used by them to the prelocking set.

We do not need to acquire metadata locks on trigger names in DML statements, since all DDL statements that change trigger metadata always lock their subject tables.

Parameters:
[in]thdThread context.
[in]prelocking_ctxPrelocking context of the statement.
[in]table_listTable list element for table.
[in]spRoutine body.
[out]need_prelockingSet to TRUE if method detects that prelocking required, not changed otherwise.
Return values:
FALSESuccess.
TRUEFailure (OOM).

Implements Prelocking_strategy.

bool Alter_table_prelocking_strategy::handle_table ( THD *  thd,
Query_tables_list *  prelocking_ctx,
TABLE_LIST table_list,
bool *  need_prelocking 
) [virtual]

Defines how prelocking algorithm for ALTER TABLE statement should handle table list elements.

Unlike in DML, we do not process triggers here.

Parameters:
[in]thdThread context.
[in]prelocking_ctxPrelocking context of the statement.
[in]table_listTable list element for table.
[in]spRoutine body.
[out]need_prelockingSet to TRUE if method detects that prelocking required, not changed otherwise.
Return values:
FALSESuccess.
TRUEFailure (OOM).

Implements Prelocking_strategy.

bool DML_prelocking_strategy::handle_view ( THD *  thd,
Query_tables_list *  prelocking_ctx,
TABLE_LIST table_list,
bool *  need_prelocking 
) [virtual]

Defines how prelocking algorithm for DML statements should handle view - all view routines should be added to the prelocking set.

Parameters:
[in]thdThread context.
[in]prelocking_ctxPrelocking context of the statement.
[in]table_listTable list element for view.
[in]spRoutine body.
[out]need_prelockingSet to TRUE if method detects that prelocking required, not changed otherwise.
Return values:
FALSESuccess.
TRUEFailure (OOM).

Implements Prelocking_strategy.

bool Alter_table_prelocking_strategy::handle_view ( THD *  thd,
Query_tables_list *  prelocking_ctx,
TABLE_LIST table_list,
bool *  need_prelocking 
) [virtual]

Defines how prelocking algorithm for ALTER TABLE statement should handle view - do nothing. We don't need to add view routines to the prelocking set in this case as view is not going to be materialized.

Implements Prelocking_strategy.

bool lock_table_names ( THD *  thd,
TABLE_LIST tables_start,
TABLE_LIST tables_end,
ulong  lock_wait_timeout,
uint  flags 
)

Acquire upgradable (SNW, SNRW) metadata locks on tables used by LOCK TABLES or by a DDL statement. Acquire lock "S" on table being created in CREATE TABLE statement.

Note:
Under LOCK TABLES, we can't take new locks, so use open_tables_check_upgradable_mdl() instead.
Parameters:
thdThread context.
tables_startStart of list of tables on which upgradable locks should be acquired.
tables_endEnd of list of tables.
lock_wait_timeoutSeconds to wait before timeout.
flagsBitmap of flags to modify how the tables will be open, see open_table() description for details.
Return values:
FALSESuccess.
TRUEFailure (e.g. connection was killed)
bool lock_tables ( THD *  thd,
TABLE_LIST tables,
uint  count,
uint  flags 
)

Lock all tables in a list.

Parameters:
thdThread handler
tablesTables to lock
countNumber of opened tables
flagsOptions (see mysql_lock_tables() for details)

You can't call lock_tables() while holding thr_lock locks, as this would break the dead-lock-free handling thr_lock gives us. You must always get all needed locks at once.

If the query for which we are calling this function is marked as requiring prelocking, this function will change locked_tables_mode to LTM_PRELOCKED.

Return values:
FALSESuccess.
TRUEA lock wait timeout, deadlock or out of memory.
void mark_tmp_table_for_reuse ( TABLE table)

Reset a single temporary table. Effectively this "closes" one temporary table, in a session.

Parameters:
tableTemporary table.
bool open_and_lock_tables ( THD *  thd,
TABLE_LIST tables,
bool  derived,
uint  flags,
Prelocking_strategy prelocking_strategy 
)

Open all tables in list, locks them and optionally process derived tables.

Parameters:
thdThread context.
tablesList of tables for open and locking.
derivedIf to handle derived tables.
flagsBitmap of options to be used to open and lock tables (see open_tables() and mysql_lock_tables() for details).
prelocking_strategyStrategy which specifies how prelocking algorithm should work for this statement.
Note:
The thr_lock locks will automatically be freed by close_thread_tables().
Return values:
FALSEOK.
TRUEError
TABLE* open_log_table ( THD *  thd,
TABLE_LIST one_table,
Open_tables_backup *  backup 
)

Open a log table. Opening such tables is performed internally in the server implementation, and is a 'nested' open, since some tables might be already opened by the current thread. The thread context before this call is saved, and is restored when calling close_log_table().

Parameters:
thdThe current thread
one_tableLog table to open
backup[out] Temporary storage used to save the thread context
TABLE* open_n_lock_single_table ( THD *  thd,
TABLE_LIST table_l,
thr_lock_type  lock_type,
uint  flags,
Prelocking_strategy prelocking_strategy 
)

Open and lock one table.

Parameters:
[in]thdthread handle
[in]table_ltable to open is first table in this list
[in]lock_typelock to use for table
[in]flagsoptions to be used while opening and locking table (see open_table(), mysql_lock_tables())
[in]prelocking_strategyStrategy which specifies how prelocking algorithm should work for this statement.
Returns:
table
Return values:
!=NULL OK, opened table returned
NULLError
Note:
If ok, the following are also set: table_list->lock_type lock_type table_list->table table
If table_l is a list, not a single table, the list is temporarily broken.

This function is meant as a replacement for open_ltable() when MERGE tables can be opened. open_ltable() cannot open MERGE tables.

There may be more differences between open_n_lock_single_table() and open_ltable(). One known difference is that open_ltable() does neither call thd->decide_logging_format() nor handle some other logging and locking issues because it does not call lock_tables().

bool open_normal_and_derived_tables ( THD *  thd,
TABLE_LIST tables,
uint  flags 
)

Open all tables in list and process derived tables

Parameters:
thdthread handler
tableslist of tables for open
flagsbitmap of flags to modify how the tables will be open: MYSQL_LOCK_IGNORE_FLUSH - open table even if someone has done a flush on it.
Return values:
false- ok
true- error
Note:
This is to be used on prepare stage when you don't read any data from the tables.
Updates Query_tables_list::table_count as side-effect.
bool open_table ( THD *  thd,
TABLE_LIST table_list,
Open_table_context ot_ctx 
)

Open a base table.

Parameters:
thdThread context.
table_listOpen first table in list.
ot_ctxContext with flags which modify how open works and which is used to recover from a failed open_table() attempt. Some examples of flags: MYSQL_OPEN_IGNORE_FLUSH - Open table even if someone has done a flush. No version number checking is done. MYSQL_OPEN_HAS_MDL_LOCK - instead of acquiring metadata locks rely on that caller already has appropriate ones.

Uses a cache of open tables to find a TABLE instance not in use.

If TABLE_LIST::open_strategy is set to OPEN_IF_EXISTS, the table is opened only if it exists. If the open strategy is OPEN_STUB, the underlying table is never opened. In both cases, metadata locks are always taken according to the lock strategy.

The function used to open temporary tables, but now it opens base tables only.

Return values:
TRUEOpen failed. "action" parameter may contain type of action needed to remedy problem before retrying again.
FALSESuccess. Members of TABLE_LIST structure are filled properly (e.g. TABLE_LIST::table is set for real tables and TABLE_LIST::view is set for views).
Open_table_context::Open_table_context ( THD *  thd,
uint  flags 
)
TABLE* open_table_uncached ( THD *  thd,
const char *  path,
const char *  db,
const char *  table_name,
bool  add_to_temporary_tables_list,
bool  open_in_engine 
)

Open a single table without table caching and don't add it to THD::open_tables. Depending on the 'add_to_temporary_tables_list' value, the opened TABLE instance will be addded to THD::temporary_tables list.

Parameters:
thdThread context.
pathPath (without .frm)
dbDatabase name.
table_nameTable name.
add_to_temporary_tables_listSpecifies if the opened TABLE instance should be linked into THD::temporary_tables list.
open_in_engineIndicates that we need to open table in storage engine in addition to constructing TABLE object for it.
Note:
This function is used:
  • by alter_table() to open a temporary table;
  • when creating a temporary table with CREATE TEMPORARY TABLE.
Returns:
TABLE instance for opened table.
Return values:
NULLon error.
bool open_tables ( THD *  thd,
TABLE_LIST **  start,
uint *  counter,
uint  flags,
Prelocking_strategy prelocking_strategy 
)

Open all tables in list

Parameters:
[in]thdThread context.
[in,out]startList of tables to be open (it can be adjusted for statement that uses tables only implicitly, e.g. for "SELECT f1()").
[out]counterNumber of tables which were open.
[in]flagsBitmap of flags to modify how the tables will be open, see open_table() description for details.
[in]prelocking_strategyStrategy which specifies how prelocking algorithm should work for this statement.
Note:
Unless we are already in prelocked mode and prelocking strategy prescribes so this function will also precache all SP/SFs explicitly or implicitly (via views and triggers) used by the query and add tables needed for their execution to table list. Statement that uses SFs, invokes triggers or requires foreign key checks will be marked as requiring prelocking. Prelocked mode will be enabled for such query during lock_tables() call.

If query for which we are opening tables is already marked as requiring prelocking it won't do such precaching and will simply reuse table list which is already built.

Return values:
FALSESuccess.
TRUEError, reported.
bool open_temporary_table ( THD *  thd,
TABLE_LIST tl 
)

Find a temporary table specified by TABLE_LIST instance in the cache and prepare its TABLE instance for use.

This function tries to resolve this table in the list of temporary tables of this thread. Temporary tables are thread-local and "shadow" base tables with the same name.

Note:
In most cases one should use open_temporary_tables() instead of this call.
One should finalize process of opening temporary table for table list element by calling open_and_process_table(). This function is responsible for table version checking and handling of merge tables.
We used to check global_read_lock before opening temporary tables. However, that limitation was artificial and is removed now.
Returns:
Error status.
Return values:
FALSEOn success. If a temporary table exists for the given key, tl->table is set.
TRUEOn error. my_error() has been called.
bool open_temporary_tables ( THD *  thd,
TABLE_LIST tl_list 
)

Pre-open temporary tables corresponding to table list elements.

Note:
One should finalize process of opening temporary tables by calling open_tables(). This function is responsible for table version checking and handling of merge tables.
Returns:
Error status.
Return values:
FALSEOn success. If a temporary tables exists for the given element, tl->table is set.
TRUEOn error. my_error() has been called.

Recover from failed attempt of open table by performing requested action.

Precondition:
This function should be called only with "action" != OT_NO_ACTION and after having called
See also:
close_tables_for_reopen().
Return values:
FALSE- Success. One should try to open tables once again.
TRUE- Error
void release_table_share ( TABLE_SHARE share)

Mark that we are not using table share anymore.

Parameters:
shareTable share

If the share has no open tables and (we have done a refresh or if we have already too many open table shares) then delete the definition.

bool Open_table_context::request_backoff_action ( enum_open_table_action  action_arg,
TABLE_LIST table 
)

Check if we can back-off and set back off action if we can. Otherwise report and return error.

Return values:
TRUEif back-off is impossible.
FALSEif we can back off. Back off action has been set.
bool rm_temporary_table ( handlerton base,
const char *  path 
)

Delete a temporary table.

Parameters:
baseHandlerton for table to be deleted.
pathPath to the table to be deleted (i.e. path to its .frm without an extension).
Return values:
false- success.
true- failure.
bool setup_tables_and_check_access ( THD *  thd,
Name_resolution_context context,
List< TABLE_LIST > *  from_clause,
TABLE_LIST tables,
TABLE_LIST **  leaves,
bool  select_insert,
ulong  want_access_first,
ulong  want_access 
)

Prepare tables and check access for the view tables.

Parameters:
thdThread context.
contextName resolution contest to setup table list there.
from_clauseTop-level list of table references in the FROM clause.
tablesTable list (select_lex->table_list).
leaves[in/out]List of join table leaves list (select_lex->leaf_tables).
select_insertIt is SELECT ... INSERT command/
want_access_firstWhat access is requested of the first leaf.
want_accessWhat access is requested on the rest of leaves.
Note:
A wrapper for check_tables that will also check the resulting table leaves list for access to all the tables that belong to a view.
Beware that it can't properly check privileges in cases when table being changed is not the first table in the list of leaf tables (for example, for multi-UPDATE).
Return values:
FALSE- Success.
TRUE- Error.
void table_def_start_shutdown ( void  )

Notify table definition cache that process of shutting down server has started so it has to keep number of TABLE and TABLE_SHARE objects minimal in order to reduce number of references to pluggable engines.

bool tdc_open_view ( THD *  thd,
TABLE_LIST table_list,
const char *  alias,
const char *  cache_key,
uint  cache_key_length,
uint  flags 
)

Open view by getting its definition from disk (and table cache in future).

Parameters:
thdThread handle
table_listTABLE_LIST with db, table_name & belong_to_view
aliasAlias name
cache_keyKey for table definition cache
cache_key_lengthLength of cache_key
flagsFlags which modify how we open the view
Todo:
This function is needed for special handling of views under LOCK TABLES. We probably should get rid of it in long term.
Returns:
FALSE if success, TRUE - otherwise.
void tdc_remove_table ( THD *  thd,
enum_tdc_remove_table_type  remove_type,
const char *  db,
const char *  table_name,
bool  has_lock 
)

Remove all or some (depending on parameter) instances of TABLE and TABLE_SHARE from the table definition cache.

Parameters:
thdThread context
remove_typeType of removal: TDC_RT_REMOVE_ALL - remove all TABLE instances and TABLE_SHARE instance. There should be no used TABLE objects and caller should have exclusive metadata lock on the table. TDC_RT_REMOVE_NOT_OWN - remove all TABLE instances except those that belong to this thread. There should be no TABLE objects used by other threads and caller should have exclusive metadata lock on the table. TDC_RT_REMOVE_UNUSED - remove all unused TABLE instances (if there are no used instances will also remove TABLE_SHARE). TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE - remove all TABLE instances except those that belong to this thread, but don't mark TABLE_SHARE as old. There should be no TABLE objects used by other threads and caller should have exclusive metadata lock on the table.
dbName of database
table_nameName of table
has_lockIf TRUE, LOCK_open is already acquired
Note:
It assumes that table instances are already not used by any (other) thread (this should be achieved by using meta-data locks).
TABLE_LIST* unique_table ( THD *  thd,
TABLE_LIST table,
TABLE_LIST table_list,
bool  check_alias 
)

Test that the subject table of INSERT/UPDATE/DELETE/CREATE or (in case of MyISAMMRG) one of its children are not used later in the query.

For MyISAMMRG tables, it is assumed that all the underlying tables of table (if any) are listed right after it and that their parent_l field points at the main table.

Return values:
non-NULLThe table list element for the table that represents the duplicate.
NULLNo duplicates found.
bool wait_while_table_is_used ( THD *  thd,
TABLE table,
enum ha_extra_function  function 
)

Force all other threads to stop using the table by upgrading metadata lock on it and remove unused TABLE instances from cache.

Parameters:
thdThread handler
tableTable to remove from cache
functionHA_EXTRA_PREPARE_FOR_DROP if table is to be deleted HA_EXTRA_FORCE_REOPEN if table is not be used HA_EXTRA_PREPARE_FOR_RENAME if table is to be renamed
Note:
When returning, the table will be unusable for other threads until metadata lock is downgraded.
Return values:
FALSESuccess.
TRUEFailure (e.g. because thread was killed).

Variable Documentation

mysql_mutex_t LOCK_open

LOCK_open protects the following variables/objects:

1) The table_def_cache This is the hash table mapping table name to a table share object. The hash table can only be manipulated while holding LOCK_open. 2) last_table_id Generation of a new unique table_map_id for a table share is done through incrementing last_table_id, a global variable used for this purpose. 3) LOCK_open protects the initialisation of the table share object and all its members and also protects reading the .frm file from where the table share is initialised. 4) In particular the share->ref_count is updated each time a new table object is created that refers to a table share. This update is protected by LOCK_open. 5) oldest_unused_share, end_of_unused_share and share->next and share->prev are variables to handle the lists of table share objects, these can only be read and manipulated while holding the LOCK_open mutex. 6) table_def_shutdown_in_progress can be updated only while holding LOCK_open and ALL table cache mutexes. 7) refresh_version This variable can only be updated while holding LOCK_open AND all table cache mutexes. 8) share->version This variable is initialised while holding LOCK_open. It can only be updated while holding LOCK_open AND all table cache mutexes. So if a table share is found through a reference its version won't change if any of those mutexes are held. 9) share->m_flush_tickets

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines