MySQL 8.3.0
Source Code Documentation
sql_table.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "my_inttypes.h"
#include "my_sharedlib.h"
#include "mysql/components/services/bits/mysql_mutex_bits.h"
#include "mysqld_error.h"
#include "sql/dd/string_type.h"
#include "sql/handler.h"
#include "sql/mdl.h"

Go to the source code of this file.

Classes

class  Foreign_key_parents_invalidator
 Helper class for keeping track for which tables we need to invalidate data-dictionary cache entries and performing such invalidation. More...
 
class  Table_ddl_hton_notification_guard
 Auxiliary class implementing RAII principle for getting permission for/ notification about finished DDL statements from interested storage engines. More...
 

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 

Typedefs

typedef mysql_mutex_t mysql_mutex_t
 

Enumerations

enum  enum_explain_filename_mode { EXPLAIN_ALL_VERBOSE = 0 , EXPLAIN_PARTITIONS_VERBOSE , EXPLAIN_PARTITIONS_AS_COMMENT }
 

Functions

handlertonget_viable_handlerton_for_create (THD *thd, const char *table_name, const HA_CREATE_INFO &ci)
 Checks if the handlerton for the specified ENGINE is enabled AND NOT explicitly disabled (listed in the disabled_storages_engines system variable). More...
 
size_t filename_to_tablename (const char *from, char *to, size_t to_length, bool stay_quiet=false, bool *has_errors=nullptr)
 
size_t tablename_to_filename (const char *from, char *to, size_t to_length)
 
size_t build_table_filename (char *buff, size_t bufflen, const char *db, const char *table, const char *ext, uint flags, bool *was_truncated)
 
size_t build_table_filename (char *buff, size_t bufflen, const char *db, const char *table, const char *ext, uint flags)
 
size_t build_tmptable_filename (THD *thd, char *buff, size_t bufflen)
 Create path to a temporary table, like mysql_tmpdir/#sql1234_12_1 (i.e. More...
 
bool mysql_create_table (THD *thd, Table_ref *create_table, HA_CREATE_INFO *create_info, Alter_info *alter_info)
 Implementation of SQLCOM_CREATE_TABLE. More...
 
bool mysql_create_table_no_lock (THD *thd, const char *db, const char *table_name, HA_CREATE_INFO *create_info, Alter_info *alter_info, uint select_field_count, bool find_parent_keys, bool *is_trans, handlerton **post_ddl_ht)
 Simple wrapper around create_table_impl() to be used in various version of CREATE TABLE statement. More...
 
bool mysql_discard_or_import_tablespace (THD *thd, Table_ref *table_list)
 
bool adjust_fk_parents (THD *thd, const char *db, const char *name, bool reload_self, const Foreign_key_parents_invalidator *fk_invalidator)
 
bool adjust_fk_children_after_parent_def_change (THD *thd, bool check_charsets, const char *parent_table_db, const char *parent_table_name, handlerton *hton, const dd::Table *parent_table_def, Alter_info *parent_alter_info, bool invalidate_tdc)
 Check if new definition of parent table is compatible with foreign keys which reference it. More...
 
bool adjust_fk_children_after_parent_def_change (THD *thd, const char *parent_table_db, const char *parent_table_name, handlerton *hton, const dd::Table *parent_table_def, Alter_info *parent_alter_info)
 Check if new definition of parent table is compatible with foreign keys which reference it. More...
 
bool collect_fk_children (THD *thd, const char *schema, const char *table_name, handlerton *hton, enum_mdl_type lock_type, MDL_request_list *mdl_requests)
 Add MDL requests for specified lock type on all tables referencing the given schema qualified table name to the list. More...
 
bool collect_fk_parents_for_new_fks (THD *thd, const char *db_name, const char *table_name, const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton, MDL_request_list *mdl_requests, Foreign_key_parents_invalidator *fk_invalidator)
 Add MDL requests for lock of specified type on tables referenced by the foreign keys to be added by the CREATE TABLE or ALTER TABLE operation. More...
 
bool collect_fk_names_for_new_fks (THD *thd, const char *db_name, const char *table_name, const Alter_info *alter_info, handlerton *hton, uint fk_max_generated_name_number, MDL_request_list *mdl_requests)
 Add MDL requests for exclusive metadata locks on names of foreign keys to be added by the CREATE TABLE or ALTER TABLE operation. More...
 
bool collect_and_lock_fk_tables_for_rename_table (THD *thd, const char *db, const char *table_name, const dd::Table *table_def, const char *new_db, const char *new_table_name, handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator)
 Acquire exclusive metadata locks on tables which definitions need to be updated or invalidated since they are related through foreign keys to the table to be renamed, Also add the referenced table names for the FKs on this table to the foreign key invalidator, to be used at a later stage to invalidate the dd::Table objects. More...
 
bool adjust_adopted_self_ref_fk_for_simple_rename_table (THD *thd, const char *db, const char *table_name, const char *new_db, const char *new_table_name, handlerton *hton)
 As a result of simple rename table operation, orphan non-self-referencing foreign keys may become non-orphan/adopted self-referencing foreign keys. More...
 
