MySQL 8.4.3
Source Code Documentation
|
#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 | |
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). 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 (THD *thd, 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_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. 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... | |
TYPELIB * | create_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 |
std::atomic_ulong | deprecated_use_fk_on_non_standard_key_count |
Count number of times foreign key is created on non standard index keys. More... | |
std::atomic_ullong | deprecated_use_fk_on_non_standard_key_last_timestamp |
Last time fk is created on non standard index key, as usec since epoch. More... | |
typedef mysql_mutex_t mysql_mutex_t |
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.
thd | Thread handle. |
db | Table's old schema. |
table_name | Table's old name. |
new_db | Table's new schema. |
new_table_name | Table's new name. |
hton | Table's SE. |
operation | outcome, false if no error. |
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.
thd | Thread handle. |
check_charsets | Indicates whether we need to check charsets of columns participating in foreign keys. |
parent_table_db | Parent table schema name. |
parent_table_name | Parent table name. |
hton | Handlerton for table's storage engine. |
parent_table_def | Table object representing the referenced table. |
parent_alter_info | Alter_info containing information about renames of parent columns. Can be nullptr if there are no such renames. |
invalidate_tdc | Indicates whether we need to invalidate TDC for referencing tables after updating their definitions. |
operation | outcome, false if no error. |
|
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.
bool adjust_fk_parents | ( | THD * | thd, |
const char * | db, | ||
const char * | name, | ||
bool | reload_self, | ||
const Foreign_key_parents_invalidator * | fk_invalidator | ||
) |
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.
thd | Thread handle. |
db | Table's old schema. |
table_name | Table's old name. |
new_db | Table's new schema. |
new_table_name | Table's new name. |
hton | Table's SE. |
operation | outcome, false if no error. |
|
inline |
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
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).
thd | The thread handle. |
buff | Where to write result in my_charset_filename. |
bufflen | buff size |
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.
thd | Thread handle. | |
db | Table's old schema. | |
table_name | Table's old name. | |
table_def | Table definition of table being RENAMEd. | |
new_db | Table's new schema. | |
new_table_name | Table's new name. | |
hton | Table's SE. | |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
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.
thd | Thread handle. | |
schema | Schema name. | |
table_name | Table name. | |
hton | Handlerton for table's storage engine. | |
lock_type | Type of MDL requests to add. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
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.
thd | Thread context. | |
db_name | Table's database name. | |
table_name | Table name. | |
alter_info | Alter_info object with the list of FKs to be added. | |
hton | Table's storage engine. | |
fk_max_generated_name_number | Max value of number component among existing generated foreign key names. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
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.
thd | Thread handle. | |
db_name | Table's database name. | |
table_name | Table name. | |
alter_info | Alter_info object with the list of FKs to be added. | |
lock_type | Type of metadata lock to be requested. | |
hton | Handlerton for table's storage engine. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
TYPELIB * create_typelib | ( | MEM_ROOT * | mem_root, |
Create_field * | field_def | ||
) |
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.
thd | Thread handle |
from | Path name in my_charset_filename Null terminated in my_charset_filename, normalized to use '/' as directory separation character. |
to | Explained name in system_charset_info |
to_length | Size of to buffer |
explain_mode | Requested 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) |
Length | of returned string |
size_t filename_to_tablename | ( | const char * | from, |
char * | to, | ||
size_t | to_length, | ||
bool | stay_quiet = false , |
||
bool * | has_errors = nullptr |
||
) |
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.
sql_field | The sql_field object |
create_info | Info generated by parser |
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.
thd | Thread handler. |
table_name | Table name. |
ci | create_info struct from parser. |
Handlerton | for specified ENGINE if this is viable. |
The | default (tmp) handlerton if viable and engine substitution is allowed. |
nullptr | if error (specified ENGINE not viable and substitution not permitted). |
Method to collect check constraint names for the all the tables and acquire MDL lock on them.
[in] | thd | Thread handle. |
[in] | tables | Check constraints of tables to be locked. |
false | Success. |
true | Failure. |
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.
[in] | thd | Thread handle. |
[in] | db | Database name. |
[in] | table_name | Table name. |
[in] | table_def | DD table object of source table. |
[in] | target_db | Target database name. |
[in] | target_table_name | Target table name. |
false | Success. |
true | Failure. |
Acquire metadata lock on triggers associated with a list of tables.
[in] | thd | Current thread context |
[in] | tables | Tables for that associated triggers have to locked. |
false | Success |
true | Failure |
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.
thd | Thread handle |
new_db | If there is a RENAME clause |
new_name | If there is a RENAME clause |
create_info | Information from the parsing phase about new table properties. |
table_list | The table to change. |
alter_info | Lists of fields, keys to be changed, added or dropped. |
true | Error |
false | Success |
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().
bool mysql_checksum_table | ( | THD * | thd, |
Table_ref * | table_list, | ||
HA_CHECK_OPT * | check_opt | ||
) |
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.
thd | Thread handler | |
[in] | table | The first table. |
[in] | alter_info | Alter options, fields and keys for the second table. |
[in] | create_info | Create options for the second table. |
[out] | metadata_equal | Result of comparison. |
true | error |
false | success |
bool mysql_create_like_table | ( | THD * | thd, |
Table_ref * | table, | ||
Table_ref * | src_table, | ||
HA_CREATE_INFO * | create_info | ||
) |
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.
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.
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.
[in,out] | thd | thread handle. Used as a memory pool and source of environment information. |
[in] | src_table | DD table object for the table to be created/altered. Will be nullptr for temporary tables. |
[in] | table | the source table, open and locked Used as an interface to the storage engine to acquire additional information about the original table. |
[in,out] | create_info | A blob with CREATE/ALTER TABLE parameters |
[in,out] | alter_info | Another 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_ctx | Runtime context for ALTER TABLE. |
true | error, out of memory or a semantical error in ALTER TABLE instructions |
false | success |
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.
thd | Thread object. | |
error_schema_name | Schema name of the table to create/alter, only error reporting. | |
error_table_name | Name of table to create/alter, only used for error reporting. | |
create_info | Create information (like MAX_ROWS). | |
alter_info | List of columns and indexes to create | |
file | The handler for the new table. | |
is_partitioned | Indicates whether table is partitioned. | |
[out] | key_info_buffer | An array of KEY structs for the indexes. |
[out] | key_count | The number of elements in the array. |
[out] | fk_key_info_buffer | An array of FOREIGN_KEY structs for the foreign keys. |
[out] | fk_key_count | The number of elements in the array. |
[in] | existing_fks | An array of pre-existing FOREIGN KEYS (in case of ALTER). |
[in] | existing_fks_count | The number of pre-existing foreign keys. |
[in] | existing_fks_table | dd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting. |
[in] | fk_max_generated_name_number | Max value of number component among existing generated foreign key names. |
select_field_count | The number of fields coming from a select table. | |
find_parent_keys | Indicates whether we need to lookup name of unique constraint in parent table for foreign keys. |
false | OK |
true | error |
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.
thd | Thread handle |
base | The handlerton handle. |
old_db | The old database name. |
old_name | The old table name. |
old_fk_db | The old table db to be used for identifying self-referencing FKs which need to be updated. |
old_fk_name | The old table name to be used for identifying generated FK names and self-referencing FKs which need to be updated. |
new_schema | DD object for the new schema. |
new_db | The new database name. |
new_name | The new table name. |
flags | flags 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. |
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.
thd | Thread handler | |
tables | Tables to drop | |
if_exists | If set, don't give an error if table doesn't exists. In this case we give an warning of level 'NOTE' | |
drop_temporary | Only drop temporary tables | |
drop_database | This is DROP DATABASE statement. Drop views and handle binary logging in a special way. | |
[out] | dropped_non_atomic_flag | Indicates whether we have dropped some tables in SEs which don't support atomic DDL. |
[out] | post_ddl_htons | Set 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_invalidator | Set 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_mdl | Under LOCK TABLES set of metadata locks on tables dropped which is safe to release after DROP operation. |
False | - ok |
True | - error |
bool mysql_trans_commit_alter_copy_data | ( | THD * | thd | ) |
Commit the copy phase of the alter table.
bool mysql_trans_prepare_alter_copy_data | ( | THD * | thd | ) |
Prepare the transaction for the alter table's copy phase.
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.
thd | Thread handle. |
db_name | Database name. |
table_name | Table name. |
alter_info | Alter_info object with list of check constraints to be created. |
false | Success. |
true | Failure. |
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.
thd | Thread object. | |
error_schema_name | Schema name of the table used for error reporting. | |
error_table_name | Table name used for error reporting. | |
create_info | Create information. | |
[in,out] | create_list | List of columns to create. |
[in,out] | select_field_pos | Position where the SELECT columns start for CREATE TABLE ... SELECT. |
file | The handler for the new table. | |
[in,out] | sql_field | Create_field to populate. |
field_no | Column number. |
false | OK |
true | error |
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.
[in,out] | thd | thread handle. Used as a memory pool and source of environment information. |
[in] | src_table | DD table object. Will be nullptr for temporary tables and during upgrade. |
[in] | table | the source table, open and locked Used as an interface to the storage engine to acquire additional information about the original table. |
[in,out] | create_info | A blob with CREATE/ALTER TABLE parameters |
[in,out] | alter_info | Another 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_ctx | Runtime context for ALTER TABLE. |
[in] | used_fields | used_fields from HA_CREATE_INFO. |
true | error, out of memory or a semantical error in ALTER TABLE instructions |
false | success |
bool prepare_fk_parent_key | ( | THD * | thd, |
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_pack_create_field | ( | THD * | thd, |
Create_field * | sql_field, | ||
longlong | table_flags | ||
) |
Prepare a create_table instance for packing.
thd | Thread handle | |
[in,out] | sql_field | field to prepare for packing |
table_flags | table flags |
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.
[in] | thd | Thread handle |
[out] | field_def | An instance of initialized create_field |
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.
column_definitions | The list of column definitions, in the physical order in which they appear in the table. |
bool quick_rm_table | ( | THD * | thd, |
handlerton * | base, | ||
const char * | db, | ||
const char * | table_name, | ||
uint | flags | ||
) |
Quickly remove a table.
thd | Thread context. |
base | The handlerton handle. |
db | The database name. |
table_name | The table name. |
flags | Flags for build_table_filename(). |
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.
thd | Thread context. |
tables | Tables to be dropped by DROP TABLES/DATABASE. |
False | - Success. |
True | - Failure. |
size_t tablename_to_filename | ( | const char * | from, |
char * | to, | ||
size_t | to_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
thd | Thread handle | |
comment_str | Comment string | |
[in,out] | comment_len | Comment length |
max_len | Maximum allowed comment length | |
err_code | Error message | |
comment_name | Type of comment |
true | Error found |
false | On success |
int write_bin_log | ( | THD * | thd, |
bool | clear_error, | ||
const char * | query, | ||
size_t | query_length, | ||
bool | is_trans = false |
||
) |
|
extern |
Count number of times foreign key is created on non standard index keys.
|
extern |
Last time fk is created on non standard index key, as usec since epoch.
|
static |
|
static |
|
static |
|
static |
Don't change generated check constraint names while renaming table.
|
static |
Don't commit transaction after updating data-dictionary while renaming the table.
|
static |
Don't check foreign key constraints while renaming table.
|
static |
Don't change generated foreign key names while renaming table.
|
extern |