MySQL  8.0.16
Source Code Documentation
sql_base.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include <memory>
#include <string>
#include "lex_string.h"
#include "map_helpers.h"
#include "my_base.h"
#include "my_inttypes.h"
#include "mysql/components/services/mysql_mutex_bits.h"
#include "prealloced_array.h"
#include "sql/mdl.h"
#include "sql/sql_array.h"
#include "sql/sql_const.h"
#include "sql/trigger_def.h"
#include "thr_lock.h"

Go to the source code of this file.

Classes

class  List< T >
 
class  List_iterator< T >
 
struct  Table_share_deleter
 
class  Prelocking_strategy
 An abstract class for a strategy specifying how the prelocking algorithm should extend the prelocking set while processing already existing elements in the set. More...
 
class  DML_prelocking_strategy
 A Strategy for prelocking algorithm suitable for DML statements. More...
 
class  Lock_tables_prelocking_strategy
 A strategy for prelocking algorithm to be used for LOCK TABLES statement. More...
 
class  Alter_table_prelocking_strategy
 Strategy for prelocking algorithm to be used for ALTER TABLE statements. More...
 
class  Open_table_context
 A context of open_tables() function, used to recover from a failed open_table() or open_routine() attempt. More...
 

Namespaces

 dd
 The version of the current data dictionary table definitions.
 

Macros

#define TEMP_PREFIX   "MY"
 
#define READ_ALL   1 /* openfrm: Read all parameters */
 
#define EXTRA_RECORD   8 /* Reservera plats f|r extra record */
 
#define DELAYED_OPEN   4096 /* Open table later */
 
#define SKIP_NEW_HANDLER   32768
 If set, open_table_from_share() will skip calling get_new_handler() to create a new handler object for the table. More...
 
#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK   0x0001
 
#define MYSQL_OPEN_IGNORE_FLUSH   0x0002
 
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY   0x0008
 
#define MYSQL_LOCK_LOG_TABLE   0x0010
 
#define MYSQL_OPEN_HAS_MDL_LOCK   0x0020
 Do not try to acquire a metadata lock on the table: we already have one. More...
 
#define MYSQL_OPEN_GET_NEW_TABLE   0x0040
 If in locked tables mode, ignore the locked tables and get a new instance of the table. More...
 
#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT   0x0100
 Fail instead of waiting when conficting metadata lock is discovered. More...
 
#define MYSQL_OPEN_FORCE_SHARED_MDL   0x0200
 Open tables using MDL_SHARED lock instead of one specified in parser. More...
 
#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL   0x0400
 Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified in parser. More...
 