bool adjust_fks_for_rename_table (THD *thd, const char *db, const char *table_name, const char *new_db, const char *new_table_name, handlerton *hton)
 Update referenced table names and the unique constraint name for FKs affected by RENAME TABLE operation. More...
 
bool prepare_fk_parent_key (handlerton *hton, const dd::Table *parent_table_def, const dd::Table *old_parent_table_def, const dd::Table *old_child_table_def, bool is_self_referencing_fk, dd::Foreign_key *fk)
 
bool prepare_fields_and_keys (THD *thd, const dd::Table *src_table, TABLE *table, HA_CREATE_INFO *create_info, Alter_info *alter_info, Alter_table_ctx *alter_ctx, const uint &used_fields)
 Prepare Create_field and Key_spec objects for ALTER and upgrade. More...
 
bool mysql_prepare_alter_table (THD *thd, const dd::Table *src_table, TABLE *table, HA_CREATE_INFO *create_info, Alter_info *alter_info, Alter_table_ctx *alter_ctx)
 Prepare column and key definitions for CREATE TABLE in ALTER TABLE. More...
 
bool mysql_trans_prepare_alter_copy_data (THD *thd)
 Prepare the transaction for the alter table's copy phase. More...
 
bool mysql_trans_commit_alter_copy_data (THD *thd)
 Commit the copy phase of the alter table. More...
 
bool mysql_alter_table (THD *thd, const char *new_db, const char *new_name, HA_CREATE_INFO *create_info, Table_ref *table_list, Alter_info *alter_info)
 Alter table. More...
 
bool mysql_compare_tables (THD *thd, TABLE *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, bool *metadata_equal)
 Compare two tables to see if their metadata are compatible. More...
 
bool mysql_recreate_table (THD *thd, Table_ref *table_list, bool table_copy)
 
bool mysql_create_like_table (THD *thd, Table_ref *table, Table_ref *src_table, HA_CREATE_INFO *create_info)
 
bool mysql_rename_table (THD *thd, handlerton *base, const char *old_db, const char *old_name, const char *old_fk_db, const char *old_fk_name, const dd::Schema &new_schema, const char *new_db, const char *new_name, uint flags)
 Rename a table. More...
 
bool mysql_checksum_table (THD *thd, Table_ref *table_list, HA_CHECK_OPT *check_opt)
 
bool mysql_rm_table (THD *thd, Table_ref *tables, bool if_exists, bool drop_temporary)
 
bool mysql_rm_table_no_locks (THD *thd, Table_ref *tables, bool if_exists, bool drop_temporary, bool drop_database, bool *dropped_non_atomic_flag, std::set< handlerton * > *post_ddl_htons, Foreign_key_parents_invalidator *fk_invalidator, std::vector< MDL_ticket * > *safe_to_release_mdl)
 Execute the drop of a normal or temporary table. More...
 
bool rm_table_do_discovery_and_lock_fk_tables (THD *thd, Table_ref *tables)
 Discover missing tables in SE and acquire locks on tables which participate in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions will have to be updated or invalidated during this operation. More...
 
bool quick_rm_table (THD *thd, handlerton *base, const char *db, const char *table_name, uint flags)
 Quickly remove a table. More...
 
bool prepare_sp_create_field (THD *thd, Create_field *field_def)
 Prepare an instance of Create_field for field creation (fill all necessary attributes). More...
 
bool prepare_pack_create_field (THD *thd, Create_field *sql_field, longlong table_flags)
 Prepare a create_table instance for packing. More...
 
const CHARSET_INFOget_sql_field_charset (const Create_field *sql_field, const HA_CREATE_INFO *create_info)
 Get the character set from field object generated by the parser, using default values when not set. More...
 
bool validate_comment_length (THD *thd, const char *comment_str, size_t *comment_len, uint max_len, uint err_code, const char *comment_name)
 check comment length of table, column, index and partition More...
 
int write_bin_log (THD *thd, bool clear_error, const char *query, size_t query_length, bool is_trans=false)
 
void promote_first_timestamp_column (List< Create_field > *column_definitions)
 Modifies the first column definition whose SQL type is TIMESTAMP by adding the features DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. More...
 
bool prepare_create_field (THD *thd, const char *error_schema_name, const char *error_table_name, HA_CREATE_INFO *create_info, List< Create_field > *create_list, int *select_field_pos, handler *file, Create_field *sql_field, int field_no)
 Prepares the column definitions for table creation. More...
 
bool mysql_prepare_create_table (THD *thd, const char *error_schema_name, const char *error_table_name, HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file, bool is_partitioned, KEY **key_info_buffer, uint *key_count, FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count, FOREIGN_KEY *existing_fks, uint existing_fks_count, const dd::Table *existing_fks_table, uint fk_max_generated_name_number, int select_field_count, bool find_parent_keys)
 Prepares the table and key structures for table creation. More...
 
