MySQL 8.0.39
Source Code Documentation
|
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 TABLE * | find_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_SHARE * | process_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_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. More... | |
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) |
Get a table share. More... | |
void | release_table_share (TABLE_SHARE *share) |
Mark that we are not using table share anymore. More... | |
TABLE_SHARE * | get_cached_table_share (const char *db, const char *table_name) |
Get an existing table definition from the table definition cache. More... | |
OPEN_TABLE_LIST * | list_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_ref * | find_table_in_global_list (Table_ref *table, const char *db_name, const char *table_name) |
Find table in global list. More... | |
static Table_ref * | find_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_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. 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... | |
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. More... | |
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. 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... | |
TABLE * | find_locked_table (TABLE *list, const char *db, const char *table_name) |
Find table in the list of open tables. More... | |
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. 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... | |
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. More... | |
TABLE * | open_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... | |
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. 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 Field * | find_field_in_view (THD *thd, Table_ref *table_list, const char *name, Item **ref, bool register_tree_change) |
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) |
Find field by name in a NATURAL/USING join table reference. More... | |
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. More... | |
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. More... | |
Field * | find_field_in_table_sef (TABLE *table, const char *name) |
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) |
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... | |
TABLE * | open_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_cache * | table_def_cache |
static TABLE_SHARE * | oldest_unused_share |
static TABLE_SHARE | end_of_unused_share |
static bool | table_def_shutdown_in_progress = false |
static Table_id | last_table_id |
Field * | not_found_field = (Field *)0x1 |
Field * | view_ref_found = (Field *)0x2 |
#define WRONG_GRANT (Field *)-1 |
using Table_definition_cache = malloc_unordered_map<std::string, std::unique_ptr<TABLE_SHARE, Table_share_deleter> > |
|
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.
[in] | thd | Thread context. |
[in] | tables_start | Pointer to a start of a list of tables to iterate |
[in] | tables_end | Pointer to a end of a list of tables where to stop |
Add a dummy LEX object for a view.
thd | Thread context |
table_list | The list of tables in the view |
true | error occurred |
false | view place holder successfully added |
void assign_new_table_id | ( | TABLE_SHARE * | share | ) |
Auxiliary routine which is used for performing automatic table repair.
|
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.
tl | Table_ref point to the table. |
true | If table belongs to a DD table. |
false | If table does not. |
uint cached_table_definitions | ( | void | ) |
|
inline |
Execute BEFORE INSERT trigger.
thd | thread context |
table | TABLE-object holding list of triggers to be invoked |
event | event type for triggers to be invoked |
insert_into_fields_bitmap | Bitmap for fields that is set in fill_record |
false | OK |
true | Error occurred |
|
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.
[in] | thd | used to report errors |
[in,out] | rt | pointer to stored routine entry in the parse tree |
[in] | sp | pointer to stored routine cache entry. Can be NULL if there is no such routine. |
true | an error, which has been reported |
false | success, version in Sroutine_hash_entry has been updated |
|
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.
[in] | thd | used to report errors |
[in,out] | tables | Table_ref instance created by the parser Metadata version information in this object is updated upon success. |
[in] | table_share | an element from the table definition cache |
true | an error, which has been reported |
false | success, version in Table_ref has been updated |
Check that table exists in data-dictionary or in some storage engine.
thd | Thread context | |
table | Table list element | |
[out] | exists | Out parameter which is set to true if table exists and to false otherwise. |
true | Some error occurred |
false | No error. 'exists' out parameter set accordingly. |
Check the NOT NULL constraint on all the fields explicitly set in INSERT INTO statement or implicitly set in BEFORE trigger.
thd | Thread context. |
ptr | Fields. |
|
static |
Check that lock is ok for tables; Call start stmt if ok.
thd | Thread handle. |
prelocking_ctx | Prelocking context. |
table_list | Table list element for table to be checked. |
false | - Ok. |
true | - Error. |
|
static |
Check the NOT NULL constraint on all the fields of the current record.
thd | Thread context. |
fields | Collection of fields. |
Check the NOT NULL constraint on all the fields of the current record.
thd | Thread context. |
ptr | Fields. |
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.
thd | Thread context. |
db | Database name. |
table_name | Table name. |
remove_from_locked_tables | True if the table is being dropped. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list. |
|
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.
thd | Thread context. |
key | TC/TDC key identifying the table. |
key_length | Length of TC/TDC key identifying the table. |
db | Database name. |
table_name | Table name. |
remove_from_locked_tables | True if the table is being dropped. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list. |
skip_table | TABLE instance that should be kept open. |
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.
thd | Thread context. |
share | Table share, but is just a handy way to access the table cache key. |
remove_from_locked_tables | True if the table is being dropped. In that case the documented behaviour is to implicitly remove the table from LOCK TABLES list. |
skip_table | TABLE instance that should be kept open. |
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.
thd | The current thread |
backup | The context to restore. |
void close_mysql_tables | ( | THD * | thd | ) |
A helper function to close a mysql.
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.
|
static |
Auxiliary function to close all tables in the open_tables list.
thd | Thread context. |
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.
[in] | thd | Thread context. |
[in,out] | tables | List of tables which we were trying to open and lock. |
[in] | start_of_statement_svp | MDL 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. |
bool close_temporary_tables | ( | THD * | thd | ) |
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.
thd | Thread 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.
void close_trans_system_tables | ( | THD * | thd | ) |
Close transactional system tables, opened with open_trans_system_tables_for_read().
thd | Thread context. |
|
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.
event | event type for triggers to be invoked |
sql_command | Type of SQL statement |
true | SQL-statement is INSERT/INSERT SELECT/REPLACE/REPLACE SELECT and trigger event is ON INSERT |
false | Either SQL-statement is not INSERT/INSERT SELECT/REPLACE/REPLACE SELECT or trigger event is not ON INSERT |
|
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.
db_name + \0 table_name + \0
[in] | db_name | the database name |
[in] | table_name | the table name |
[out] | key | buffer for the key to be created (must be of size MAX_DBKEY_LENGTH) |
|
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().
db_name | the database name |
table_name | the table name |
|
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():
[in] | thd | thread context |
[in] | db_name | the database name |
[in] | table_name | the table name |
[out] | key | buffer for the key to be created (must be of size MAX_DBKEY_LENGTH) |
Drop a temporary table.
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.
thd | Thread handler. |
table | Table reference. |
fields | Item_fields list to be filled |
values | Values to fill with. |
bitmap | Bitmap over fields to fill. |
insert_into_fields_bitmap | Bitmap for fields that is set in fill_record. |
raise_autoinc_has_expl_non_null_val | Set corresponding flag in TABLE object to true if non-NULL value is explicitly assigned to auto-increment field. |
false | OK |
true | Error occurred |
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.
thd | Thread handler. |
table | Table reference. |
ptr | Array of fields to fill in. |
values | List of values to fill with. |
bitmap | Bitmap over fields to fill. |
insert_into_fields_bitmap | Bitmap for fields that is set in fill_record. |
raise_autoinc_has_expl_non_null_val | Set corresponding flag in TABLE object to true if non-NULL value is explicitly assigned to auto-increment field. |
false | OK |
true | Error occurred |
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.
thd | Thread context. | |
optype_info | COPY_INFO structure used for default values handling. | |
fields | Item_fields list to be filled. | |
values | Values to fill with. | |
table | TABLE-object for the table. | |
event | Event type for triggers to be invoked. | |
num_fields | Number of fields in table. | |
raise_autoinc_has_expl_non_null_val | Set corresponding flag in TABLE to true if non-NULL value is explicitly assigned to auto-increment field. | |
[out] | is_row_changed | Set to true if a row is changed after filling record and invoking before triggers for UPDATE operation. Otherwise set to false. |
false | OK |
true | Error occurred |
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.
thd | Thread context. |
ptr | NULL-ended array of fields to be filled. |
values | Values to fill with. |
table | TABLE-object holding list of triggers to be invoked. |
event | Event type for triggers to be invoked. |
num_fields | Number of fields in table. |
false | OK |
true | Error occurred. |
|
static |
Test that table is unique (It's only exists once in the table list)
table | table to be checked (must be updatable base table) |
table_list | list of tables |
check_alias | whether 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
!=0 | found duplicate |
0 | if table is unique |
|
static |
Find field by name in a NATURAL/USING join table reference.
thd | thread handler | |
table_ref | table reference to search | |
name | name of field | |
[in,out] | ref | if 'name' is resolved to a view field, ref is set to point to the found view field |
register_tree_change | true if ref is not stack variable and we need register changes in item tree | |
[out] | actual_table | The 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
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.
table | table where to search for the field | |
name | name of field | |
allow_rowid | do allow finding of "_rowid" field? | |
[out] | field_index_ptr | position in field list (used to speedup lookup for fields in prepared tables) |
NULL | field is not found |
!= | NULL pointer to field |
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.
thd | thread handler | |
table_list | table reference to search | |
name | name of field | |
length | length of field name | |
item_name | name of item if it will be created (VIEW) | |
db_name | optional database name that qualifies the field | |
table_name | optional table name that qualifies the field | |
[in,out] | ref | if 'name' is resolved to a view field, ref is set to point to the found view field |
want_privilege | privileges to check for column = 0: no privilege checking is needed | |
allow_rowid | do allow finding of "_rowid" field? | |
field_index_ptr | position in field list (used to speedup lookup for fields in prepared tables) | |
register_tree_change | TRUE if ref is not stack variable and we need register changes in item tree | |
[out] | actual_table | the 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:
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.
NULL | field is not found |
view_ref_found | found value in VIEW (real result is in *ref) |
otherwise | pointer to field |
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 | ||
) |
|
static |
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)
thd | pointer to current thread | |
find | Item to find | |
items | List of items to search | |
[out] | found | Returns the pointer to the found item, or nullptr if the item was not found |
[out] | counter | Returns number of found item in list |
[out] | resolution | Set 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) |
Find table in the list of open tables.
list | List of TABLE objects to be inspected. |
db | Database name |
table_name | Table name |
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.
thd | Thread context |
db | Database name. |
table_name | Name of table. |
no_error | Don't emit error if no suitable TABLE instance were found. |
Table_ref * find_table_in_global_list | ( | Table_ref * | table, |
const char * | db_name, | ||
const char * | table_name | ||
) |
Find table in global list.
table | Pointer to table list |
db_name | Data base name |
table_name | Table name |
NULL | Table not found |
Find temporary table specified by database and table names in the THD::temporary_tables list.
|
static |
Find a temporary table specified by a key in the THD::temporary_tables list.
Find a temporary table specified by Table_ref instance in the THD::temporary_tables list.
Auxiliary routine for automatically updating row format for the table.
void free_io_cache | ( | TABLE * | table | ) |
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.
thd | Thread context. |
tables_start | Start of list of tables on which locks should be acquired. |
tables_end | End of list of tables. |
lock_wait_timeout | Seconds to wait before timeout. |
flags | Bitmap of flags to modify how the tables will be open, see open_table() description for details. |
true | Failure (e.g. connection was killed) |
false | Success. |
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.
db | database name. |
table_name | table name. |
nulltpr | a share for the table does not exist in the cache |
!= | nulltpr pointer to existing share in the cache |
size_t get_table_def_key | ( | const Table_ref * | table_list, |
const char ** | key | ||
) |
Get table cache key for a table list element.
[in] | table_list | Table list element. |
[out] | key | On return points to table cache key for the table. |
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.
thd | thread handle |
db | schema name |
table_name | table name |
key | table cache key |
key_length | length of key |
open_view | allow open of view |
open_secondary | get the share for a table in a secondary storage engine |
|
static |
Get a table share.
If it didn't exist, try creating it from engine
For arguments and return values, see get_table_share()
|
overridevirtual |
Defines how prelocking algorithm for DML statements should handle routines:
[in] | thd | Thread context. |
[in] | prelocking_ctx | Prelocking context of the statement. |
[in] | rt | Prelocking set element describing routine. |
[in] | sp | Routine body. |
[out] | need_prelocking | Set to true if method detects that prelocking required, not changed otherwise. |
false | Success. |
true | Failure (OOM). |
Implements Prelocking_strategy.
|
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.
|
overridevirtual |
Defines how prelocking algorithm for DML statements should handle table list elements:
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.
[in] | thd | Thread context. |
[in] | prelocking_ctx | Prelocking context of the statement. |
[in] | table_list | Table list element for table. |
[out] | need_prelocking | Set to true if method detects that prelocking required, not changed otherwise. |
false | Success. |
true | Failure (OOM). |
Implements Prelocking_strategy.
Reimplemented in Lock_tables_prelocking_strategy.
|
overrideprivatevirtual |
Defines how prelocking algorithm for LOCK TABLES statement should handle table list elements.
[in] | thd | Thread context. |
[in] | prelocking_ctx | Prelocking context of the statement. |
[in] | table_list | Table list element for table. |
[out] | need_prelocking | Set to true if method detects that prelocking required, not changed otherwise. |
false | Success. |
true | Failure (OOM). |
Reimplemented from DML_prelocking_strategy.
|
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.
|
overridevirtual |
Defines how prelocking algorithm for DML statements should handle view - all view routines should be added to the prelocking set.
[in] | thd | Thread context. |
[in] | prelocking_ctx | Prelocking context of the statement. |
[in] | table_list | Table list element for view. |
[out] | need_prelocking | Set to true if method detects that prelocking required, not changed otherwise. |
false | Success. |
true | Failure (OOM). |
Implements Prelocking_strategy.
|
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.
|
inlinestatic |
bool init_ftfuncs | ( | THD * | thd, |
Query_block * | query_block | ||
) |
|
static |
Initialize performance schema instrumentation points used by the table cache.
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 | ||
) |
void intern_close_table | ( | TABLE * | table | ) |
Invoke check constraints defined on the table.
thd | Thread handle. |
table | Instance of TABLE. |
false | If all enforced check constraints are satisfied. |
true | Otherwise. THD::is_error() may be "true" in this case. |
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.
tl | Table_ref pointing to the table. |
ltm | THD->locked_tables_mode enum. |
We ignore use of ACL table,
|
inlinestatic |
Check whether a table being opened is a temporary table.
table | table being opened |
OPEN_TABLE_LIST * list_open_tables | ( | THD * | thd, |
const char * | db, | ||
const char * | wild | ||
) |
Simplified version of lock_tables() call to be used for locking data-dictionary tables when reading or storing data-dictionary objects.
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.
thd | Thread context. |
tables_start | Start of list of tables on which locks should be acquired. |
tables_end | End of list of tables. |
lock_wait_timeout | Seconds to wait before timeout. |
flags | Bitmap of flags to modify how the tables will be open, see open_table() description for details. |
schema_reqs | When 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. |
false | Success. |
true | Failure (e.g. connection was killed) |
Lock all tables in a list.
thd | Thread handler |
tables | Tables to lock |
count | Number of opened tables |
flags | Options (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.
false | Success. |
true | A lock wait timeout, deadlock or out of memory. |
|
static |
|
static |
|
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.
thd | thread context |
void mark_tmp_table_for_reuse | ( | TABLE * | table | ) |
Reset a single temporary table.
Effectively this "closes" one temporary table, in a session.
table | Temporary table. |
bool mysql_rm_tmp_tables | ( | void | ) |
Drop all temporary tables which have been left from previous server run.
Used on server start-up.
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.
thd | Thread context. |
tables | List of tables for open and locking. |
flags | Bitmap of options to be used to open and lock tables (see open_tables() and mysql_lock_tables() for details). |
prelocking_strategy | Strategy which specifies how prelocking algorithm should work for this statement. |
false | OK. |
true | Error |
|
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.
[in] | thd | Thread context. |
[in] | prelocking_ctx | Prelocking context. |
[in] | rt | Element of prelocking set to be processed. |
[in] | prelocking_strategy | Strategy which specifies how the prelocking set should be extended when one of its elements is processed. |
[in] | has_prelocking_list | Indicates that prelocking set/list for this statement has already been built. |
[in] | ot_ctx | Context of open_table used to recover from locking failures. |
[out] | need_prelocking | Set to true if it was detected that this statement will require prelocked mode for its execution, not touched otherwise. |
[out] | routine_modifies_data | Set to true if it was detected that this routine does modify table data. |
false | Success. |
true | Failure (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.
|
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.
[in] | thd | Thread context. |
[in] | lex | LEX structure for statement. |
[in] | tables | Table list element to be processed. |
[in,out] | counter | Number of tables which are open. |
[in] | prelocking_strategy | Strategy which specifies how the prelocking set should be extended when table or view is processed. |
[in] | has_prelocking_list | Indicates that prelocking set/list for this statement has already been built. |
[in] | ot_ctx | Context used to recover from a failed open_table() attempt. |
false | Success. |
true | Error, reported unless there is a chance to recover from it. |
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().
thd | The current thread | |
one_table | Log table to open | |
[out] | backup | Temporary storage used to save the thread context |
TABLE * open_ltable | ( | THD * | thd, |
Table_ref * | table_list, | ||
thr_lock_type | lock_type, | ||
uint | lock_flags | ||
) |
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.
[in] | thd | thread handle |
[in] | table_l | table to open is first table in this list |
[in] | lock_type | lock to use for table |
[in] | flags | options to be used while opening and locking table (see open_table(), mysql_lock_tables()) |
[in] | prelocking_strategy | Strategy which specifies how prelocking algorithm should work for this statement. |
!= | NULL OK, opened table returned |
NULL | Error |
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().
Check if a secondary engine can be used to execute the current statement, and if so, replace the opened tables with their secondary counterparts.
thd | thread handler |
flags | bitmap of flags to pass to open_table |
bool open_table | ( | THD * | thd, |
Table_ref * | table_list, | ||
Open_table_context * | ot_ctx | ||
) |
Open a base table.
thd | Thread context. |
table_list | Open first table in list. |
ot_ctx | Context 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.
true | Open failed. "action" parameter may contain type of action needed to remedy problem before retrying again. |
false | Success. 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). |
|
static |
Finalize the process of TABLE creation by loading table triggers and taking action if a HEAP table content was emptied implicitly.
|
static |
Try to acquire an MDL lock for a table being opened.
[in,out] | thd | Session context, to report errors. |
[out] | ot_ctx | Open 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_list | Table 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] | flags | flags MYSQL_OPEN_FORCE_SHARED_MDL, MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL or MYSQL_OPEN_FAIL_ON_MDL_CONFLICT |
[out] | mdl_ticket | Only 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. |
true | An error occurred. |
false | No error, but perhaps a lock conflict, check mdl_ticket. |
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.
thd | Thread context. |
path | Path (without .frm) |
db | Database name. |
table_name | Table name. |
add_to_temporary_tables_list | Specifies if the opened TABLE instance should be linked into THD::temporary_tables list. |
open_in_engine | Indicates that we need to open table in storage engine in addition to constructing TABLE object for it. |
table_def | A data-dictionary Table-object describing table to be used for opening. |
NULL | on error. |
bool open_tables | ( | THD * | thd, |
Table_ref ** | start, | ||
uint * | counter, | ||
uint | flags, | ||
Prelocking_strategy * | prelocking_strategy | ||
) |
Open all tables in list.
[in] | thd | Thread context. |
[in,out] | start | List of tables to be open (it can be adjusted for statement that uses tables only implicitly, e.g. for "SELECT f1()"). |
[out] | counter | Number of tables which were open. |
[in] | flags | Bitmap of flags to modify how the tables will be open, see open_table() description for details. |
[in] | prelocking_strategy | Strategy which specifies how prelocking algorithm should work for this statement. |
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.
false | Success. |
true | Error, 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.
|
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.
thd | Thread context. |
tables_start | Start of list of tables on which upgradable locks should be searched for. |
tables_end | End of list of tables. |
false | Success. |
true | Failure (e.g. connection was killed) |
Open all tables for a query or statement, in list started by "tables".
thd | thread handler |
tables | list of tables for open |
flags | bitmap 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. |
false | - ok |
true | - error |
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.
false | On success. If a temporary table exists for the given key, tl->table is set. |
true | On error. my_error() has been called. |
Pre-open temporary tables corresponding to table list elements.
false | On success. If a temporary tables exists for the given element, tl->table is set. |
true | On error. my_error() has been called. |
Open and lock transactional system tables for read.
One must call close_trans_system_tables() to close systems tables opened with this call.
thd | Thread context. |
table_list | List of tables to open. |
void Table_share_deleter::operator() | ( | TABLE_SHARE * | share | ) | const |
|
static |
|
static |
Process table's foreign keys (if any) by prelocking algorithm.
thd | Thread context. | |
prelocking_ctx | Prelocking context of the statement. | |
share | Table's share. | |
is_insert | Indicates whether statement is going to INSERT into the table. | |
is_update | Indicates whether statement is going to UPDATE the table. | |
is_delete | Indicates whether statement is going to DELETE from the table. | |
belong_to_view | Uppermost view which uses this table element (nullptr - if it is not used by a view). | |
[out] | need_prelocking | Set to true if method detects that prelocking required, not changed otherwise. |
|
static |
Read any existing histogram statistics from the data dictionary and store a copy of them in the TABLE_SHARE.
thd | Thread handler |
share | The table share where to store the histograms |
schema | Schema definition |
table_def | Table definition |
true | on error |
false | on success |
thr_lock_type read_lock_type_for_table | ( | THD * | thd, |
Query_tables_list * | prelocking_ctx, | ||
Table_ref * | table_list, | ||
bool | routine_modifies_data | ||
) |
bool Open_table_context::recover_from_failed_open | ( | ) |
Recover from failed attempt of open table by performing requested action.
false | - Success. One should try to open tables once again. |
true | - Error |
Helper function which returns TABLE to Table Cache or closes if table is marked as needing re-open.
void release_table_share | ( | TABLE_SHARE * | share | ) |
Mark that we are not using table share anymore.
share | Table share |
If the share has no open tables and (we have done a refresh or if we have already too many open table shares) then delete the definition.
bool Open_table_context::request_backoff_action | ( | enum_open_table_action | action_arg, |
Table_ref * | table | ||
) |
Check if we can back-off and set back off action if we can.
Otherwise report and return error.
true | if back-off is impossible. |
false | if we can back off. Back off action has been set. |
Resolve variable assignments from LEX object.
thd | Thread handler |
lex | Lex object containing variable assignments |
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.
bool rm_temporary_table | ( | THD * | thd, |
handlerton * | base, | ||
const char * | path, | ||
const dd::Table * | table_def | ||
) |
Delete a temporary table.
thd | Thread handle |
base | Handlerton for table to be deleted. |
path | Path to the table to be deleted (without an extension). |
table_def | dd::Table object describing temporary table to be deleted. |
false | - success. |
true | - failure. |
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
thd | Thread context |
0 | Everything is fine |
!=0 | Error in the outcome of the hook. |
|
static |
|
static |
Check if this is a ACL table is requested for read and then request InnoDB to do non-locking reads on the table.
thd | Thread | |
[in] | tl | Table_ref pointing to table being checked. |
[in] | issue_warning | If true, issue warning irrespective of isolation level. |
Issue a warning when,
Check if this is a DD table used under a I_S view then request InnoDB to do non-locking reads on the table.
thd | Thread | |
[in] | tl | Table_ref pointing to table being checked. |
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.
thd | thread handler | |
want_privilege | privilege 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_func | true if set operations are allowed in context. | |
column_update | if true, reject expressions that do not resolve to a base table column | |
split_sum_funcs | If true, Item::split_sum_func will add hidden items to "fields". See also description in its helper method Item::split_sum_func2. | |
typed_items | List of reference items for type derivation May be nullptr. | |
[in,out] | fields | list of expressions, populated with resolved data about expressions. |
[out] | ref_item_array | filled in with references to items. |
false | if success |
true | if error |
int setup_ftfuncs | ( | const THD * | thd, |
Query_block * | query_block | ||
) |
bool setup_natural_join_row_types | ( | THD * | thd, |
mem_root_deque< Table_ref * > * | from_clause, | ||
Name_resolution_context * | context | ||
) |
|
static |
|
static |
void table_def_free | ( | void | ) |
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.
void tdc_flush_unused_tables | ( | ) |
|
static |
Open view by getting its definition from disk (and table cache in future).
thd | Thread handle |
table_list | Table_ref with db, table_name & belong_to_view |
cache_key | Key for table definition cache |
cache_key_length | Length of cache_key |
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.
thd | Thread context |
remove_type | Type 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. |
db | Name of database |
table_name | Name of table |
has_lock | If true, LOCK_open is already acquired |
|
static |
Check if table's share is being removed from the table definition cache and, if yes, wait until the flush is complete.
thd | Thread context. |
db | Database name. |
table_name | Table name. |
wait_timeout | Timeout for waiting. |
deadlock_weight | Weight of this wait for deadlock detector. |
false | Success. Share is up to date or has been flushed. |
true | Error (OOM, our was killed, the wait resulted in a deadlock or timeout). Reported. |
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.
table | table to be checked (must be updatable base table) |
table_list | List of tables to check against |
check_alias | whether to check tables' aliases |
non-NULL | The table list element for the table that represents the duplicate. |
NULL | No duplicates found. |
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.
update | table which we try to update |
operation | name of update operation |
duplicate | duplicate table which we found |
|
static |
Update TABLE_SHARE with options from dd::Schema object.
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.
thd | Thread handler |
table | Table to remove from cache |
function | HA_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 |
false | Success. |
true | Failure (e.g. because thread was killed). |
|
static |
|
static |
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.
|
static |
|
static |
|
static |
|
static |
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
|
static |
Table_definition_cache* table_def_cache |
|
static |