#define MYSQL_LOCK_IGNORE_TIMEOUT   0x0800
 When opening or locking the table, use the maximum timeout (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value. More...
 
#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK   0x1000
 When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to be open do not acquire global, tablespace-scope and schema-scope IX locks. More...
 
#define MYSQL_LOCK_RPL_INFO_TABLE   0x2000
 When opening or locking a replication table through an internal operation rather than explicitly through an user thread. More...
 
#define MYSQL_OPEN_IGNORE_KILLED   0x4000
 Only check THD::killed if waits happen (e.g. More...
 
#define MYSQL_OPEN_NO_NEW_TABLE_IN_SE   0x8000
 For new TABLE instances constructed do not open table in the storage engine. More...
 
#define MYSQL_OPEN_SECONDARY_ENGINE   0x10000
 Open a shadow copy of a table from a secondary storage engine. More...
 
#define MYSQL_OPEN_REOPEN
 Please refer to the internals manual. More...
 

Typedefs

typedef Bounds_checked_array< Item * > Ref_item_array
 

Enumerations

enum  find_item_error_report_type {
  REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND, IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
  IGNORE_EXCEPT_NON_UNIQUE
}
 
enum  enum_tdc_remove_table_type { TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN, TDC_RT_REMOVE_UNUSED, TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE }
 

Functions

bool table_def_init (void)
 
void table_def_free (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 assign_new_table_id (TABLE_SHARE *share)
 
uint cached_table_definitions (void)
 
size_t get_table_def_key (const TABLE_LIST *table_list, const char **key)
 Get table cache key for a table list element. 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=false)
 Get the TABLE_SHARE for a table. More...
 
void release_table_share (TABLE_SHARE *share)
 Mark that we are not using table share anymore. More...
 
TABLEopen_ltable (THD *thd, TABLE_LIST *table_list, thr_lock_type update, uint lock_flags)
 
bool open_table (THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
 Open a base table. 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...
 
TABLEfind_locked_table (TABLE *list, const char *db, const char *table_name)
 Find table in the list of open tables. More...
 
thr_lock_type read_lock_type_for_table (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool routine_modifies_data)
 
bool mysql_rm_tmp_tables (void)
 Drop all temporary tables which have been left from previous server run. More...
 
bool rm_temporary_table (THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
 Delete a temporary table. More...
 
void close_tables_for_reopen (THD *thd, TABLE_LIST **tables, const MDL_savepoint &start_of_statement_svp)
 Prepare statement for reopening of tables and recalculation of set of prelocked tables. 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_LIST *tl)
 Find a temporary table specified by TABLE_LIST instance in the THD::temporary_tables list. More...
 
void close_thread_tables (THD *thd)
 
bool fill_record_n_invoke_before_triggers (THD *thd, COPY_INFO *optype_info, List< Item > &fields, List< Item > &values, TABLE *table, enum enum_trigger_event_type event, int num_fields)
 
bool fill_record_n_invoke_before_triggers (THD *thd, Field **field, List< Item > &values, TABLE *table, enum enum_trigger_event_type event, int num_fields)
 
bool resolve_var_assignments (THD *thd, LEX *lex)
 Resolve variable assignments from LEX object. More...
 
bool insert_fields (THD *thd, Name_resolution_context *context, const char *db_name, const char *table_name, List_iterator< Item > *it, bool any_privileges)
 
bool setup_fields (THD *thd, Ref_item_array ref_item_array, List< Item > &item, ulong privilege, List< Item > *sum_func_list, bool allow_sum_func, bool column_update)
 Resolve a list of expressions and setup appropriate data. More...
 
bool fill_record (THD *thd, TABLE *table, List< Item > &fields, List< Item > &values, MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap)
 
bool fill_record (THD *thd, TABLE *table, Field **field, List< Item > &values, MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap)
 Fill field buffer with values from Field list. More...
 
bool check_record (THD *thd, Field **ptr)
 Check the NOT NULL constraint on all the fields of the current record. More...
 
bool invoke_table_check_constraints (THD *thd, const TABLE *table)
 Invoke check constraints defined on the table. More...
 
Fieldfind_field_in_tables (THD *thd, Item_ident *item, TABLE_LIST *first_table, TABLE_LIST *last_table, Item **ref, find_item_error_report_type report_error, ulong want_privilege, bool register_tree_change)
 
Fieldfind_field_in_table_ref (THD *thd, TABLE_LIST *table_list, const char *name, size_t length, const char *item_name, const char *db_name, const char *table_name, Item **ref, ulong want_privilege, bool allow_rowid, uint *cached_field_index_ptr, bool register_tree_change, TABLE_LIST **actual_table)
 
Fieldfind_field_in_table (TABLE *table, const char *name, size_t length, bool allow_rowid, uint *cached_field_index_ptr)
 
Fieldfind_field_in_table_sef (TABLE *table, const char *name)
 
Item ** find_item_in_list (THD *thd, Item *item, List< Item > &items, uint *counter, find_item_error_report_type report_error, enum_resolution_type *resolution)
 
bool setup_natural_join_row_types (THD *thd, List< TABLE_LIST > *from_clause, Name_resolution_context *context)
 
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...
 
void update_non_unique_table_error (TABLE_LIST *update, const char *operation, TABLE_LIST *duplicate)
 Issue correct error message in case we found 2 duplicate tables which prevent some update operation. More...
 
int setup_ftfuncs (const THD *thd, SELECT_LEX *select)
 
bool init_ftfuncs (THD *thd, SELECT_LEX *select)
 
int run_before_dml_hook (THD *thd)
 Run the server hook called "before_dml". More...
 
bool get_and_lock_tablespace_names (THD *thd, TABLE_LIST *tables_start, TABLE_LIST *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_LIST *table_list, TABLE_LIST *table_list_end, ulong lock_wait_timeout, uint flags, Prealloced_array< MDL_request *, 1 > *schema_reqs=nullptr)
 Acquire "strong" (SRO, SNW, SNRW) metadata locks on tables used by LOCK TABLES or by a DDL statement. More...
 
bool open_tables (THD *thd, TABLE_LIST **tables, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
 Open all tables in list. More...
 
bool open_and_lock_tables (THD *thd, TABLE_LIST *tables, uint flags, Prelocking_strategy *prelocking_strategy)
 Open all tables in list, locks them and optionally process derived tables. More...
 
TABLEopen_n_lock_single_table (THD *thd, TABLE_LIST *table_l, thr_lock_type lock_type, uint flags, Prelocking_strategy *prelocking_strategy)
 Open and lock one table. More...
 
bool open_tables_for_query (THD *thd, TABLE_LIST *tables, uint flags)
 Open all tables for a query or statement, in list started by "tables". More...
 
bool lock_tables (THD *thd, TABLE_LIST *tables, uint counter, uint flags)
 Lock all tables in a list. More...
 
void free_io_cache (TABLE *entry)
 
void intern_close_table (TABLE *entry)
 
void close_thread_table (THD *thd, TABLE **table_ptr)
 
bool close_temporary_tables (THD *thd)
 
TABLE_LISTunique_table (const TABLE_LIST *table, TABLE_LIST *table_list, bool check_alias)
 Test that the subject table of INSERT/UPDATE/DELETE/CREATE or (in case of MyISAMMRG) one of its children are not used later in the query. More...
 
void drop_temporary_table (THD *thd, TABLE_LIST *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 *new_db, const char *table_name)
 
bool open_temporary_tables (THD *thd, TABLE_LIST *tl_list)
 Pre-open temporary tables corresponding to table list elements. More...
 
bool open_temporary_table (THD *thd, TABLE_LIST *tl)
 Find a temporary table specified by TABLE_LIST instance in the cache and prepare its TABLE instance for use. More...
 
bool is_equal (const LEX_STRING *a, const LEX_STRING *b)
 
bool open_trans_system_tables_for_read (THD *thd, TABLE_LIST *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_LIST *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...
 
bool close_cached_tables (THD *thd, TABLE_LIST *tables, bool wait_for_refresh, ulong timeout)
 
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...
 
OPEN_TABLE_LISTlist_open_tables (THD *thd, const char *db, const char *wild)
 
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...
 
void tdc_flush_unused_tables ()
 
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 mark_tmp_table_for_reuse (TABLE *table)
 Reset a single temporary table. More...
 
TABLE_LISTfind_table_in_global_list (TABLE_LIST *table, const char *db_name, const char *table_name)
 Find table in global list. More...
 
bool open_tables (THD *thd, TABLE_LIST **tables, uint *counter, uint flags)
 
TABLEopen_n_lock_single_table (THD *thd, TABLE_LIST *table_l, thr_lock_type lock_type, uint flags)
 
bool open_and_lock_tables (THD *thd, TABLE_LIST *tables, uint flags)
 

Variables

mysql_mutex_t LOCK_open
 LOCK_open protects the following variables/objects: More...
 
Item ** not_found_item
 
Fieldnot_found_field
 
Fieldview_ref_found
 
malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > > * table_def_cache
 

Macro Definition Documentation

◆ DELAYED_OPEN

#define DELAYED_OPEN   4096 /* Open table later */

◆ EXTRA_RECORD

#define EXTRA_RECORD   8 /* Reservera plats f|r extra record */

◆ MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY

#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY   0x0008

◆ MYSQL_LOCK_IGNORE_TIMEOUT

#define MYSQL_LOCK_IGNORE_TIMEOUT   0x0800

When opening or locking the table, use the maximum timeout (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.

◆ MYSQL_LOCK_LOG_TABLE

#define MYSQL_LOCK_LOG_TABLE   0x0010

◆ MYSQL_LOCK_RPL_INFO_TABLE

#define MYSQL_LOCK_RPL_INFO_TABLE   0x2000

When opening or locking a replication table through an internal operation rather than explicitly through an user thread.

◆ MYSQL_OPEN_FAIL_ON_MDL_CONFLICT

#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT   0x0100

Fail instead of waiting when conficting metadata lock is discovered.

◆ MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL

#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL   0x0400

Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified in parser.

◆ MYSQL_OPEN_FORCE_SHARED_MDL

#define MYSQL_OPEN_FORCE_SHARED_MDL   0x0200

Open tables using MDL_SHARED lock instead of one specified in parser.

◆ MYSQL_OPEN_GET_NEW_TABLE

#define MYSQL_OPEN_GET_NEW_TABLE   0x0040

If in locked tables mode, ignore the locked tables and get a new instance of the table.

◆ MYSQL_OPEN_HAS_MDL_LOCK

#define MYSQL_OPEN_HAS_MDL_LOCK   0x0020

Do not try to acquire a metadata lock on the table: we already have one.

◆ MYSQL_OPEN_IGNORE_FLUSH

#define MYSQL_OPEN_IGNORE_FLUSH   0x0002

◆ MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK

#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK   0x0001

◆ MYSQL_OPEN_IGNORE_KILLED

#define MYSQL_OPEN_IGNORE_KILLED   0x4000

Only check THD::killed if waits happen (e.g.

wait on MDL, wait on table flush, wait on thr_lock.c locks) while opening and locking table.

◆ MYSQL_OPEN_NO_NEW_TABLE_IN_SE

#define MYSQL_OPEN_NO_NEW_TABLE_IN_SE   0x8000

For new TABLE instances constructed do not open table in the storage engine.

Existing TABLE instances for which there is a handler object which represents table open in storage engines can still be used.

◆ MYSQL_OPEN_REOPEN

#define MYSQL_OPEN_REOPEN
Value:
MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_LOCK_IGNORE_TIMEOUT | \
MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_GET_NEW_TABLE | \
MYSQL_OPEN_HAS_MDL_LOCK)
#define MYSQL_OPEN_GET_NEW_TABLE
If in locked tables mode, ignore the locked tables and get a new instance of the table.
Definition: sql_base.h:132
#define MYSQL_OPEN_IGNORE_FLUSH
Definition: sql_base.h:119
#define MYSQL_LOCK_IGNORE_TIMEOUT
When opening or locking the table, use the maximum timeout (LONG_TIMEOUT = 1 year) rather than the us...
Definition: sql_base.h:147
#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK
Definition: sql_base.h:118

Please refer to the internals manual.

◆ MYSQL_OPEN_SECONDARY_ENGINE

#define MYSQL_OPEN_SECONDARY_ENGINE   0x10000

Open a shadow copy of a table from a secondary storage engine.

◆ MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK

#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK   0x1000

When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to be open do not acquire global, tablespace-scope and schema-scope IX locks.

◆ READ_ALL

#define READ_ALL   1 /* openfrm: Read all parameters */

◆ SKIP_NEW_HANDLER

#define SKIP_NEW_HANDLER   32768

If set, open_table_from_share() will skip calling get_new_handler() to create a new handler object for the table.

Designed to be used when opening a table from inside storage engines.

◆ TEMP_PREFIX

#define TEMP_PREFIX   "MY"

Typedef Documentation

◆ Ref_item_array

Enumeration Type Documentation

◆ enum_tdc_remove_table_type

Enumerator
TDC_RT_REMOVE_ALL 
TDC_RT_REMOVE_NOT_OWN 
TDC_RT_REMOVE_UNUSED 
TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE 

◆ find_item_error_report_type

Enumerator
REPORT_ALL_ERRORS 
REPORT_EXCEPT_NOT_FOUND 
IGNORE_ERRORS 
REPORT_EXCEPT_NON_UNIQUE 
IGNORE_EXCEPT_NON_UNIQUE 

Function Documentation

◆ open_and_lock_tables()

bool open_and_lock_tables ( THD thd,
TABLE_LIST tables,
uint  flags 
)
inline

◆ open_n_lock_single_table()

TABLE* open_n_lock_single_table ( THD thd,
TABLE_LIST table_l,
thr_lock_type  lock_type,
uint  flags 
)
inline

◆ open_tables()

bool open_tables ( THD thd,
TABLE_LIST **  tables,
uint counter,
uint  flags 
)
inline