size_t explain_filename (THD *thd, const char *from, char *to, size_t to_length, enum_explain_filename_mode explain_mode)
 Explain a path name by split it to database, table etc. More...
 
bool lock_trigger_names (THD *thd, Table_ref *tables)
 Acquire metadata lock on triggers associated with a list of tables. More...
 
TYPELIBcreate_typelib (MEM_ROOT *mem_root, Create_field *field_def)
 
bool lock_check_constraint_names (THD *thd, Table_ref *tables)
 Method to collect check constraint names for the all the tables and acquire MDL lock on them. More...
 
bool lock_check_constraint_names_for_rename (THD *thd, const char *db, const char *table_name, const dd::Table *table_def, const char *target_db, const char *target_table_name)
 Method to lock check constraint names for rename table operation. More...
 
bool prepare_check_constraints_for_create (THD *thd, const char *db_name, const char *table_name, Alter_info *alter_info)
 Method to prepare check constraints for the CREATE operation. More...
 

Variables

static const uint FN_FROM_IS_TMP = 1 << 0
 
static const uint FN_TO_IS_TMP = 1 << 1
 
static const uint FN_IS_TMP = FN_FROM_IS_TMP | FN_TO_IS_TMP
 
static const uint NO_FK_CHECKS = 1 << 2
 Don't check foreign key constraints while renaming table. More...
 
static const uint NO_DD_COMMIT = 1 << 3
 Don't commit transaction after updating data-dictionary while renaming the table. More...
 
static const uint NO_FK_RENAME = 1 << 4
 Don't change generated foreign key names while renaming table. More...
 
static const uint NO_CC_RENAME = 1 << 5
 Don't change generated check constraint names while renaming table. More...
 
MYSQL_PLUGIN_IMPORT const char * primary_key_name
 

Typedef Documentation

◆ mysql_mutex_t

Enumeration Type Documentation

◆ enum_explain_filename_mode

Enumerator
EXPLAIN_ALL_VERBOSE 
EXPLAIN_PARTITIONS_VERBOSE 
EXPLAIN_PARTITIONS_AS_COMMENT 

Function Documentation

◆ adjust_adopted_self_ref_fk_for_simple_rename_table()

bool adjust_adopted_self_ref_fk_for_simple_rename_table ( THD thd,
const char *  db,
const char *  table_name,
const char *  new_db,
const char *  new_table_name,
handlerton hton 
)

As a result of simple rename table operation, orphan non-self-referencing foreign keys may become non-orphan/adopted self-referencing foreign keys.

For such transformed foreign key, check that table has compatible referenced column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.

Parameters
thdThread handle.
dbTable's old schema.
table_nameTable's old name.
new_dbTable's new schema.
new_table_nameTable's new name.
htonTable's SE.
Return values
operationoutcome, false if no error.

◆ adjust_fk_children_after_parent_def_change() [1/2]

bool adjust_fk_children_after_parent_def_change ( THD thd,
bool  check_charsets,
const char *  parent_table_db,
const char *  parent_table_name,
handlerton hton,
const dd::Table parent_table_def,
Alter_info parent_alter_info,
bool  invalidate_tdc 
)

Check if new definition of parent table is compatible with foreign keys which reference it.

Update the unique constraint names and referenced column names for the foreign keys accordingly.

Parameters
thdThread handle.
check_charsetsIndicates whether we need to check charsets of columns participating in foreign keys.
parent_table_dbParent table schema name.
parent_table_nameParent table name.
htonHandlerton for table's storage engine.
parent_table_defTable object representing the referenced table.
parent_alter_infoAlter_info containing information about renames of parent columns. Can be nullptr if there are no such renames.
invalidate_tdcIndicates whether we need to invalidate TDC for referencing tables after updating their definitions.
Return values
operationoutcome, false if no error.

◆ adjust_fk_children_after_parent_def_change() [2/2]

bool adjust_fk_children_after_parent_def_change ( THD thd,
const char *  parent_table_db,
const char *  parent_table_name,
handlerton hton,
const dd::Table parent_table_def,
Alter_info parent_alter_info 
)
inline

Check if new definition of parent table is compatible with foreign keys which reference it.

Update the unique constraint names and referenced column names for the foreign keys accordingly. Do mandatory character set checks and TDC invalidation.

◆ adjust_fk_parents()

bool adjust_fk_parents ( THD thd,
const char *  db,
const char *  name,
bool  reload_self,
const Foreign_key_parents_invalidator fk_invalidator 
)

◆ adjust_fks_for_rename_table()

bool adjust_fks_for_rename_table ( THD thd,
const char *  db,
const char *  table_name,
const char *  new_db,
const char *  new_table_name,
handlerton hton 
)

Update referenced table names and the unique constraint name for FKs affected by RENAME TABLE operation.

Parameters
thdThread handle.
dbTable's old schema.
table_nameTable's old name.
new_dbTable's new schema.
new_table_nameTable's new name.
htonTable's SE.
Return values
operationoutcome, false if no error.

◆ build_table_filename() [1/2]

