MySQL 8.0.40
Source Code Documentation
Data Dictionary

Namespaces

namespace  anonymous_namespace{sql_base.cc}
 

Classes

class  MDL_deadlock_handler
 An error handler which converts, if possible, ER_LOCK_DEADLOCK error that can occur when we are trying to acquire a metadata lock to a request for back-off and re-start of open_tables() process. More...
 
class  Fix_row_type_error_handler
 Error handler class for suppressing HA_ERR_ROW_FORMAT_CHANGED errors from SE. More...
 
class  MDL_deadlock_discovery_repair_handler
 An error handler to mark transaction to rollback on DEADLOCK error during DISCOVER / REPAIR. More...
 
class  Tables_in_user_order_iterator
 This is an iterator which emits leaf Table_ref nodes in an order suitable for expansion of 'table_name. More...
 

Macros

#define WRONG_GRANT   (Field *)-1
 

Typedefs

using Table_definition_cache = malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > >
 

Functions

static void init_tdc_psi_keys (void)
 Initialize performance schema instrumentation points used by the table cache. More...
 
static bool check_and_update_table_version (THD *thd, Table_ref *tables, TABLE_SHARE *table_share)
 Compare metadata versions of an element obtained from the table definition cache and its corresponding node in the parse tree. More...
 
static bool open_table_entry_fini (THD *thd, TABLE_SHARE *share, const dd::Table *table, TABLE *entry)
 Finalize the process of TABLE creation by loading table triggers and taking action if a HEAP table content was emptied implicitly. More...
 
static bool auto_repair_table (THD *thd, Table_ref *table_list)
 Auxiliary routine which is used for performing automatic table repair. More...
 
static TABLEfind_temporary_table (THD *thd, const char *table_key, size_t table_key_length)
 Find a temporary table specified by a key in the THD::temporary_tables list. More...
 
static bool tdc_open_view (THD *thd, Table_ref *table_list, const char *cache_key, size_t cache_key_length)
 Open view by getting its definition from disk (and table cache in future). More...
 
static bool add_view_place_holder (THD *thd, Table_ref *table_list)
 Add a dummy LEX object for a view. More...
 
static size_t create_table_def_key (const char *db_name, const char *table_name, char *key)
 Create a table cache/table definition cache key for a table. More...
 
static size_t create_table_def_key_tmp (const THD *thd, const char *db_name, const char *table_name, char *key)
 Create a table cache/table definition cache key for a temporary table. More...
 
static std::string create_table_def_key_secondary (const char *db_name, const char *table_name)
 Create a table cache/table definition cache key for a table in a secondary storage engine. More...
 
size_t get_table_def_key (const Table_ref *table_list, const char **key)
 Get table cache key for a table list element. More...
 
bool table_def_init (void)
 
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. More...
 
void table_def_free (void)
 
uint cached_table_definitions (void)
 
static TABLE_SHAREprocess_found_table_share (THD *thd, TABLE_SHARE *share, bool open_view)
 
static bool read_histograms (THD *thd, TABLE_SHARE *share, const dd::Schema *schema, const dd::Abstract_table *table_def)
 Read any existing histogram statistics from the data dictionary and store a copy of them in the TABLE_SHARE. More...
 
static void update_schema_options (const dd::Schema *sch_obj, TABLE_SHARE *share)
 Update TABLE_SHARE with options from dd::Schema object. More...
 
TABLE_SHAREget_table_share (THD *thd, const char *db, const char *table_name, const char *key, size_t key_length, bool open_view, bool open_secondary)
 Get the TABLE_SHARE for a table. More...
 
static TABLE_SHAREget_table_share_with_discover (THD *thd, Table_ref *table_list, const char *key, size_t key_length, bool open_secondary, int *error)
 Get a table share. More...
 
void release_table_share (TABLE_SHARE *share)
 Mark that we are not using table share anymore. More...
 
TABLE_SHAREget_cached_table_share (const char *db, const char *table_name)
 Get an existing table definition from the table definition cache. More...
 
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_ref *tables, bool wait_for_refresh, ulong timeout)
 
static void mark_temp_tables_as_free_for_reuse (THD *thd)
 Mark all temporary tables which were used by the current statement or substatement as free for reuse, but only if the query_id can be cleared. More...
 
void mark_tmp_table_for_reuse (TABLE *table)
 Reset a single temporary table. More...
 
static void mark_used_tables_as_free_for_reuse (THD *thd, TABLE *table)
 
static void close_open_tables (THD *thd)
 Auxiliary function to close all tables in the open_tables list. More...
 
static void close_all_tables_for_name (THD *thd, const char *key, size_t key_length, const char *db, const char *table_name, bool remove_from_locked_tables, TABLE *skip_table)
 Close all open instances of the table but keep the MDL lock. More...
 
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. More...
 
void close_all_tables_for_name (THD *thd, const char *db, const char *table_name, bool remove_from_locked_tables)
 Close all open instances of the table but keep the MDL lock. More...
 
static bool in_LTM (THD *thd)
 
static bool belongs_to_dd_table (const Table_ref *tl)
 Check if the given Table_ref belongs to a DD table. More...
 
void close_thread_tables (THD *thd)
 Close all tables used by the current substatement, or all tables used by this thread if we are on the outer-most level. More...
 
static void release_or_close_table (THD *thd, TABLE *table)
 Helper function which returns TABLE to Table Cache or closes if table is marked as needing re-open. More...
 
void close_thread_table (THD *thd, TABLE **table_ptr)
 
static uint tmpkeyval (TABLE *table)
 
bool close_temporary_tables (THD *thd)
 
Table_reffind_table_in_global_list (Table_ref *table, const char *db_name, const char *table_name)
 Find table in global list. More...
 
static Table_reffind_dup_table (const Table_ref *table, Table_ref *table_list, bool check_alias)
 Test that table is unique (It's only exists once in the table list) More...
 
Table_refunique_table (const Table_ref *table, Table_ref *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. More...
 
void update_non_unique_table_error (Table_ref *update, const char *operation, Table_ref *duplicate)
 Issue correct error message in case we found 2 duplicate tables which prevent some update operation. More...
 
TABLEfind_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. More...
 
TABLEfind_temporary_table (THD *thd, const Table_ref *tl)
 Find a temporary table specified by Table_ref instance in the THD::temporary_tables list. More...
 
void drop_temporary_table (THD *thd, Table_ref *table_list)
 Drop a temporary table. More...
 
void close_temporary_table (THD *thd, TABLE *table, bool free_share, bool delete_table)
 
void close_temporary (THD *thd, 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)
 Force all other threads to stop using the table by upgrading metadata lock on it and remove unused TABLE instances from cache. More...
 
static bool check_if_table_exists (THD *thd, Table_ref *table, bool *exists)
 Check that table exists in data-dictionary or in some storage engine. More...
 
static bool open_table_get_mdl_lock (THD *thd, Open_table_context *ot_ctx, Table_ref *table_list, uint flags, MDL_ticket **mdl_ticket)
 Try to acquire an MDL lock for a table being opened. More...
 
static bool tdc_wait_for_old_version (THD *thd, const char *db, const char *table_name, ulong wait_timeout, uint deadlock_weight)
 Check if table's share is being removed from the table definition cache and, if yes, wait until the flush is complete. More...
 
bool open_table (THD *thd, Table_ref *table_list, Open_table_context *ot_ctx)
 Open a base table. More...
 
TABLEfind_locked_table (TABLE *list, const char *db, const char *table_name)
 Find table in the list of open tables. More...
 
TABLEfind_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. More...
 
void assign_new_table_id (TABLE_SHARE *share)
 
static bool check_and_update_routine_version (THD *thd, Sroutine_hash_entry *rt, sp_head *sp)
 Compares versions of a stored routine obtained from the sp cache and the version used at prepare. More...
 
static bool fix_row_type (THD *thd, Table_ref *table_list)
 Auxiliary routine for automatically updating row format for the table. More...
 
thr_lock_type read_lock_type_for_table (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool routine_modifies_data)
 
static void process_table_fks (THD *thd, Query_tables_list *prelocking_ctx, TABLE_SHARE *share, bool is_insert, bool is_update, bool is_delete, Table_ref *belong_to_view, bool *need_prelocking)
 Process table's foreign keys (if any) by prelocking algorithm. More...
 
static bool open_and_process_routine (THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, Prelocking_strategy *prelocking_strategy, bool has_prelocking_list, Open_table_context *ot_ctx, bool *need_prelocking, bool *routine_modifies_data)
 Handle element of prelocking set other than table. More...
 
static bool open_and_process_table (THD *thd, LEX *lex, Table_ref *const tables, uint *counter, Prelocking_strategy *prelocking_strategy, bool has_prelocking_list, Open_table_context *ot_ctx)
 Handle table list element by obtaining metadata lock, opening table or view and, if prelocking strategy prescribes so, extending the prelocking set with tables and routines used by it. More...
 
int run_before_dml_hook (THD *thd)
 Run the server hook called "before_dml". More...
 
static bool is_temporary_table_being_opened (const Table_ref *table)
 Check whether a table being opened is a temporary table. More...
 
bool get_and_lock_tablespace_names (THD *thd, Table_ref *tables_start, Table_ref *tables_end, ulong lock_wait_timeout, uint flags)
 Acquire IX metadata locks on tablespace names used by LOCK TABLES or by a DDL statement. More...
 
bool lock_table_names (THD *thd, Table_ref *tables_start, Table_ref *tables_end, ulong lock_wait_timeout, uint flags, Prealloced_array< MDL_request *, 1 > *schema_reqs)
 Acquire "strong" (SRO, SNW, SNRW) metadata locks on tables used by LOCK TABLES or by a DDL statement. More...
 
static bool open_tables_check_upgradable_mdl (THD *thd, Table_ref *tables_start, Table_ref *tables_end)
 Check for upgradable (SNW, SNRW) metadata locks on tables to be opened for a DDL statement. More...
 
static bool acquire_backup_lock_in_lock_tables_mode (THD *thd, Table_ref *tables_start, Table_ref *tables_end)
 Iterate along a list of tables and acquire BACKUP LOCK in shared mode in case a strong MDL request (DDL/LOCK TABLES-type) was specified for a table. More...
 
static bool set_non_locking_read_for_IS_view (THD *thd, Table_ref *tl)
 Check if this is a DD table used under a I_S view then request InnoDB to do non-locking reads on the table. More...
 
bool is_acl_table_in_non_LTM (const Table_ref *tl, enum enum_locked_tables_mode ltm)
 Check if given Table_ref is a acl table and is being read and not in LOCK TABLE mode. More...
 
static bool set_non_locking_read_for_ACL_table (THD *thd, Table_ref *tl, const bool &issue_warning)
 Check if this is a ACL table is requested for read and then request InnoDB to do non-locking reads on the table. More...
 
bool open_tables (THD *thd, Table_ref **start, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
 Open all tables in list. More...
 
static bool check_lock_and_start_stmt (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list)
 Check that lock is ok for tables; Call start stmt if ok. More...
 
TABLEopen_n_lock_single_table (THD *thd, Table_ref *table_l, thr_lock_type lock_type, uint flags, Prelocking_strategy *prelocking_strategy)
 Open and lock one table. More...
 
TABLEopen_ltable (THD *thd, Table_ref *table_list, thr_lock_type lock_type, uint lock_flags)
 
bool open_and_lock_tables (THD *thd, Table_ref *tables, uint flags, Prelocking_strategy *prelocking_strategy)
 Open all tables in list, locks them and optionally process derived tables. More...
 
static bool open_secondary_engine_tables (THD *thd, uint flags)
 Check if a secondary engine can be used to execute the current statement, and if so, replace the opened tables with their secondary counterparts. More...
 
bool open_tables_for_query (THD *thd, Table_ref *tables, uint flags)
 Open all tables for a query or statement, in list started by "tables". More...
 
static void mark_real_tables_as_free_for_reuse (Table_ref *table_list)
 
bool lock_tables (THD *thd, Table_ref *tables, uint count, uint flags)
 Lock all tables in a list. More...
 
bool lock_dictionary_tables (THD *thd, Table_ref *tables, uint count, uint flags)
 Simplified version of lock_tables() call to be used for locking data-dictionary tables when reading or storing data-dictionary objects. More...
 
void close_tables_for_reopen (THD *thd, Table_ref **tables, const MDL_savepoint &start_of_statement_svp)
 Prepare statement for reopening of tables and recalculation of set of prelocked tables. More...
 
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, const dd::Table &table_def)
 Open a single table without table caching and don't add it to THD::open_tables. More...
 
bool rm_temporary_table (THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
 Delete a temporary table. More...
 
bool open_temporary_table (THD *thd, Table_ref *tl)
 Find a temporary table specified by Table_ref instance in the cache and prepare its TABLE instance for use. More...
 
bool open_temporary_tables (THD *thd, Table_ref *tl_list)
 Pre-open temporary tables corresponding to table list elements. More...
 
static Fieldfind_field_in_view (THD *thd, Table_ref *table_list, const char *name, Item **ref, bool register_tree_change)
 
static Fieldfind_field_in_natural_join (THD *thd, Table_ref *table_ref, const char *name, Item **ref, bool register_tree_change, Table_ref **actual_table)
 Find field by name in a NATURAL/USING join table reference. More...
 
Fieldfind_field_in_table (TABLE *table, const char *name, bool allow_rowid, uint *field_index_ptr)
 Find field by name in a base table. More...
 
Fieldfind_field_in_table_ref (THD *thd, Table_ref *table_list, const char *name, size_t length, const char *item_name, const char *db_name, const char *table_name, Item **ref, Access_bitmask want_privilege, bool allow_rowid, uint *field_index_ptr, bool register_tree_change, Table_ref **actual_table)
 Find field in a table reference. More...
 
Fieldfind_field_in_table_sef (TABLE *table, const char *name)
 
Fieldfind_field_in_tables (THD *thd, Item_ident *item, Table_ref *first_table, Table_ref *last_table, Item **ref, find_item_error_report_type report_error, Access_bitmask want_privilege, bool register_tree_change)
 
bool find_item_in_list (THD *thd, Item *find, mem_root_deque< Item * > *items, Item ***found, uint *counter, enum_resolution_type *resolution)
 Find Item in list of items (find_field_in_tables analog) More...
 
static bool test_if_string_in_list (const char *find, List< String > *str_list)
 
static bool set_new_item_local_context (THD *thd, Item_ident *item, Table_ref *table_ref)
 
static bool mark_common_columns (THD *thd, Table_ref *table_ref_1, Table_ref *table_ref_2, List< String > *using_fields, uint *found_using_fields)
 
static bool store_natural_using_join_columns (THD *thd, Table_ref *natural_using_join, Table_ref *table_ref_1, Table_ref *table_ref_2, List< String > *using_fields, uint found_using_fields)
 
static bool store_top_level_join_columns (THD *thd, Table_ref *table_ref, Table_ref *left_neighbor, Table_ref *right_neighbor)
 
bool setup_natural_join_row_types (THD *thd, mem_root_deque< Table_ref * > *from_clause, Name_resolution_context *context)
 
bool resolve_var_assignments (THD *thd, LEX *lex)
 Resolve variable assignments from LEX object. More...
 
bool setup_fields (THD *thd, Access_bitmask want_privilege, bool allow_sum_func, bool split_sum_funcs, bool column_update, const mem_root_deque< Item * > *typed_items, mem_root_deque< Item * > *fields, Ref_item_array ref_item_array)
 Resolve a list of expressions and setup appropriate data. More...
 
bool insert_fields (THD *thd, Query_block *query_block, const char *db_name, const char *table_name, mem_root_deque< Item * > *fields, mem_root_deque< Item * >::iterator *it, bool any_privileges)
 
bool fill_record (THD *thd, TABLE *table, const mem_root_deque< Item * > &fields, const mem_root_deque< Item * > &values, MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap, bool raise_autoinc_has_expl_non_null_val)
 Fill fields with given items. More...
 
static bool check_record (THD *thd, const mem_root_deque< Item * > &fields)
 Check the NOT NULL constraint on all the fields of the current record. More...
 
bool check_record (THD *thd, Field **ptr)
 Check the NOT NULL constraint on all the fields of the current record. More...
 
static bool check_inserting_record (THD *thd, Field **ptr)
 Check the NOT NULL constraint on all the fields explicitly set in INSERT INTO statement or implicitly set in BEFORE trigger. More...
 
bool invoke_table_check_constraints (THD *thd, const TABLE *table)
 Invoke check constraints defined on the table. More...
 
static bool command_can_invoke_insert_triggers (enum enum_trigger_event_type event, enum_sql_command sql_command)
 Check if SQL-statement is INSERT/INSERT SELECT/REPLACE/REPLACE SELECT and trigger event is ON INSERT. More...
 
bool call_before_insert_triggers (THD *thd, TABLE *table, enum enum_trigger_event_type event, MY_BITMAP *insert_into_fields_bitmap)
 Execute BEFORE INSERT trigger. More...
 
bool fill_record_n_invoke_before_triggers (THD *thd, COPY_INFO *optype_info, const mem_root_deque< Item * > &fields, const mem_root_deque< Item * > &values, TABLE *table, enum enum_trigger_event_type event, int num_fields, bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed)
 Fill fields in list with values from the list of items and invoke before triggers. More...
 
bool fill_record (THD *thd, TABLE *table, Field **ptr, const mem_root_deque< Item * > &values, MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap, bool raise_autoinc_has_expl_non_null_val)
 Fill field buffer with values from Field list. More...
 
bool fill_record_n_invoke_before_triggers (THD *thd, Field **ptr, const mem_root_deque< Item * > &values, TABLE *table, enum enum_trigger_event_type event, int num_fields)
 Fill fields in array with values from the list of items and invoke before triggers. More...
 
bool mysql_rm_tmp_tables (void)
 Drop all temporary tables which have been left from previous server run. More...
 
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)
 Remove all or some (depending on parameter) instances of TABLE and TABLE_SHARE from the table definition cache. More...
 
int setup_ftfuncs (const THD *thd, Query_block *query_block)
 
bool init_ftfuncs (THD *thd, Query_block *query_block)
 
bool open_trans_system_tables_for_read (THD *thd, Table_ref *table_list)
 Open and lock transactional system tables for read. More...
 
void close_trans_system_tables (THD *thd)
 Close transactional system tables, opened with open_trans_system_tables_for_read(). More...
 
void close_mysql_tables (THD *thd)
 A helper function to close a mysql. More...
 
TABLEopen_log_table (THD *thd, Table_ref *one_table, Open_tables_backup *backup)
 Open a log table. More...
 
void close_log_table (THD *thd, Open_tables_backup *backup)
 Close a log table. More...
 
void Table_share_deleter::operator() (TABLE_SHARE *share) const
 
 Open_table_context::Open_table_context (THD *thd, uint flags)
 Open_table_context. More...
 
bool Open_table_context::request_backoff_action (enum_open_table_action action_arg, Table_ref *table)
 Check if we can back-off and set back off action if we can. More...
 
bool Open_table_context::recover_from_failed_open ()
 Recover from failed attempt of open table by performing requested action. More...
 
bool DML_prelocking_strategy::handle_routine (THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking) override
 Defines how prelocking algorithm for DML statements should handle routines: More...
 
bool DML_prelocking_strategy::handle_table (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
 Defines how prelocking algorithm for DML statements should handle table list elements: More...
 
bool DML_prelocking_strategy::handle_view (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
 Defines how prelocking algorithm for DML statements should handle view - all view routines should be added to the prelocking set. More...
 
bool Lock_tables_prelocking_strategy::handle_table (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
 Defines how prelocking algorithm for LOCK TABLES statement should handle table list elements. More...
 
bool Alter_table_prelocking_strategy::handle_routine (THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking) override
 Defines how prelocking algorithm for ALTER TABLE statement should handle routines - do nothing as this statement is not supposed to call routines. More...
 
bool Alter_table_prelocking_strategy::handle_table (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
 Defines how prelocking algorithm for ALTER TABLE statement should handle table list elements. More...
 
bool Alter_table_prelocking_strategy::handle_view (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
 Defines how prelocking algorithm for ALTER TABLE statement should handle view - do nothing. More...
 

Variables

mysql_mutex_t LOCK_open
 LOCK_open protects the following variables/objects: More...
 
mysql_cond_t COND_open
 COND_open synchronizes concurrent opening of the same share: More...
 
static PSI_mutex_key key_LOCK_open
 
static PSI_cond_key key_COND_open
 
static PSI_mutex_info all_tdc_mutexes []
 
static PSI_cond_info all_tdc_conds []
 
Table_definition_cachetable_def_cache
 
static TABLE_SHAREoldest_unused_share
 
static TABLE_SHARE end_of_unused_share
 
static bool table_def_shutdown_in_progress = false
 
static Table_id last_table_id
 
Fieldnot_found_field = (Field *)0x1
 
Fieldview_ref_found = (Field *)0x2
 

Detailed Description

Macro Definition Documentation

◆ WRONG_GRANT

#define WRONG_GRANT   (Field *)-1

Typedef Documentation

◆ Table_definition_cache

Function Documentation

◆ Open_table_context()

Open_table_context::Open_table_context ( THD thd,
uint  flags 
)

Open_table_context.

◆ acquire_backup_lock_in_lock_tables_mode()

static bool acquire_backup_lock_in_lock_tables_mode ( THD thd,
Table_ref tables_start,
Table_ref tables_end 
)
static

Iterate along a list of tables and acquire BACKUP LOCK in shared mode in case a strong MDL request (DDL/LOCK TABLES-type) was specified for a table.

Parameters
[in]thdThread context.
[in]tables_startPointer to a start of a list of tables to iterate
[in]tables_endPointer to a end of a list of tables where to stop
Returns
false on success, true on error.

◆ add_view_place_holder()

bool add_view_place_holder ( THD thd,
Table_ref table_list 
)
static

Add a dummy LEX object for a view.

Parameters
thdThread context
table_listThe list of tables in the view
Return values
trueerror occurred
falseview place holder successfully added

◆ assign_new_table_id()

void assign_new_table_id ( TABLE_SHARE share)

◆ auto_repair_table()

static bool auto_repair_table ( THD thd,
Table_ref table_list 
)
static

Auxiliary routine which is used for performing automatic table repair.

◆ belongs_to_dd_table()

static bool belongs_to_dd_table ( const Table_ref tl)
static

Check if the given Table_ref belongs to a DD table.

The function checks whether the table is a DD table being used in the context of a DD transaction, or whether it is referred by a system view. Then, it implies that if either of these two conditions hold, then this is a DD table. If in case this is a DD table being used in some other situation, then this function does not return 'true'. We do not know if there is such a situation right now.

This function ignores Table_ref's that is created by optimizer when processing a system view.

Parameters
tlTable_ref point to the table.
Return values
trueIf table belongs to a DD table.
falseIf table does not.

◆ cached_table_definitions()

uint cached_table_definitions ( void  )

◆ call_before_insert_triggers()

bool call_before_insert_triggers ( THD thd,
TABLE table,
enum enum_trigger_event_type  event,
MY_BITMAP insert_into_fields_bitmap 
)
inline

Execute BEFORE INSERT trigger.

Parameters
thdthread context
tableTABLE-object holding list of triggers to be invoked
eventevent type for triggers to be invoked
insert_into_fields_bitmapBitmap for fields that is set in fill_record
Returns
Operation status
Return values
falseOK
trueError occurred

◆ check_and_update_routine_version()

static bool check_and_update_routine_version ( THD thd,
Sroutine_hash_entry rt,
sp_head sp 
)
static

Compares versions of a stored routine obtained from the sp cache and the version used at prepare.

If the new and the old values mismatch, invoke Metadata_version_observer. At prepared statement prepare, all Sroutine_hash_entry version values are NULL and we always have a mismatch. But there is no observer set in THD, and therefore no error is reported. Instead, we update the value in Sroutine_hash_entry, effectively recording the original version. At prepared statement execute, an observer may be installed. If there is a version mismatch, we push an error and return true.

For conventional execution (no prepared statements), the observer is never installed.

Parameters
[in]thdused to report errors
[in,out]rtpointer to stored routine entry in the parse tree
[in]sppointer to stored routine cache entry. Can be NULL if there is no such routine.
Return values
truean error, which has been reported
falsesuccess, version in Sroutine_hash_entry has been updated

◆ check_and_update_table_version()

static bool check_and_update_table_version ( THD thd,
Table_ref tables,
TABLE_SHARE table_share 
)
static

Compare metadata versions of an element obtained from the table definition cache and its corresponding node in the parse tree.

If the new and the old values mismatch, invoke Metadata_version_observer. At prepared statement prepare, all Table_ref version values are NULL and we always have a mismatch. But there is no observer set in THD, and therefore no error is reported. Instead, we update the value in the parse tree, effectively recording the original version. At prepared statement execute, an observer may be installed. If there is a version mismatch, we push an error and return true.

For conventional execution (no prepared statements), the observer is never installed.

See also
Execute_observer
check_prepared_statement() to see cases when an observer is installed
Table_ref::is_table_ref_id_equal()
TABLE_SHARE::get_table_ref_id()
Parameters
[in]thdused to report errors
[in,out]tablesTable_ref instance created by the parser Metadata version information in this object is updated upon success.
[in]table_sharean element from the table definition cache
Return values
truean error, which has been reported
falsesuccess, version in Table_ref has been updated

◆ check_if_table_exists()

static bool check_if_table_exists ( THD thd,
Table_ref table,
bool *  exists 
)
static

Check that table exists in data-dictionary 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
If there is no table in data-dictionary but it exists in one of engines (e.g. it was created on another node of NDB cluster) this function will fetch and add proper table description to the data-dictionary.
Return values
trueSome error occurred
falseNo error. 'exists' out parameter set accordingly.

◆ check_inserting_record()

static bool check_inserting_record ( THD thd,
Field **  ptr 
)
static

Check the NOT NULL constraint on all the fields explicitly set in INSERT INTO statement or implicitly set in BEFORE trigger.

Parameters
thdThread context.
ptrFields.
Returns
Error status.

◆ check_lock_and_start_stmt()

static bool check_lock_and_start_stmt ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list 
)
static

Check that lock is ok for tables; Call start stmt if ok.

Parameters
thdThread handle.
prelocking_ctxPrelocking context.
table_listTable list element for table to be checked.
Return values
false- Ok.
true- Error.

◆ check_record() [1/2]

static bool check_record ( THD thd,
const mem_root_deque< Item * > &  fields 
)
static

Check the NOT NULL constraint on all the fields of the current record.

Parameters
thdThread context.
fieldsCollection of fields.
Returns
Error status.

◆ check_record() [2/2]

bool check_record ( THD thd,
Field **  ptr 
)

Check the NOT NULL constraint on all the fields of the current record.

Parameters
thdThread context.
ptrFields.
Returns
Error status.

◆ close_all_tables_for_name() [1/3]

void close_all_tables_for_name ( THD thd,
const char *  db,
const char *  table_name,
bool  remove_from_locked_tables 
)

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 context.
dbDatabase name.
table_nameTable name.
remove_from_locked_tablesTrue if the table is being dropped. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list.
Precondition
Must be called with an X MDL lock on the table.

◆ close_all_tables_for_name() [2/3]

static void close_all_tables_for_name ( THD thd,
const char *  key,
size_t  key_length,
const char *  db,
const char *  table_name,
bool  remove_from_locked_tables,
TABLE skip_table 
)
static

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 context.
keyTC/TDC key identifying the table.
key_lengthLength of TC/TDC key identifying the table.
dbDatabase name.
table_nameTable name.
remove_from_locked_tablesTrue if the table is being dropped. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list.
skip_tableTABLE instance that should be kept open.
Precondition
Must be called with an X MDL lock on the table.

◆ close_all_tables_for_name() [3/3]

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 context.
shareTable share, but is just a handy way to access the table cache key.
remove_from_locked_tablesTrue if the table is being dropped. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list.
skip_tableTABLE instance that should be kept open.
Precondition
Must be called with an X MDL lock on the table.

◆ close_cached_tables()

bool close_cached_tables ( THD thd,
Table_ref tables,
bool  wait_for_refresh,
ulong  timeout 
)

◆ close_log_table()

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
backupThe context to restore.

◆ close_mysql_tables()

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.

◆ close_open_tables()

static void close_open_tables ( THD thd)
static

Auxiliary function to close all tables in the open_tables list.

Parameters
thdThread context.
Remarks
It should not ordinarily be called directly.

◆ close_tables_for_reopen()

void close_tables_for_reopen ( THD thd,
Table_ref **  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.

◆ close_temporary()

void close_temporary ( THD thd,
TABLE table,
bool  free_share,
bool  delete_table 
)

◆ close_temporary_table()

void close_temporary_table ( THD thd,
TABLE table,
bool  free_share,
bool  delete_table 
)

◆ close_temporary_tables()

bool close_temporary_tables ( THD thd)

◆ close_thread_table()

void close_thread_table ( THD thd,
TABLE **  table_ptr 
)

◆ close_thread_tables()

void close_thread_tables ( THD thd)

Close all tables used by the current substatement, or all tables used by this thread if we are on the outer-most level.

Parameters
thdThread handler

Unlocks all open persistent and temporary base tables. Put all persistent base tables used by thread in free list.

It will only close/mark as free for reuse tables opened by this substatement, it will also check if we are closing tables after execution of complete query (i.e. we are on outer-most level) and will leave prelocked mode if needed.

◆ close_trans_system_tables()

void close_trans_system_tables ( THD thd)

Close transactional system tables, opened with open_trans_system_tables_for_read().

Parameters
thdThread context.

◆ command_can_invoke_insert_triggers()

static bool command_can_invoke_insert_triggers ( enum enum_trigger_event_type  event,
enum_sql_command  sql_command 
)
inlinestatic

Check if SQL-statement is INSERT/INSERT SELECT/REPLACE/REPLACE SELECT and trigger event is ON INSERT.

When this condition is true that means that the statement basically can invoke BEFORE INSERT trigger if it was created before.

Parameters
eventevent type for triggers to be invoked
sql_commandType of SQL statement
Returns
Test result
Return values
trueSQL-statement is INSERT/INSERT SELECT/REPLACE/REPLACE SELECT and trigger event is ON INSERT
falseEither SQL-statement is not INSERT/INSERT SELECT/REPLACE/REPLACE SELECT or trigger event is not ON INSERT

◆ create_table_def_key()

static size_t create_table_def_key ( const char *  db_name,
const char *  table_name,
char *  key 
)
static

Create a table cache/table definition cache key for a table.

The table is neither a temporary table nor a table in a secondary storage engine.

Note
The table cache_key is created from:
db_name + \0
table_name + \0
Parameters
[in]db_namethe database name
[in]table_namethe table name
[out]keybuffer for the key to be created (must be of size MAX_DBKEY_LENGTH)
Returns
the length of the key

◆ create_table_def_key_secondary()

static std::string create_table_def_key_secondary ( const char *  db_name,
const char *  table_name 
)
static

Create a table cache/table definition cache key for a table in a secondary storage engine.

The key is constructed by appending a single byte with the value 1 to the key generated by create_table_def_key().

Parameters
db_namethe database name
table_namethe table name
Returns
the key

◆ create_table_def_key_tmp()

static size_t create_table_def_key_tmp ( const THD thd,
const char *  db_name,
const char *  table_name,
char *  key 
)
static

Create a table cache/table definition cache key for a temporary table.

The key is constructed by appending the following to the key generated by create_table_def_key():

  • 4 bytes for master thread id
  • 4 bytes pseudo thread id
Parameters
[in]thdthread context
[in]db_namethe database name
[in]table_namethe table name
[out]keybuffer for the key to be created (must be of size MAX_DBKEY_LENGTH)
Returns
the length of the key

◆ drop_temporary_table()

void drop_temporary_table ( THD thd,
Table_ref table_list 
)

Drop a temporary table.

  • 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 the table from the list of temporary tables.

◆ fill_record() [1/2]

bool fill_record ( THD thd,
TABLE table,
const mem_root_deque< Item * > &  fields,
const mem_root_deque< Item * > &  values,
MY_BITMAP bitmap,
MY_BITMAP insert_into_fields_bitmap,
bool  raise_autoinc_has_expl_non_null_val 
)

Fill fields with given items.

Parameters
thdThread handler.
tableTable reference.
fieldsItem_fields list to be filled
valuesValues to fill with.
bitmapBitmap over fields to fill.
insert_into_fields_bitmapBitmap for fields that is set in fill_record.
raise_autoinc_has_expl_non_null_valSet corresponding flag in TABLE object to true if non-NULL value is explicitly assigned to auto-increment field.
Note
fill_record() may set TABLE::autoinc_field_has_explicit_non_null_value to true (even in case of failure!) and its caller should make sure that it is reset before next call to this function (i.e. before processing next row) and/or before TABLE instance is returned to table cache. One can use helper Auto_increment_field_not_null_reset_guard class to do this.
In order to simplify implementation this call is allowed to reset TABLE::autoinc_field_has_explicit_non_null_value flag even in case when raise_autoinc_has_expl_non_null_val is false. However, this should be fine since this flag is supposed to be reset already in such cases.
Returns
Operation status
Return values
falseOK
trueError occurred

◆ fill_record() [2/2]

bool fill_record ( THD thd,
TABLE table,
Field **  ptr,
const mem_root_deque< Item * > &  values,
MY_BITMAP bitmap,
MY_BITMAP insert_into_fields_bitmap,
bool  raise_autoinc_has_expl_non_null_val 
)

Fill field buffer with values from Field list.

Parameters
thdThread handler.
tableTable reference.
ptrArray of fields to fill in.
valuesList of values to fill with.
bitmapBitmap over fields to fill.
insert_into_fields_bitmapBitmap for fields that is set in fill_record.
raise_autoinc_has_expl_non_null_valSet corresponding flag in TABLE object to true if non-NULL value is explicitly assigned to auto-increment field.
Note
fill_record() may set TABLE::autoinc_field_has_explicit_non_null_value to true (even in case of failure!) and its caller should make sure that it is reset before next call to this function (i.e. before processing next row) and/or before TABLE instance is returned to table cache. One can use helper Auto_increment_field_not_null_reset_guard class to do this.
In order to simplify implementation this call is allowed to reset TABLE::autoinc_field_has_explicit_non_null_value flag even in case when raise_autoinc_has_expl_non_null_val is false. However, this should be fine since this flag is supposed to be reset already in such cases.
Returns
Operation status
Return values
falseOK
trueError occurred

◆ fill_record_n_invoke_before_triggers() [1/2]

bool fill_record_n_invoke_before_triggers ( THD thd,
COPY_INFO optype_info,
const mem_root_deque< Item * > &  fields,
const mem_root_deque< Item * > &  values,
TABLE table,
enum enum_trigger_event_type  event,
int  num_fields,
bool  raise_autoinc_has_expl_non_null_val,
bool *  is_row_changed 
)

Fill fields in list with values from the list of items and invoke before triggers.

Parameters
thdThread context.
optype_infoCOPY_INFO structure used for default values handling.
fieldsItem_fields list to be filled.
valuesValues to fill with.
tableTABLE-object for the table.
eventEvent type for triggers to be invoked.
num_fieldsNumber of fields in table.
raise_autoinc_has_expl_non_null_valSet corresponding flag in TABLE to true if non-NULL value is explicitly assigned to auto-increment field.
[out]is_row_changedSet to true if a row is changed after filling record and invoking before triggers for UPDATE operation. Otherwise set to false.
Note
This function assumes that fields which values will be set and triggers to be invoked belong to the same table, and that TABLE::record[0] and record[1] buffers correspond to new and old versions of row respectively.
This call may set TABLE::autoinc_field_has_explicit_non_null_value to true (even in case of failure!) and its caller should make sure that it is reset appropriately (
See also
fill_record()).
Returns
Operation status
Return values
falseOK
trueError occurred

◆ fill_record_n_invoke_before_triggers() [2/2]

bool fill_record_n_invoke_before_triggers ( THD thd,
Field **  ptr,
const mem_root_deque< Item * > &  values,
TABLE table,
enum enum_trigger_event_type  event,
int  num_fields 
)

Fill fields in array with values from the list of items and invoke before triggers.

Parameters
thdThread context.
ptrNULL-ended array of fields to be filled.
valuesValues to fill with.
tableTABLE-object holding list of triggers to be invoked.
eventEvent type for triggers to be invoked.
num_fieldsNumber of fields in table.
Note
This function assumes that fields which values will be set and triggers to be invoked belong to the same table, and that TABLE::record[0] and record[1] buffers correspond to new and old versions of row respectively.
This function is called during handling of statements INSERT/ INSERT SELECT/CREATE SELECT. It means that the only trigger's type that can be invoked when this function is called is a BEFORE INSERT trigger so we don't need to make branching based on the result of execution function command_can_invoke_insert_triggers().
Unlike another version of fill_record_n_invoke_before_triggers() this call tries to set TABLE::autoinc_field_has_explicit_non_null_value to correct value unconditionally. So this flag can be set to true (even in case of failure!) and the caller should make sure that it is reset appropriately (
See also
fill_record()).
Return values
falseOK
trueError occurred.

◆ find_dup_table()

static Table_ref * find_dup_table ( const Table_ref table,
Table_ref table_list,
bool  check_alias 
)
static

Test that table is unique (It's only exists once in the table list)

Parameters
tabletable to be checked (must be updatable base table)
table_listlist of tables
check_aliaswhether to check tables' aliases

NOTE: to exclude derived tables from check we use following mechanism: a) during derived table processing set THD::derived_tables_processing b) Query_block::prepare set SELECT::exclude_from_table_unique_test if THD::derived_tables_processing set. (we can't use JOIN::execute because for PS we perform only Query_block::prepare, but we can't set this flag in Query_block::prepare if we are not sure that we are in derived table processing loop, because multi-update call fix_fields() for some its items (which mean Query_block::prepare for subqueries) before unique_table call to detect which tables should be locked for write). c) find_dup_table skip all tables which belong to SELECT with SELECT::exclude_from_table_unique_test set. Also SELECT::exclude_from_table_unique_test used to exclude from check tables of main SELECT of multi-delete and multi-update

We also skip tables with Table_ref::prelocking_placeholder set, because we want to allow SELECTs from them, and their modification will rise the error anyway.

TODO: when we will have table/view change detection we can do this check only once for PS/SP

Return values
!=0found duplicate
0if table is unique

◆ find_field_in_natural_join()

static Field * find_field_in_natural_join ( THD thd,
Table_ref table_ref,
const char *  name,
Item **  ref,
bool  register_tree_change,
Table_ref **  actual_table 
)
static

Find field by name in a NATURAL/USING join table reference.

Parameters
thdthread handler
table_reftable reference to search
namename of field
[in,out]refif 'name' is resolved to a view field, ref is set to point to the found view field
register_tree_changetrue if ref is not stack variable and we need register changes in item tree
[out]actual_tableThe original table reference where the field belongs - differs from 'table_list' only for NATURAL/USING joins

DESCRIPTION Search for a field among the result fields of a NATURAL/USING join. Notice that this procedure is called only for non-qualified field names. In the case of qualified fields, we search directly the base tables of a natural join.

Sometimes when a field is found, it is checked for privileges according to THD::want_privilege and marked according to THD::mark_used_columns. But it is unclear when, so caller generally has to do the same.

RETURN NULL if the field was not found WRONG_GRANT if no access rights to the found field

Pointer to the found Field

◆ find_field_in_table()

Field * find_field_in_table ( TABLE table,
const char *  name,
bool  allow_rowid,
uint field_index_ptr 
)

Find field by name in a base table.

No privileges are checked, and the column is not marked in read_set/write_set.

Parameters
tabletable where to search for the field
namename of field
allow_rowiddo allow finding of "_rowid" field?
[out]field_index_ptrposition in field list (used to speedup lookup for fields in prepared tables)
Return values
NULLfield is not found
!=NULL pointer to field

◆ find_field_in_table_ref()

Field * find_field_in_table_ref ( THD thd,
Table_ref table_list,
const char *  name,
size_t  length,
const char *  item_name,
const char *  db_name,
const char *  table_name,
Item **  ref,
Access_bitmask  want_privilege,
bool  allow_rowid,
uint field_index_ptr,
bool  register_tree_change,
Table_ref **  actual_table 
)

Find field in a table reference.

Parameters
thdthread handler
table_listtable reference to search
namename of field
lengthlength of field name
item_namename of item if it will be created (VIEW)
db_nameoptional database name that qualifies the field
table_nameoptional table name that qualifies the field
[in,out]refif 'name' is resolved to a view field, ref is set to point to the found view field
want_privilegeprivileges to check for column = 0: no privilege checking is needed
allow_rowiddo allow finding of "_rowid" field?
field_index_ptrposition in field list (used to speedup lookup for fields in prepared tables)
register_tree_changeTRUE if ref is not stack variable and we need register changes in item tree
[out]actual_tablethe original table reference where the field belongs - differs from 'table_list' only for NATURAL_USING joins.

Find a field in a table reference depending on the type of table reference. There are three types of table references with respect to the representation of their result columns:

  • an array of Field_translator objects for MERGE views and some information_schema tables,
  • an array of Field objects (and possibly a name hash) for stored tables,
  • a list of Natural_join_column objects for NATURAL/USING joins. This procedure detects the type of the table reference 'table_list' and calls the corresponding search routine.

The function checks column-level privileges for the found field according to argument want_privilege.

The function marks the column in corresponding table's read set or write set according to THD::mark_used_columns.

Return values
NULLfield is not found
view_ref_foundfound value in VIEW (real result is in *ref)
otherwisepointer to field

◆ find_field_in_table_sef()

Field * find_field_in_table_sef ( TABLE table,
const char *  name 
)

◆ find_field_in_tables()

Field * find_field_in_tables ( THD thd,
Item_ident item,
Table_ref first_table,
Table_ref last_table,
Item **  ref,
find_item_error_report_type  report_error,
Access_bitmask  want_privilege,
bool  register_tree_change 
)

◆ find_field_in_view()

static Field * find_field_in_view ( THD thd,
Table_ref table_list,
const char *  name,
Item **  ref,
bool  register_tree_change 
)
static

◆ find_item_in_list()

bool find_item_in_list ( THD thd,
Item find,
mem_root_deque< Item * > *  items,
Item ***  found,
uint counter,
enum_resolution_type resolution 
)

Find Item in list of items (find_field_in_tables analog)

Parameters
thdpointer to current thread
findItem to find
itemsList of items to search
[out]foundReturns the pointer to the found item, or nullptr if the item was not found
[out]counterReturns number of found item in list
[out]resolutionSet to the resolution type if the item is found (it says whether the item is resolved against an alias, or as a field name without alias, or as a field hidden by alias, or ignoring alias)
Note
"counter" and "resolution" are undefined unless "found" identifies an item.
Returns
true if error, false if success

◆ find_locked_table()

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.

◆ find_table_for_mdl_upgrade()

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.

◆ find_table_in_global_list()

Table_ref * find_table_in_global_list ( Table_ref table,
const char *  db_name,
const char *  table_name 
)

Find table in global list.

Parameters
tablePointer to table list
db_nameData base name
table_nameTable name
Returns
Pointer to found table.
Return values
NULLTable not found

◆ find_temporary_table() [1/3]

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.

◆ find_temporary_table() [2/3]

static TABLE * find_temporary_table ( THD thd,
const char *  table_key,
size_t  table_key_length 
)
static

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.

◆ find_temporary_table() [3/3]

TABLE * find_temporary_table ( THD thd,
const Table_ref tl 
)

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

Returns
TABLE instance if a temporary table has been found; NULL otherwise.

◆ fix_row_type()

static bool fix_row_type ( THD thd,
Table_ref table_list 
)
static

Auxiliary routine for automatically updating row format for the table.

◆ free_io_cache()

void free_io_cache ( TABLE table)

◆ get_and_lock_tablespace_names()

bool get_and_lock_tablespace_names ( THD thd,
Table_ref tables_start,
Table_ref tables_end,
ulong  lock_wait_timeout,
uint  flags 
)

Acquire IX metadata locks on tablespace names used by LOCK TABLES or by a DDL statement.

Note
That the tablespace MDL locks are taken only after locks on tables are acquired. So it is recommended to maintain this same lock order across the server. It is very easy to break the this lock order if we invoke acquire_locks() with list of MDL requests which contain both MDL_key::TABLE and MDL_key::TABLESPACE. We would end-up in deadlock then.
Parameters
thdThread context.
tables_startStart of list of tables on which 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
trueFailure (e.g. connection was killed)
falseSuccess.

◆ get_cached_table_share()

TABLE_SHARE * get_cached_table_share ( const char *  db,
const char *  table_name 
)

Get an existing table definition from the table definition cache.

Search the table definition cache for a share with the given key. If the share exists or if it is in the process of being opened by another thread (m_open_in_progress flag is true) return share. Do not wait for share opening to finish.

Parameters
dbdatabase name.
table_nametable name.
Return values
nulltpra share for the table does not exist in the cache
!=nulltpr pointer to existing share in the cache

◆ get_table_def_key()

size_t get_table_def_key ( const Table_ref table_list,
const char **  key 
)

Get table cache key for a table list element.

Parameters
[in]table_listTable list element.
[out]keyOn 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.

◆ get_table_share()

TABLE_SHARE * get_table_share ( THD thd,
const char *  db,
const char *  table_name,
const char *  key,
size_t  key_length,
bool  open_view,
bool  open_secondary 
)

Get the TABLE_SHARE for a table.

Get a table definition from the table definition cache. If the share does not exist, create a new one from the persistently stored table definition, and temporarily release LOCK_open while retrieving it. Re-lock LOCK_open when the table definition has been retrieved, and broadcast this to other threads waiting for the share to become opened.

If the share exists, and is in the process of being opened, wait for opening to complete before continuing.

Precondition
It is a precondition that the caller must own LOCK_open before calling this function.
Note
Callers of this function cannot rely on LOCK_open being held for the duration of the call. It may be temporarily released while the table definition is opened, and it may be temporarily released while the thread is waiting for a different thread to finish opening it.
After share->m_open_in_progress is set, there should be no wait for resources like row- or metadata locks, table flushes, etc. Otherwise, we may end up in deadlocks that will not be detected.
Parameters
thdthread handle
dbschema name
table_nametable name
keytable cache key
key_lengthlength of key
open_viewallow open of view
open_secondaryget the share for a table in a secondary storage engine
Returns
Pointer to the new TABLE_SHARE, or NULL if there was an error

◆ get_table_share_with_discover()

static TABLE_SHARE * get_table_share_with_discover ( THD thd,
Table_ref table_list,
const char *  key,
size_t  key_length,
bool  open_secondary,
int *  error 
)
static

Get a table share.

If it didn't exist, try creating it from engine

For arguments and return values, see get_table_share()

◆ handle_routine() [1/2]

bool DML_prelocking_strategy::handle_routine ( THD thd,
Query_tables_list prelocking_ctx,
Sroutine_hash_entry rt,
sp_head sp,
bool *  need_prelocking 
)
overridevirtual

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.

◆ handle_routine() [2/2]

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

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.

◆ handle_table() [1/3]

bool DML_prelocking_strategy::handle_table ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list,
bool *  need_prelocking 
)
overridevirtual

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.
  • If table participates in a foreign key we should add another table from it to the prelocking set with an appropriate metadata lock.

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.
[out]need_prelockingSet to true if method detects that prelocking required, not changed otherwise.
Return values
falseSuccess.
trueFailure (OOM).

Implements Prelocking_strategy.

Reimplemented in Lock_tables_prelocking_strategy.

◆ handle_table() [2/3]

bool Lock_tables_prelocking_strategy::handle_table ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list,
bool *  need_prelocking 
)
overrideprivatevirtual

Defines how prelocking algorithm for LOCK TABLES statement should handle table list elements.

Parameters
[in]thdThread context.
[in]prelocking_ctxPrelocking context of the statement.
[in]table_listTable list element for table.
[out]need_prelockingSet to true if method detects that prelocking required, not changed otherwise.
Return values
falseSuccess.
trueFailure (OOM).

Reimplemented from DML_prelocking_strategy.

◆ handle_table() [3/3]

bool Alter_table_prelocking_strategy::handle_table ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list,
bool *  need_prelocking 
)
overridevirtual

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

Unlike in DML, we do not process triggers here.

Implements Prelocking_strategy.

◆ handle_view() [1/2]

bool DML_prelocking_strategy::handle_view ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list,
bool *  need_prelocking 
)
overridevirtual

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.
[out]need_prelockingSet to true if method detects that prelocking required, not changed otherwise.
Return values
falseSuccess.
trueFailure (OOM).

Implements Prelocking_strategy.

◆ handle_view() [2/2]

bool Alter_table_prelocking_strategy::handle_view ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list,
bool *  need_prelocking 
)
overridevirtual

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.