size_t build_table_filename ( char *  buff,
size_t  bufflen,
const char *  db,
const char *  table,
const char *  ext,
uint  flags 
)
inline

◆ build_table_filename() [2/2]

size_t build_table_filename ( char *  buff,
size_t  bufflen,
const char *  db,
const char *  table,
const char *  ext,
uint  flags,
bool *  was_truncated 
)

Mark OUT param if path gets truncated. Most of functions which invoke this function are sure that the path will not be truncated. In case some functions are not sure, we can use 'was_truncated' OUTPARAM

◆ build_tmptable_filename()

size_t build_tmptable_filename ( THD thd,
char *  buff,
size_t  bufflen 
)

Create path to a temporary table, like mysql_tmpdir/#sql1234_12_1 (i.e.

to its .FRM file but without an extension).

Parameters
thdThe thread handle.
buffWhere to write result in my_charset_filename.
bufflenbuff size
Note
Uses current_pid, thread_id, and tmp_table counter to create a file name in mysql_tmpdir.
Returns
Path length.

◆ collect_and_lock_fk_tables_for_rename_table()

bool collect_and_lock_fk_tables_for_rename_table ( THD thd,
const char *  db,
const char *  table_name,
const dd::Table table_def,
const char *  new_db,
const char *  new_table_name,
handlerton hton,
Foreign_key_parents_invalidator fk_invalidator 
)

Acquire exclusive metadata locks on tables which definitions need to be updated or invalidated since they are related through foreign keys to the table to be renamed, Also add the referenced table names for the FKs on this table to the foreign key invalidator, to be used at a later stage to invalidate the dd::Table objects.

Parameters
thdThread handle.
dbTable's old schema.
table_nameTable's old name.
table_defTable definition of table being RENAMEd.
new_dbTable's new schema.
new_table_nameTable's new name.
htonTable's SE.
[in,out]fk_invalidatorObject keeping track of which dd::Table objects to invalidate.
Return values
operationoutcome, false if no error.

◆ collect_fk_children()

bool collect_fk_children ( THD thd,
const char *  schema,
const char *  table_name,
handlerton hton,
enum_mdl_type  lock_type,
MDL_request_list mdl_requests 
)

Add MDL requests for specified lock type on all tables referencing the given schema qualified table name to the list.

Parameters
thdThread handle.
schemaSchema name.
table_nameTable name.
htonHandlerton for table's storage engine.
lock_typeType of MDL requests to add.
[in,out]mdl_requestsList to which MDL requests are to be added.
Return values
operationoutcome, false if no error.

◆ collect_fk_names_for_new_fks()

bool collect_fk_names_for_new_fks ( THD thd,
const char *  db_name,
const char *  table_name,
const Alter_info alter_info,
handlerton hton,
uint  fk_max_generated_name_number,
MDL_request_list mdl_requests 
)

Add MDL requests for exclusive metadata locks on names of foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.

Parameters
thdThread context.
db_nameTable's database name.
table_nameTable name.
alter_infoAlter_info object with the list of FKs to be added.
htonTable's storage engine.
fk_max_generated_name_numberMax value of number component among existing generated foreign key names.
[in,out]mdl_requestsList to which MDL requests are to be added.
Return values
operationoutcome, false if no error.

◆ collect_fk_parents_for_new_fks()

bool collect_fk_parents_for_new_fks ( THD thd,
const char *  db_name,
const char *  table_name,
const Alter_info alter_info,
enum_mdl_type  lock_type,
handlerton hton,
MDL_request_list mdl_requests,
Foreign_key_parents_invalidator fk_invalidator 
)

Add MDL requests for lock of specified type on tables referenced by the foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.

Also add the referenced table names to the foreign key invalidator, to be used at a later stage to invalidate the dd::Table objects.

Parameters
thdThread handle.
db_nameTable's database name.
table_nameTable name.
alter_infoAlter_info object with the list of FKs to be added.
lock_typeType of metadata lock to be requested.
htonHandlerton for table's storage engine.
[in,out]mdl_requestsList to which MDL requests are to be added.
[in,out]fk_invalidatorObject keeping track of which dd::Table objects to invalidate.
Return values
operationoutcome, false if no error.

◆ create_typelib()

TYPELIB * create_typelib ( MEM_ROOT mem_root,
Create_field field_def 
)

◆ explain_filename()

size_t explain_filename ( THD thd,
const char *  from,
char *  to,
size_t  to_length,
enum_explain_filename_mode  explain_mode 
)

Explain a path name by split it to database, table etc.

Break down the path name to its logic parts (database, table, partition, subpartition). filename_to_tablename cannot be used on partitions, due to the #P# part. There can be up to 6 '#', #P# for partition, #SP# for subpartition and #TMP# or #REN# for temporary or renamed partitions. This should be used when something should be presented to a user in a diagnostic, error etc. when it would be useful to know what a particular file [and directory] means. Such as SHOW ENGINE STATUS, error messages etc.