◆ in_LTM()

static bool in_LTM ( THD thd)
inlinestatic

◆ init_ftfuncs()

bool init_ftfuncs ( THD thd,
Query_block query_block 
)

◆ init_tdc_psi_keys()

static void init_tdc_psi_keys ( void  )
static

Initialize performance schema instrumentation points used by the table cache.

◆ insert_fields()

bool insert_fields ( THD thd,
Query_block query_block,
const char *  db_name,
const char *  table_name,
mem_root_deque< Item * > *  fields,
mem_root_deque< Item * >::iterator *  it,
bool  any_privileges 
)

◆ intern_close_table()

void intern_close_table ( TABLE table)

◆ invoke_table_check_constraints()

bool invoke_table_check_constraints ( THD thd,
const TABLE table 
)

Invoke check constraints defined on the table.

Parameters
thdThread handle.
tableInstance of TABLE.
Return values
falseIf all enforced check constraints are satisfied.
trueOtherwise. THD::is_error() may be "true" in this case.

◆ is_acl_table_in_non_LTM()

bool is_acl_table_in_non_LTM ( const Table_ref tl,
enum enum_locked_tables_mode  ltm 
)

Check if given Table_ref is a acl table and is being read and not in LOCK TABLE mode.

Parameters
tlTable_ref pointing to the table.
ltmTHD->locked_tables_mode enum.
Returns
true if acl table is being read, otherwise false.

We ignore use of ACL table,

  • Under LOCK TABLE modes.
  • Under system view. E.g., I_S.ROLE_* uses CTE where they use TL_READ_DEFAULT for ACL tables. We ignore them.
  • If the Table_ref is used by optimizer as placeholder.

◆ is_temporary_table_being_opened()

static bool is_temporary_table_being_opened ( const Table_ref table)
inlinestatic

Check whether a table being opened is a temporary table.

Parameters
tabletable being opened
Returns
true if a table is temporary table, else false

◆ list_open_tables()

OPEN_TABLE_LIST * list_open_tables ( THD thd,
const char *  db,
const char *  wild 
)

◆ lock_dictionary_tables()

bool lock_dictionary_tables ( THD thd,
Table_ref tables,
uint  count,
uint  flags 
)

Simplified version of lock_tables() call to be used for locking data-dictionary tables when reading or storing data-dictionary objects.

Note
The main reason why this function exists is that it avoids allocating temporary buffer on memory root of statement. As result it can be called many times (e.g. thousands) during DDL statement execution without hogging memory.

◆ lock_table_names()

bool lock_table_names ( THD thd,
Table_ref tables_start,
Table_ref tables_end,
ulong  lock_wait_timeout,
uint  flags,
Prealloced_array< MDL_request *, 1 > *  schema_reqs 
)