Parameters
thdThread handle
fromPath name in my_charset_filename Null terminated in my_charset_filename, normalized to use '/' as directory separation character.
toExplained name in system_charset_info
to_lengthSize of to buffer
explain_modeRequested output format. EXPLAIN_ALL_VERBOSE -> [Database db, ]Table tbl[,[ Temporary| Renamed] Partition p [, Subpartition sp]] EXPLAIN_PARTITIONS_VERBOSE -> db.tbl [[ Temporary| Renamed] Partition p [, Subpartition sp]] EXPLAIN_PARTITIONS_AS_COMMENT -> db.tbl |* [,[ Temporary| Renamed] Partition p [, Subpartition sp]] *| (| is really a /, and it is all in one line)
Return values
Lengthof returned string

◆ filename_to_tablename()

size_t filename_to_tablename ( const char *  from,
char *  to,
size_t  to_length,
bool  stay_quiet = false,
bool *  has_errors = nullptr 
)

◆ get_sql_field_charset()

const CHARSET_INFO * get_sql_field_charset ( const Create_field sql_field,
const HA_CREATE_INFO create_info 
)

Get the character set from field object generated by the parser, using default values when not set.

Parameters
sql_fieldThe sql_field object
create_infoInfo generated by parser
Returns
character set

◆ get_viable_handlerton_for_create()

handlerton * get_viable_handlerton_for_create ( THD thd,
const char *  table_name,
const HA_CREATE_INFO ci 
)

Checks if the handlerton for the specified ENGINE is enabled AND NOT explicitly disabled (listed in the disabled_storages_engines system variable).

In the case of temporary tables the handlerton must also support those to be viable.

When returning a handlerton different from the one specified ER_DISABLED_STORAGE_ENGINE and ER_USING_OTHER_HANDLER are emitted as warnings.

Parameters
thdThread handler.
table_nameTable name.
cicreate_info struct from parser.
Return values
Handlertonfor specified ENGINE if this is viable.
Thedefault (tmp) handlerton if viable and engine substitution is allowed.
nullptrif error (specified ENGINE not viable and substitution not permitted).

◆ lock_check_constraint_names()

bool lock_check_constraint_names ( THD thd,
Table_ref tables 
)

Method to collect check constraint names for the all the tables and acquire MDL lock on them.

Parameters
[in]thdThread handle.
[in]tablesCheck constraints of tables to be locked.
Return values
falseSuccess.
trueFailure.

◆ lock_check_constraint_names_for_rename()

bool lock_check_constraint_names_for_rename ( THD thd,
const char *  db,
const char *  table_name,
const dd::Table table_def,
const char *  target_db,
const char *  target_table_name 
)

Method to lock check constraint names for rename table operation.

Method acquire locks on the constraint names of source table and also on the name of check constraint in the target table.

Parameters
[in]thdThread handle.
[in]dbDatabase name.
[in]table_nameTable name.
[in]table_defDD table object of source table.
[in]target_dbTarget database name.
[in]target_table_nameTarget table name.
Return values
falseSuccess.
trueFailure.

◆ lock_trigger_names()

bool lock_trigger_names ( THD thd,
Table_ref tables 
)

Acquire metadata lock on triggers associated with a list of tables.

Parameters
[in]thdCurrent thread context
[in]tablesTables for that associated triggers have to locked.
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ mysql_alter_table()

bool mysql_alter_table ( THD thd,
const char *  new_db,
const char *  new_name,
HA_CREATE_INFO create_info,
Table_ref table_list,
Alter_info alter_info 
)

Alter table.

Parameters
thdThread handle
new_dbIf there is a RENAME clause
new_nameIf there is a RENAME clause
create_infoInformation from the parsing phase about new table properties.
table_listThe table to change.
alter_infoLists of fields, keys to be changed, added or dropped.
Return values
trueError
falseSuccess

This is a veery long function and is everything but the kitchen sink :) It is used to alter a table and not only by ALTER TABLE but also CREATE|DROP INDEX are mapped on this function.

When the ALTER TABLE statement just does a RENAME or ENABLE|DISABLE KEYS, or both, then this function short cuts its operation by renaming the table and/or enabling/disabling the keys. In this case, the FRM is not changed, directly by mysql_alter_table. However, if there is a RENAME + change of a field, or an index, the short cut is not used. See how create_list is used to generate the new FRM regarding the structure of the fields. The same is done for the indices of the table.

Altering a table can be done in two ways. The table can be modified directly using an in-place algorithm, or the changes can be done using an intermediate temporary table (copy). In-place is the preferred algorithm as it avoids copying table data. The storage engine selects which algorithm to use in check_if_supported_inplace_alter() based on information about the table changes from fill_alter_inplace_info().

◆ mysql_checksum_table()

bool mysql_checksum_table ( THD thd,
Table_ref table_list,
HA_CHECK_OPT check_opt 
)

◆ mysql_compare_tables()

bool mysql_compare_tables ( THD thd,
TABLE table,
Alter_info alter_info,
HA_CREATE_INFO create_info,
bool *  metadata_equal 
)

Compare two tables to see if their metadata are compatible.

One table specified by a TABLE instance, the other using Alter_info and HA_CREATE_INFO.

Parameters
thdThread handler
[in]tableThe first table.
[in]alter_infoAlter options, fields and keys for the second table.
[in]create_infoCreate options for the second table.
[out]metadata_equalResult of comparison.
Return values
trueerror
falsesuccess

◆ mysql_create_like_table()

bool mysql_create_like_table ( THD thd,
Table_ref table,
Table_ref src_table,
HA_CREATE_INFO create_info 
)

◆ mysql_create_table()

bool mysql_create_table ( THD thd,
Table_ref create_table,
HA_CREATE_INFO create_info,
Alter_info alter_info 
)

Implementation of SQLCOM_CREATE_TABLE.

Take the metadata locks (including a shared lock on the affected schema) and create the table. Is written to be called from mysql_execute_command(), to which it delegates the common parts with other commands (i.e. implicit commit before and after, close of thread tables.

◆ mysql_create_table_no_lock()

bool mysql_create_table_no_lock ( THD thd,
const char *  db,
const char *  table_name,
HA_CREATE_INFO create_info,
Alter_info alter_info,
uint  select_field_count,
bool  find_parent_keys,
bool *  is_trans,
handlerton **  post_ddl_ht 
)

Simple wrapper around create_table_impl() to be used in various version of CREATE TABLE statement.

◆ mysql_discard_or_import_tablespace()

bool mysql_discard_or_import_tablespace ( THD thd,
Table_ref table_list 
)

◆ mysql_prepare_alter_table()

bool mysql_prepare_alter_table ( THD thd,
const dd::Table src_table,
TABLE table,
HA_CREATE_INFO create_info,
Alter_info alter_info,
Alter_table_ctx alter_ctx 
)

Prepare column and key definitions for CREATE TABLE in ALTER TABLE.

This function transforms parse output of ALTER TABLE - lists of columns and keys to add, drop or modify into, essentially, CREATE TABLE definition - a list of columns and keys of the new table. While doing so, it also performs some (bug not all) semantic checks.

This function is invoked when we know that we're going to perform ALTER TABLE via a temporary table – i.e. in-place ALTER TABLE is not possible, perhaps because the ALTER statement contains instructions that require change in table data, not only in table definition or indexes.

Parameters
[in,out]thdthread handle. Used as a memory pool and source of environment information.
[in]src_tableDD table object for the table to be created/altered. Will be nullptr for temporary tables.
[in]tablethe source table, open and locked Used as an interface to the storage engine to acquire additional information about the original table.
[in,out]create_infoA blob with CREATE/ALTER TABLE parameters
[in,out]alter_infoAnother blob with ALTER/CREATE parameters. Originally create_info was used only in CREATE TABLE and alter_info only in ALTER TABLE. But since ALTER might end-up doing CREATE, this distinction is gone and we just carry around two structures.
[in,out]alter_ctxRuntime context for ALTER TABLE.
Returns
Fills various create_info members based on information retrieved from the storage engine. Sets create_info->varchar if the table has a VARCHAR column. Prepares alter_info->create_list and alter_info->key_list with columns and keys of the new table.
Return values
trueerror, out of memory or a semantical error in ALTER TABLE instructions
falsesuccess

◆ mysql_prepare_create_table()

bool mysql_prepare_create_table ( THD thd,
const char *  error_schema_name,
const char *  error_table_name,
HA_CREATE_INFO create_info,
Alter_info alter_info,
handler file,
bool  is_partitioned,
KEY **  key_info_buffer,
uint *  key_count,
FOREIGN_KEY **  fk_key_info_buffer,
uint *  fk_key_count,
FOREIGN_KEY existing_fks,
uint  existing_fks_count,
const dd::Table existing_fks_table,
uint  fk_max_generated_name_number,
int  select_field_count,
bool  find_parent_keys 
)

Prepares the table and key structures for table creation.

Parameters
thdThread object.
error_schema_nameSchema name of the table to create/alter, only error reporting.
error_table_nameName of table to create/alter, only used for error reporting.
create_infoCreate information (like MAX_ROWS).
alter_infoList of columns and indexes to create
fileThe handler for the new table.
is_partitionedIndicates whether table is partitioned.
[out]key_info_bufferAn array of KEY structs for the indexes.
[out]key_countThe number of elements in the array.
[out]fk_key_info_bufferAn array of FOREIGN_KEY structs for the foreign keys.
[out]fk_key_countThe number of elements in the array.
[in]existing_fksAn array of pre-existing FOREIGN KEYS (in case of ALTER).
[in]existing_fks_countThe number of pre-existing foreign keys.
[in]existing_fks_tabledd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting.
[in]fk_max_generated_name_numberMax value of number component among existing generated foreign key names.
select_field_countThe number of fields coming from a select table.
find_parent_keysIndicates whether we need to lookup name of unique constraint in parent table for foreign keys.
Return values
falseOK
trueerror

◆ mysql_recreate_table()

bool mysql_recreate_table ( THD thd,
Table_ref table_list,
bool  table_copy 
)

◆ mysql_rename_table()

bool mysql_rename_table ( THD thd,
handlerton base,
const char *  old_db,
const char *  old_name,
const char *  old_fk_db,
const char *  old_fk_name,
const dd::Schema new_schema,
const char *  new_db,
const char *  new_name,
uint  flags 
)

Rename a table.

Parameters
thdThread handle
baseThe handlerton handle.
old_dbThe old database name.
old_nameThe old table name.
old_fk_dbThe old table db to be used for identifying self-referencing FKs which need to be updated.
old_fk_nameThe old table name to be used for identifying generated FK names and self-referencing FKs which need to be updated.
new_schemaDD object for the new schema.
new_dbThe new database name.
new_nameThe new table name.
flagsflags FN_FROM_IS_TMP old_name is temporary. FN_TO_IS_TMP new_name is temporary. NO_FK_CHECKS Don't check FK constraints during rename. NO_DD_COMMIT Don't commit transaction after updating data-dictionary. NO_FK_RENAME Don't change generated foreign key names during rename. NO_CC_RENAME Don't change generated check constraint names during rename.
Note
Use of NO_DD_COMMIT flag only allowed for SEs supporting atomic DDL.
In case when NO_DD_COMMIT flag was used, the caller must rollback both statement and transaction on failure. This is necessary to revert results of handler::ha_rename_table() call in case when update to the data-dictionary which follows it fails. Also this must be done before any further accesses to DD.
Returns
false OK
true Error

◆ mysql_rm_table()

bool mysql_rm_table ( THD thd,
Table_ref tables,
bool  if_exists,
bool  drop_temporary 
)

◆ mysql_rm_table_no_locks()

bool mysql_rm_table_no_locks ( THD thd,
Table_ref tables,
bool  if_exists,
bool  drop_temporary,
bool  drop_database,
bool *  dropped_non_atomic_flag,
std::set< handlerton * > *  post_ddl_htons,
Foreign_key_parents_invalidator fk_invalidator,
std::vector< MDL_ticket * > *  safe_to_release_mdl 
)

Execute the drop of a normal or temporary table.

Parameters
thdThread handler
tablesTables to drop
if_existsIf set, don't give an error if table doesn't exists. In this case we give an warning of level 'NOTE'
drop_temporaryOnly drop temporary tables
drop_databaseThis is DROP DATABASE statement. Drop views and handle binary logging in a special way.
[out]dropped_non_atomic_flagIndicates whether we have dropped some tables in SEs which don't support atomic DDL.
[out]post_ddl_htonsSet of handlertons for tables in SEs supporting atomic DDL for which post-DDL hook needs to be called after statement commit or rollback.
[out]fk_invalidatorSet of parent tables which participate in FKs together with tables dropped and which entries in DD cache need to be invalidated as result of DROP operation.
[out]safe_to_release_mdlUnder LOCK TABLES set of metadata locks on tables dropped which is safe to release after DROP operation.
Return values
False- ok
True- error
Note
This function assumes that metadata locks have already been taken. It is also assumed that the tables have been removed from TDC.
This function assumes that temporary tables to be dropped have been pre-opened using corresponding table list elements.

◆ mysql_trans_commit_alter_copy_data()

bool mysql_trans_commit_alter_copy_data ( THD thd)

Commit the copy phase of the alter table.

◆ mysql_trans_prepare_alter_copy_data()

bool mysql_trans_prepare_alter_copy_data ( THD thd)

Prepare the transaction for the alter table's copy phase.

◆ prepare_check_constraints_for_create()

bool prepare_check_constraints_for_create ( THD thd,
const char *  db_name,
const char *  table_name,
Alter_info alter_info 
)

Method to prepare check constraints for the CREATE operation.

If name of the check constraint is not specified then name is generated, check constraint is pre-validated and MDL on check constraint is acquired.

Parameters
thdThread handle.
db_nameDatabase name.
table_nameTable name.
alter_infoAlter_info object with list of check constraints to be created.
Return values
falseSuccess.
trueFailure.

◆ prepare_create_field()

bool prepare_create_field ( THD thd,
const char *  error_schema_name,
const char *  error_table_name,
HA_CREATE_INFO create_info,
List< Create_field > *  create_list,
int *  select_field_pos,
handler file,
Create_field sql_field,
int  field_no 
)

Prepares the column definitions for table creation.

Parameters
thdThread object.
error_schema_nameSchema name of the table used for error reporting.
error_table_nameTable name used for error reporting.
create_infoCreate information.
[in,out]create_listList of columns to create.
[in,out]select_field_posPosition where the SELECT columns start for CREATE TABLE ... SELECT.
fileThe handler for the new table.
[in,out]sql_fieldCreate_field to populate.
field_noColumn number.
Return values
falseOK
trueerror

◆ prepare_fields_and_keys()

bool prepare_fields_and_keys ( THD thd,
const dd::Table src_table,
TABLE table,
HA_CREATE_INFO create_info,
Alter_info alter_info,
Alter_table_ctx alter_ctx,
const uint &  used_fields 
)

Prepare Create_field and Key_spec objects for ALTER and upgrade.

Parameters
[in,out]thdthread handle. Used as a memory pool and source of environment information.
[in]src_tableDD table object. Will be nullptr for temporary tables and during upgrade.
[in]tablethe source table, open and locked Used as an interface to the storage engine to acquire additional information about the original table.
[in,out]create_infoA blob with CREATE/ALTER TABLE parameters
[in,out]alter_infoAnother blob with ALTER/CREATE parameters. Originally create_info was used only in CREATE TABLE and alter_info only in ALTER TABLE. But since ALTER might end-up doing CREATE, this distinction is gone and we just carry around two structures.
[in,out]alter_ctxRuntime context for ALTER TABLE.
[in]used_fieldsused_fields from HA_CREATE_INFO.
Return values
trueerror, out of memory or a semantical error in ALTER TABLE instructions
falsesuccess

◆ prepare_fk_parent_key()

bool prepare_fk_parent_key ( handlerton hton,
const dd::Table parent_table_def,
const dd::Table old_parent_table_def,
const dd::Table old_child_table_def,
bool  is_self_referencing_fk,
dd::Foreign_key fk 
)

◆ prepare_pack_create_field()

bool prepare_pack_create_field ( THD thd,
Create_field sql_field,
longlong  table_flags 
)

Prepare a create_table instance for packing.

Parameters
thdThread handle
[in,out]sql_fieldfield to prepare for packing
table_flagstable flags
Returns
true if error, false if ok

◆ prepare_sp_create_field()

bool prepare_sp_create_field ( THD thd,
Create_field field_def 
)

Prepare an instance of Create_field for field creation (fill all necessary attributes).

Only used for stored programs.

Parameters
[in]thdThread handle
[out]field_defAn instance of initialized create_field
Returns
Error status.

◆ promote_first_timestamp_column()

void promote_first_timestamp_column ( List< Create_field > *  column_definitions)

Modifies the first column definition whose SQL type is TIMESTAMP by adding the features DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.

Parameters
column_definitionsThe list of column definitions, in the physical order in which they appear in the table.

◆ quick_rm_table()

bool quick_rm_table ( THD thd,
handlerton base,
const char *  db,
const char *  table_name,
uint  flags 
)

Quickly remove a table.

Parameters
thdThread context.
baseThe handlerton handle.
dbThe database name.
table_nameThe table name.
flagsFlags for build_table_filename().
Note
In case when NO_DD_COMMIT flag was used, the caller must rollback both statement and transaction on failure. This is necessary to revert results of handler::ha_delete_table() call in case when update to the data-dictionary which follows it fails. Also this must be done before any further accesses to DD.
See also
dd::drop_table().
Returns
False in case of success, True otherwise.

◆ rm_table_do_discovery_and_lock_fk_tables()

bool rm_table_do_discovery_and_lock_fk_tables ( THD thd,
Table_ref tables 
)

Discover missing tables in SE and acquire locks on tables which participate in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions will have to be updated or invalidated during this operation.

Parameters
thdThread context.
tablesTables to be dropped by DROP TABLES/DATABASE.
Return values
False- Success.
True- Failure.

◆ tablename_to_filename()

size_t tablename_to_filename ( const char *  from,
char *  to,
size_t  to_length 
)

◆ validate_comment_length()

bool validate_comment_length ( THD thd,
const char *  comment_str,
size_t *  comment_len,
uint  max_len,
uint  err_code,
const char *  comment_name 
)

check comment length of table, column, index and partition

If comment length is more than the standard length truncate it and store the comment length up to the standard comment length size

Parameters
thdThread handle
comment_strComment string
[in,out]comment_lenComment length
max_lenMaximum allowed comment length
err_codeError message
comment_nameType of comment
Returns
Operation status
Return values
trueError found
falseOn success

◆ write_bin_log()

int write_bin_log ( THD thd,
bool  clear_error,
const char *  query,
size_t  query_length,
bool  is_trans = false 
)

Variable Documentation

◆ FN_FROM_IS_TMP

const uint FN_FROM_IS_TMP = 1 << 0
static

◆ FN_IS_TMP

const uint FN_IS_TMP = FN_FROM_IS_TMP | FN_TO_IS_TMP
static

◆ FN_TO_IS_TMP

const uint FN_TO_IS_TMP = 1 << 1
static

◆ NO_CC_RENAME

const uint NO_CC_RENAME = 1 << 5
static

Don't change generated check constraint names while renaming table.

◆ NO_DD_COMMIT

const uint NO_DD_COMMIT = 1 << 3
static

Don't commit transaction after updating data-dictionary while renaming the table.

◆ NO_FK_CHECKS

const uint NO_FK_CHECKS = 1 << 2
static

Don't check foreign key constraints while renaming table.

◆ NO_FK_RENAME

const uint NO_FK_RENAME = 1 << 4
static

Don't change generated foreign key names while renaming table.

◆ primary_key_name

MYSQL_PLUGIN_IMPORT const char* primary_key_name
extern