Acquire "strong" (SRO, 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 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.
schema_reqsWhen non-nullptr, pointer to array in which pointers to MDL requests for acquired schema locks to be stored. It is guaranteed that each schema will be present in this array only once.
Return values
falseSuccess.
trueFailure (e.g. connection was killed)

◆ lock_tables()

bool lock_tables ( THD thd,
Table_ref 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.

◆ mark_common_columns()

static bool mark_common_columns ( THD thd,
Table_ref table_ref_1,
Table_ref table_ref_2,
List< String > *  using_fields,
uint found_using_fields 
)
static

◆ mark_real_tables_as_free_for_reuse()

static void mark_real_tables_as_free_for_reuse ( Table_ref table_list)
static

◆ mark_temp_tables_as_free_for_reuse()

static void mark_temp_tables_as_free_for_reuse ( THD thd)
static

Mark all temporary tables which were used by the current statement or substatement as free for reuse, but only if the query_id can be cleared.

Parameters
thdthread context
Remarks
For temp tables associated with a open SQL HANDLER the query_id is not reset until the HANDLER is closed.

◆ mark_tmp_table_for_reuse()

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.

◆ mark_used_tables_as_free_for_reuse()

static void mark_used_tables_as_free_for_reuse ( THD thd,
TABLE table 
)
static

◆ mysql_rm_tmp_tables()

bool mysql_rm_tmp_tables ( void  )

Drop all temporary tables which have been left from previous server run.

Used on server start-up.

Returns
False on success, true on error.

◆ open_and_lock_tables()

bool open_and_lock_tables ( THD thd,
Table_ref tables,
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.
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().
open_and_lock_tables() is not intended for open-and-locking system tables in those cases when execution of statement has started already and other tables have been opened. Use open_trans_system_tables_for_read() instead.
Return values
falseOK.
trueError

◆ open_and_process_routine()

static bool open_and_process_routine ( THD thd,
Query_tables_list prelocking_ctx,
Sroutine_hash_entry rt,
Prelocking_strategy prelocking_strategy,
bool  has_prelocking_list,
Open_table_context ot_ctx,
bool *  need_prelocking,
bool *  routine_modifies_data 
)
static

Handle element of prelocking set other than table.

E.g. cache routine and, if prelocking strategy prescribes so, extend the prelocking set with tables and routines used by it.

Parameters
[in]thdThread context.
[in]prelocking_ctxPrelocking context.
[in]rtElement of prelocking set to be processed.
[in]prelocking_strategyStrategy which specifies how the prelocking set should be extended when one of its elements is processed.
[in]has_prelocking_listIndicates that prelocking set/list for this statement has already been built.
[in]ot_ctxContext of open_table used to recover from locking failures.
[out]need_prelockingSet to true if it was detected that this statement will require prelocked mode for its execution, not touched otherwise.
[out]routine_modifies_dataSet to true if it was detected that this routine does modify table data.
Return values
falseSuccess.
trueFailure (Conflicting metadata lock, OOM, other errors).

We add trigger entries to lex->sroutines_list, but we don't load them here. The trigger entry is only used when building a transitive closure of objects used in a statement, to avoid adding to this closure objects that are used in the trigger more than once. E.g. if a trigger trg refers to table t2, and the trigger table t1 is used multiple times in the statement (say, because it's used in function f1() twice), we will only add t2 once to the list of tables to prelock.

We don't take metadata locks on triggers either: they are protected by a respective lock on the table, on which the trigger is defined.

The only two cases which give "trouble" are SHOW CREATE TRIGGER and DROP TRIGGER statements. For these, statement syntax doesn't specify the table on which this trigger is defined, so we have to make a "dirty" read in the data dictionary to find out the table name. Once we discover the table name, we take a metadata lock on it, and this protects all trigger operations. Of course the table, in theory, may disappear between the dirty read and metadata lock acquisition, but in that case we just return a run-time error.

Grammar of other trigger DDL statements (CREATE, DROP) requires the table to be specified explicitly, so we use the table metadata lock to protect trigger metadata in these statements. Similarly, in DML we always use triggers together with their tables, and thus don't need to take separate metadata locks on them.

◆ open_and_process_table()

static bool open_and_process_table ( THD thd,
LEX lex,
Table_ref *const  tables,
uint counter,
Prelocking_strategy prelocking_strategy,
bool  has_prelocking_list,
Open_table_context ot_ctx 
)
static

Handle table list element by obtaining metadata lock, opening table or view and, if prelocking strategy prescribes so, extending the prelocking set with tables and routines used by it.

Parameters
[in]thdThread context.
[in]lexLEX structure for statement.
[in]tablesTable list element to be processed.
[in,out]counterNumber of tables which are open.
[in]prelocking_strategyStrategy which specifies how the prelocking set should be extended when table or view is processed.
[in]has_prelocking_listIndicates that prelocking set/list for this statement has already been built.
[in]ot_ctxContext used to recover from a failed open_table() attempt.
Return values
falseSuccess.
trueError, reported unless there is a chance to recover from it.

◆ open_log_table()

TABLE * open_log_table ( THD thd,
Table_ref 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
[out]backupTemporary storage used to save the thread context

◆ open_ltable()

TABLE * open_ltable ( THD thd,
Table_ref table_list,
thr_lock_type  lock_type,
uint  lock_flags 
)

◆ open_n_lock_single_table()

TABLE * open_n_lock_single_table ( THD thd,
Table_ref 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().

◆ open_secondary_engine_tables()

static bool open_secondary_engine_tables ( THD thd,
uint  flags 
)
static

Check if a secondary engine can be used to execute the current statement, and if so, replace the opened tables with their secondary counterparts.

Parameters
thdthread handler
flagsbitmap of flags to pass to open_table
Returns
true if an error is raised, false otherwise

◆ open_table()

bool open_table ( THD thd,
Table_ref 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_ref::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.

Return values
trueOpen failed. "action" parameter may contain type of action needed to remedy problem before retrying again.
falseSuccess. Members of Table_ref structure are filled properly (e.g. Table_ref::table is set for real tables and Table_ref::view is set for views).

◆ open_table_entry_fini()

static bool open_table_entry_fini ( THD thd,
TABLE_SHARE share,
const dd::Table table,
TABLE entry 
)
static

Finalize the process of TABLE creation by loading table triggers and taking action if a HEAP table content was emptied implicitly.

◆ open_table_get_mdl_lock()

static bool open_table_get_mdl_lock ( THD thd,
Open_table_context ot_ctx,
Table_ref table_list,
uint  flags,
MDL_ticket **  mdl_ticket 
)
static

Try to acquire an MDL lock for a table being opened.

Parameters
[in,out]thdSession context, to report errors.
[out]ot_ctxOpen table context, to hold the back off state. If we failed to acquire a lock due to a lock conflict, we add the failed request to the open table context.
[in,out]table_listTable list element for the table being opened. Its "mdl_request" member specifies the MDL lock to be requested. If we managed to acquire a ticket (no errors or lock conflicts occurred), Table_ref::mdl_request contains a reference to it on return. However, is not modified if MDL lock type- modifying flags were provided. We also use Table_ref::lock_type member to detect cases when MDL_SHARED_WRITE_LOW_PRIO lock should be acquired instead of the normal MDL_SHARED_WRITE lock.
[in]flagsflags MYSQL_OPEN_FORCE_SHARED_MDL, MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL or MYSQL_OPEN_FAIL_ON_MDL_CONFLICT
See also
open_table().
Parameters
[out]mdl_ticketOnly modified if there was no error. If we managed to acquire an MDL lock, contains a reference to the ticket, otherwise is set to NULL.
Return values
trueAn error occurred.
falseNo error, but perhaps a lock conflict, check mdl_ticket.

◆ open_table_uncached()

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,
const dd::Table table_def 
)

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 added 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.
table_defA data-dictionary Table-object describing table to be used for opening.
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.

◆ open_tables()

bool open_tables ( THD thd,
Table_ref **  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.

Setup lock type for read requests for ACL table in SQL statements.

Do not request SE to skip row lock if 'flags' has MYSQL_OPEN_FORCE_SHARED_MDL, which indicates that this is PREPARE phase. It is OK to do so since during this phase no rows will be read anyway. And by doing this we avoid generation of extra warnings. EXECUTION phase will request SE to skip row locks if necessary.

◆ open_tables_check_upgradable_mdl()

static bool open_tables_check_upgradable_mdl ( THD thd,
Table_ref tables_start,
Table_ref tables_end 
)
static

Check for upgradable (SNW, SNRW) metadata locks on tables to be opened for a DDL statement.

Under LOCK TABLES, we can't take new locks, so we must check if appropriate locks were pre-acquired.

Parameters
thdThread context.
tables_startStart of list of tables on which upgradable locks should be searched for.
tables_endEnd of list of tables.
Return values
falseSuccess.
trueFailure (e.g. connection was killed)

◆ open_tables_for_query()

bool open_tables_for_query ( THD thd,
Table_ref tables,
uint  flags 
)

Open all tables for a query or statement, in list started by "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.

◆ open_temporary_table()

bool open_temporary_table ( THD thd,
Table_ref tl 
)

Find a temporary table specified by Table_ref 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.

◆ open_temporary_tables()

bool open_temporary_tables ( THD thd,
Table_ref 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.

◆ open_trans_system_tables_for_read()

bool open_trans_system_tables_for_read ( THD thd,
Table_ref table_list 
)

Open and lock transactional system tables for read.

One must call close_trans_system_tables() to close systems tables opened with this call.

Parameters
thdThread context.
table_listList of tables to open.
Note
THR_LOCK deadlocks are not possible here because of the restrictions we put on opening and locking of system tables for writing. Thus, the system tables can be opened and locked for reading even if some other tables have already been opened and locked.
MDL-deadlocks are possible, but they are properly detected and reported.
Row-level deadlocks should be either avoided altogether using non-locking reads (as it is done now for InnoDB), or should be correctly detected and reported (in case of other transactional SE).
It is now technically possible to open non-transactional tables (MyISAM system tables) using this function. That situation might still happen if the user run the server on the elder data-directory or manually alters the system tables to reside in MyISAM instead of InnoDB. It will be forbidden in the future.
Returns
Error status.

◆ operator()()

void Table_share_deleter::operator() ( TABLE_SHARE share) const

◆ process_found_table_share()

static TABLE_SHARE * process_found_table_share ( THD thd,
TABLE_SHARE share,
bool  open_view 
)
static

◆ process_table_fks()

static void process_table_fks ( THD thd,
Query_tables_list prelocking_ctx,
TABLE_SHARE share,
bool  is_insert,
bool  is_update,
bool  is_delete,
Table_ref belong_to_view,
bool *  need_prelocking 
)
static

Process table's foreign keys (if any) by prelocking algorithm.

Parameters
thdThread context.
prelocking_ctxPrelocking context of the statement.
shareTable's share.
is_insertIndicates whether statement is going to INSERT into the table.
is_updateIndicates whether statement is going to UPDATE the table.
is_deleteIndicates whether statement is going to DELETE from the table.
belong_to_viewUppermost view which uses this table element (nullptr - if it is not used by a view).
[out]need_prelockingSet to true if method detects that prelocking required, not changed otherwise.

◆ read_histograms()

static bool read_histograms ( THD thd,
TABLE_SHARE share,
const dd::Schema schema,
const dd::Abstract_table table_def 
)
static

Read any existing histogram statistics from the data dictionary and store a copy of them in the TABLE_SHARE.

Parameters
thdThread handler
shareThe table share where to store the histograms
schemaSchema definition
table_defTable definition
Return values
trueon error
falseon success

◆ read_lock_type_for_table()

thr_lock_type read_lock_type_for_table ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list,
bool  routine_modifies_data 
)

◆ recover_from_failed_open()

bool Open_table_context::recover_from_failed_open ( )

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

◆ release_or_close_table()

static void release_or_close_table ( THD thd,
TABLE table 
)
static

Helper function which returns TABLE to Table Cache or closes if table is marked as needing re-open.

◆ release_table_share()

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.

◆ rename_temporary_table()

bool rename_temporary_table ( THD thd,
TABLE table,
const char *  db,
const char *  table_name 
)

◆ request_backoff_action()

bool Open_table_context::request_backoff_action ( enum_open_table_action  action_arg,
Table_ref 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.

◆ resolve_var_assignments()

bool resolve_var_assignments ( THD thd,
LEX lex 
)

Resolve variable assignments from LEX object.

Parameters
thdThread handler
lexLex object containing variable assignments
Returns
false if success, true if error
Note
set_entry() must be called before fix_fields() of the whole list of field items because:

1) the list of field items has same order as in the query, and the Item_func_get_user_var item may go before the Item_func_set_user_var:

      SELECT @a, @a := 10 FROM t;

2) The entry->update_query_id value controls constantness of Item_func_get_user_var items, so in presence of Item_func_set_user_var items we have to refresh their entries before fixing of Item_func_get_user_var items.

◆ rm_temporary_table()

bool rm_temporary_table ( THD thd,
handlerton base,
const char *  path,
const dd::Table table_def 
)

Delete a temporary table.

Parameters
thdThread handle
baseHandlerton for table to be deleted.
pathPath to the table to be deleted (without an extension).
table_defdd::Table object describing temporary table to be deleted.
Return values
false- success.
true- failure.

◆ run_before_dml_hook()

int run_before_dml_hook ( THD thd)

Run the server hook called "before_dml".

This is a hook originated from replication that allow server plugins to execute code before any DML instruction is executed. In case of negative outcome, it will set my_error to ER_BEFORE_DML_VALIDATION_ERROR

Parameters
thdThread context
Returns
hook outcome
Return values
0Everything is fine
!=0Error in the outcome of the hook.

◆ set_new_item_local_context()

static bool set_new_item_local_context ( THD thd,
Item_ident item,
Table_ref table_ref 
)
static

◆ set_non_locking_read_for_ACL_table()

static bool set_non_locking_read_for_ACL_table ( THD thd,
Table_ref tl,
const bool &  issue_warning 
)
static

Check if this is a ACL table is requested for read and then request InnoDB to do non-locking reads on the table.

Parameters
thdThread
[in]tlTable_ref pointing to table being checked.
[in]issue_warningIf true, issue warning irrespective of isolation level.
Returns
false on success, true on error.

Issue a warning when,

  • We are skipping the SE locks in serializable
  • We are skipping the SE locks for SELECT IN SHARE MODE in all isolation mode.
  • When ACL table is not used under I_S system view.

◆ set_non_locking_read_for_IS_view()

static bool set_non_locking_read_for_IS_view ( THD thd,
Table_ref tl 
)
static

Check if this is a DD table used under a I_S view then request InnoDB to do non-locking reads on the table.

Parameters
thdThread
[in]tlTable_ref pointing to table being checked.
Returns
false on success, true on error.

◆ setup_fields()

bool setup_fields ( THD thd,
Access_bitmask  want_privilege,
bool  allow_sum_func,
bool  split_sum_funcs,
bool  column_update,
const mem_root_deque< Item * > *  typed_items,
mem_root_deque< Item * > *  fields,
Ref_item_array  ref_item_array 
)

Resolve a list of expressions and setup appropriate data.

Parameters
thdthread handler
want_privilegeprivilege representing desired operation. whether the expressions are selected, inserted or updated, or no operation is done. will also decide inclusion in read/write maps.
allow_sum_functrue if set operations are allowed in context.
column_updateif true, reject expressions that do not resolve to a base table column
split_sum_funcsIf true, Item::split_sum_func will add hidden items to "fields". See also description in its helper method Item::split_sum_func2.
typed_itemsList of reference items for type derivation May be nullptr.
[in,out]fieldslist of expressions, populated with resolved data about expressions.
[out]ref_item_arrayfilled in with references to items.
Return values
falseif success
trueif error
Note
The function checks updatability/insertability for the table before checking column privileges, for consistent error reporting. This has consequences for columns that are specified to be updated: The column is first resolved without privilege check. This check is followed by an updatablity/insertability check. Finally, a column privilege check is run, and the column is marked for update.

◆ setup_ftfuncs()

int setup_ftfuncs ( const THD thd,
Query_block query_block 
)

◆ setup_natural_join_row_types()

bool setup_natural_join_row_types ( THD thd,
mem_root_deque< Table_ref * > *  from_clause,
Name_resolution_context context 
)

◆ store_natural_using_join_columns()

static bool store_natural_using_join_columns ( THD thd,
Table_ref natural_using_join,
Table_ref table_ref_1,
Table_ref table_ref_2,
List< String > *  using_fields,
uint  found_using_fields 
)
static

◆ store_top_level_join_columns()

static bool store_top_level_join_columns ( THD thd,
Table_ref table_ref,
Table_ref left_neighbor,
Table_ref right_neighbor 
)
static

◆ table_def_free()

void table_def_free ( void  )

◆ table_def_init()

bool table_def_init ( void  )

◆ table_def_start_shutdown()

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.

◆ tdc_flush_unused_tables()

void tdc_flush_unused_tables ( )

◆ tdc_open_view()

static bool tdc_open_view ( THD thd,
Table_ref table_list,
const char *  cache_key,
size_t  cache_key_length 
)
static

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

Parameters
thdThread handle
table_listTable_ref with db, table_name & belong_to_view
cache_keyKey for table definition cache
cache_key_lengthLength of cache_key
Returns
false if success, true - otherwise.

◆ tdc_remove_table()

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. TDC_RT_MARK_FOR_REOPEN - remove all unused TABLE instances, mark used TABLE instances as needing reopen.
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).

◆ tdc_wait_for_old_version()

static bool tdc_wait_for_old_version ( THD thd,
const char *  db,
const char *  table_name,
ulong  wait_timeout,
uint  deadlock_weight 
)
static

Check if table's share is being removed from the table definition cache and, if yes, wait until the flush is complete.

Parameters
thdThread context.
dbDatabase name.
table_nameTable name.
wait_timeoutTimeout for waiting.
deadlock_weightWeight of this wait for deadlock detector.
Return values
falseSuccess. Share is up to date or has been flushed.
trueError (OOM, our was killed, the wait resulted in a deadlock or timeout). Reported.

◆ test_if_string_in_list()

static bool test_if_string_in_list ( const char *  find,
List< String > *  str_list 
)
static

◆ tmpkeyval()

static uint tmpkeyval ( TABLE table)
inlinestatic

◆ unique_table()

Table_ref * unique_table ( const Table_ref table,
Table_ref 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.

Parameters
tabletable to be checked (must be updatable base table)
table_listList of tables to check against
check_aliaswhether to check tables' aliases
Return values
non-NULLThe table list element for the table that represents the duplicate.
NULLNo duplicates found.

◆ update_non_unique_table_error()

void update_non_unique_table_error ( Table_ref update,
const char *  operation,
Table_ref duplicate 
)

Issue correct error message in case we found 2 duplicate tables which prevent some update operation.

Parameters
updatetable which we try to update
operationname of update operation
duplicateduplicate table which we found
Note
here we hide view underlying tables if we have them.

◆ update_schema_options()

static void update_schema_options ( const dd::Schema sch_obj,
TABLE_SHARE share 
)
static

Update TABLE_SHARE with options from dd::Schema object.

◆ wait_while_table_is_used()

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

◆ all_tdc_conds

PSI_cond_info all_tdc_conds[]
static
Initial value:
= {
{&key_COND_open, "COND_open", 0, 0, PSI_DOCUMENT_ME}}
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
static PSI_cond_key key_COND_open
Definition: sql_base.cc:302

◆ all_tdc_mutexes

PSI_mutex_info all_tdc_mutexes[]
static
Initial value:
= {
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:35
static PSI_mutex_key key_LOCK_open
Definition: sql_base.cc:301

◆ COND_open

mysql_cond_t COND_open

COND_open synchronizes concurrent opening of the same share:

If a thread calls get_table_share, it releases the LOCK_open mutex while reading the definition from file. If a different thread calls get_table_share for the same share at this point in time, it will find the share in the TDC, but with the m_open_in_progress flag set to true. This will make the (second) thread wait for the COND_open condition, while the first thread completes opening the table definition.

When the first thread is done reading the table definition, it will set m_open_in_progress to false and broadcast the COND_open condition. Then, all threads waiting for COND_open will wake up and, re-search the TDC for the share, and:

1) If the share is gone, the thread will continue to allocate and open the table definition. This happens, e.g., if the first thread failed when opening the table definition and had to destroy the share. 2) If the share is still in the cache, and m_open_in_progress is still true, the thread will wait for the condition again. This happens if a different thread finished opening a different share. 3) If the share is still in the cache, and m_open_in_progress has become false, the thread will check if the share is ok (no error), increment the ref counter, and return the share.

◆ end_of_unused_share

TABLE_SHARE end_of_unused_share
static

◆ key_COND_open

PSI_cond_key key_COND_open
static

◆ key_LOCK_open

PSI_mutex_key key_LOCK_open
static

◆ last_table_id

Table_id last_table_id
static

◆ LOCK_open

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, however, it does not protect reading the .frm file from where the table share is initialised. In get_table_share, the lock is temporarily released while opening the table definition in order to allow a higher degree of concurrency. Concurrent access to the same share is controlled by introducing a condition variable for signaling when opening the share is completed. 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

◆ not_found_field

Field* not_found_field = (Field *)0x1

◆ oldest_unused_share

TABLE_SHARE* oldest_unused_share
static

◆ table_def_cache

Table_definition_cache* table_def_cache

◆ table_def_shutdown_in_progress

bool table_def_shutdown_in_progress = false
static

◆ view_ref_found

Field* view_ref_found = (Field *)0x2