MySQL 9.0.0
Source Code Documentation
sql_table.cc File Reference
#include "sql/sql_table.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
#include "my_psi_config.h"
#include "mysql/psi/psi_table.h"
#include "decimal.h"
#include "field_types.h"
#include "lex_string.h"
#include "m_string.h"
#include "map_helpers.h"
#include "mem_root_deque.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_bitmap.h"
#include "my_check_opt.h"
#include "my_checksum.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_md5.h"
#include "my_md5_size.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_systime.h"
#include "my_thread_local.h"
#include "my_time.h"
#include "mysql/binlog/event/binlog_event.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/bits/psi_stage_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_stage.h"
#include "mysql/psi/mysql_table.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "nulls.h"
#include "pfs_table_provider.h"
#include "prealloced_array.h"
#include "scope_guard.h"
#include "sql-common/my_decimal.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/binlog.h"
#include "sql/create_field.h"
#include "sql/current_thd.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/collection.h"
#include "sql/dd/dd.h"
#include "sql/dd/dd_schema.h"
#include "sql/dd/dd_table.h"
#include "sql/dd/dictionary.h"
#include "sql/dd/properties.h"
#include "sql/dd/sdi_api.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/check_constraint.h"
#include "sql/dd/types/column.h"
#include "sql/dd/types/foreign_key.h"
#include "sql/dd/types/foreign_key_element.h"
#include "sql/dd/types/index.h"
#include "sql/dd/types/index_element.h"
#include "sql/dd/types/partition.h"
#include "sql/dd/types/schema.h"
#include "sql/dd/types/table.h"
#include "sql/dd/types/trigger.h"
#include "sql/dd_sql_view.h"
#include "sql/dd_table_share.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/error_handler.h"
#include "sql/field.h"
#include "sql/field_common_properties.h"
#include "sql/filesort.h"
#include "sql/gis/srid.h"
#include "sql/handler.h"
#include "sql/histograms/histogram.h"
#include "sql/item.h"
#include "sql/item_timefunc.h"
#include "sql/iterators/row_iterator.h"
#include "sql/join_optimizer/access_path.h"
#include "sql/join_optimizer/bit_utils.h"
#include "sql/key.h"
#include "sql/key_spec.h"
#include "sql/lock.h"
#include "sql/locked_tables_list.h"
#include "sql/log.h"
#include "sql/log_event.h"
#include "sql/mdl.h"
#include "sql/mem_root_array.h"
#include "sql/mysqld.h"
#include "sql/partition_element.h"
#include "sql/partition_info.h"
#include "sql/partitioning/partition_handler.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_rli.h"
#include "sql/session_tracker.h"
#include "sql/sql_alter.h"
#include "sql/sql_backup_lock.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_check_constraint.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_constraint.h"
#include "sql/sql_db.h"
#include "sql/sql_error.h"
#include "sql/sql_executor.h"
#include "sql/sql_gipk.h"
#include "sql/sql_handler.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_partition.h"
#include "sql/sql_plist.h"
#include "sql/sql_plugin.h"
#include "sql/sql_plugin_ref.h"
#include "sql/sql_resolver.h"
#include "sql/sql_show.h"
#include "sql/sql_tablespace.h"
#include "sql/sql_time.h"
#include "sql/sql_trigger.h"
#include "sql/srs_fetcher.h"
#include "sql/stateless_allocator.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql/trigger.h"
#include "sql/xa.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "strmake.h"
#include "strxmov.h"
#include "strxnmov.h"
#include "template_utils.h"
#include "thr_lock.h"
#include "typelib.h"

Classes

struct  anonymous_namespace{sql_table.cc}::Handlerton_pair
 
struct  anonymous_namespace{sql_table.cc}::Viability
 
class  Disable_slave_info_update_guard
 RAII class to control the atomic DDL commit on slave. More...
 
class  Drop_tables_ctx
 Runtime context for DROP TABLES statement. More...
 
class  Drop_tables_query_builder
 Auxiliary class which is used to construct synthesized DROP TABLES statements for the binary log during execution of DROP TABLES statement. More...
 
struct  anonymous_namespace{sql_table.cc}::sort_keys
 
class  anonymous_namespace{sql_table.cc}::Replace_field_processor_arg
 This class is used as an input argument to Item::walk, and takes care of replacing the field pointer in Item_field with pointers to a Create_field_wrapper. More...
 
struct  Table_exists_result
 Struct for representing the result of checking if a table exists before trying to create it. More...
 
class  Rename_table_error_handler
 

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 
namespace  anonymous_namespace{sql_table.cc}
 

Macros

#define ER_THD_OR_DEFAULT(thd, X)    ((thd) ? ER_THD_NONCONST(thd, X) : ER_DEFAULT_NONCONST(X))
 

Typedefs

using anonymous_namespace{sql_table.cc}::Viability_error_emitter = std::function< void(const char *engine_name)>
 
using anonymous_namespace{sql_table.cc}::Viability_substitution_warning_emitter = std::function< void(THD *, const char *requested_engine_name, const char *substituted_engine_name, const char *table_name)>
 
typedef std::set< std::pair< dd::String_type, dd::String_type > > Normalized_fk_children
 

Enumerations

enum  fk_column_change_type { FK_COLUMN_NO_CHANGE , FK_COLUMN_DATA_CHANGE , FK_COLUMN_RENAMED , FK_COLUMN_DROPPED }
 Type of change to foreign key column,. More...
 

Functions

bool anonymous_namespace{sql_table.cc}::is_temp_table (const HA_CREATE_INFO &ci)
 
bool anonymous_namespace{sql_table.cc}::is_engine_specified (const HA_CREATE_INFO &ci)
 
handlertonanonymous_namespace{sql_table.cc}::default_handlerton (THD *thd, const HA_CREATE_INFO &ci)
 
handlertonanonymous_namespace{sql_table.cc}::requested_handlerton (THD *thd, const HA_CREATE_INFO &ci)
 
Viability anonymous_namespace{sql_table.cc}::get_viability (const handlerton &hton, const HA_CREATE_INFO &ci)
 
handlertonanonymous_namespace{sql_table.cc}::get_viable_handlerton_for_create_impl (THD *thd, const char *table_name, const HA_CREATE_INFO &ci, Handlerton_pair hp)
 
handlertonanonymous_namespace{sql_table.cc}::get_viable_handlerton_for_create_like (THD *thd, const char *table_name, const HA_CREATE_INFO &ci, handlerton *source)
 Check if source is enabled AND NOT explicitly disabled (listed in the disabled_storages_engines system variable. More...
 
handlertonanonymous_namespace{sql_table.cc}::get_viable_handlerton_for_alter (THD *thd, const HA_CREATE_INFO &ci, handlerton *existing)
 Does nothing (returns existing) unless ALTER changes the ENGINE. More...
 
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...
 
static bool check_if_keyname_exists (const char *name, KEY *start, KEY *end)
 
static const char * make_unique_key_name (const char *field_name, KEY *start, KEY *end)
 
static const dd::Indexfind_fk_supporting_key (handlerton *hton, const dd::Table *table_def, const dd::Foreign_key *fk)
 Find supporting key for the foreign key. More...
 
const dd::Indexanonymous_namespace{sql_table.cc}::find_fk_parent_key (THD *thd, handlerton *hton, const dd::Index *supporting_key, const dd::Table *parent_table_def, const dd::Foreign_key *fk)
 Find parent key which matches the foreign key. More...
 
static int copy_data_between_tables (THD *thd, PSI_stage_progress *psi, TABLE *from, TABLE *to, List< Create_field > &create, ha_rows *copied, ha_rows *deleted, Alter_info::enum_enable_or_disable keys_onoff, Alter_table_ctx *alter_ctx)
 
static bool prepare_blob_field (THD *thd, Create_field *sql_field, bool convert_character_set)
 
static bool check_engine (const char *db_name, const char *table_name, HA_CREATE_INFO *create_info)
 Check if the table can be created in the specified storage engine. More...
 
static bool prepare_set_field (THD *thd, Create_field *sql_field)
 
static bool prepare_enum_field (THD *thd, Create_field *sql_field)
 
static uint blob_length_by_type (enum_field_types type)
 maximum possible length for certain blob types. More...
 
static const Create_fieldget_field_by_index (Alter_info *alter_info, uint idx)
 Get Create_field object for newly created table by field index. More...
 
static bool generate_check_constraint_name (THD *thd, const char *table_name, uint ordinal_number, LEX_STRING &name, bool skip_validation)
 Helper method to generate check constraint name. More...
 
static bool push_check_constraint_mdl_request_to_list (THD *thd, const char *db, const char *cc_name, MDL_request_list &cc_mdl_request_list)
 Helper method to create MDL_request for check constraint names. More...
 
static bool prepare_check_constraints_for_create_like_table (THD *thd, Table_ref *src_table, Table_ref *target_table, Alter_info *alter_info)
 Method to prepare check constraints for the CREATE TABLE LIKE operation. More...
 
static bool prepare_check_constraints_for_alter (THD *thd, const TABLE *table, Alter_info *alter_info, Alter_table_ctx *alter_tbl_ctx)
 Method to prepare check constraints for the ALTER TABLE operation. More...
 
static void set_check_constraints_alter_mode (dd::Table *new_table, Alter_info *alter_info)
 During alter table operation, check constraints of a new table are marked as in alter mode. More...
 
static void reset_check_constraints_alter_mode (dd::Table *new_table)
 Reset alter mode of check constraints. More...
 
static bool adjust_check_constraint_names_for_old_table_version (THD *thd, const char *old_table_db, dd::Table *old_table)
 Make old table definition's check constraint use temporary names. More...
 
static bool is_any_check_constraints_evaluation_required (const Alter_info *alter_info)
 Helper method to check if any check constraints (re-)evaluation is required. More...
 
static bool check_if_field_used_by_generated_column_or_default (TABLE *table, const Field *field, const Alter_info *alter_info)
 Check if the column being removed or renamed is in use by a generated column, default or functional index, which will be kept around/unchanged by this ALTER TABLE, and report error which is appropriate for the case. More...
 
static bool trans_intermediate_ddl_commit (THD *thd, bool error)
 
static char * add_identifier (THD *thd, char *to_p, const char *end_p, const char *name, size_t name_len)
 Helper function for explain_filename. 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...
 
size_t filename_to_tablename (const char *from, char *to, size_t to_length, bool stay_quiet, bool *has_errors)
 
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_name, const char *ext, uint flags, bool *was_truncated)
 
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...
 
static bool rea_create_tmp_table (THD *thd, const char *path, const dd::Schema &sch_obj, const char *db, const char *table_name, HA_CREATE_INFO *create_info, List< Create_field > &create_fields, uint keys, KEY *key_info, Alter_info::enum_enable_or_disable keys_onoff, const Sql_check_constraint_spec_list *check_cons_spec, handler *file, bool no_ha_table, bool *binlog_to_trx_cache, std::unique_ptr< dd::Table > *tmp_table_def)
 Create a dd::Table-object specifying the temporary table definition, but do not put it into the Data Dictionary. More...
 
static bool rea_create_base_table (THD *thd, const char *path, const dd::Schema &sch_obj, const char *db, const char *table_name, HA_CREATE_INFO *create_info, List< Create_field > &create_fields, uint keys, KEY *key_info, Alter_info::enum_enable_or_disable keys_onoff, uint fk_keys, FOREIGN_KEY *fk_key_info, const Sql_check_constraint_spec_list *check_cons_spec, handler *file, bool no_ha_table, bool do_not_store_in_dd, partition_info *part_info, bool *binlog_to_trx_cache, std::unique_ptr< dd::Table > *table_def_ptr, handlerton **post_ddl_ht)
 Create table definition in the Data Dictionary. More...
 
int write_bin_log (THD *thd, bool clear_error, const char *query, size_t query_length, bool is_trans)
 
bool lock_trigger_names (THD *thd, Table_ref *tables)
 Acquire metadata lock on triggers associated with a list of tables. More...
 
static bool collect_fk_parents_for_all_fks (THD *thd, const dd::Table *table_def, handlerton *hton, enum_mdl_type lock_type, MDL_request_list *mdl_requests, Foreign_key_parents_invalidator *fk_invalidator)
 Add MDL requests for specified lock type on all tables referenced by the given dd::Table object to the list. More...
 
static bool collect_fk_children (THD *thd, const dd::Table *table_def, enum_mdl_type lock_type, MDL_request_list *mdl_requests)
 Add MDL requests for specified lock type on all tables referencing the given table. More...
 
static bool collect_fk_names (THD *thd, const char *db, const dd::Table *table_def, MDL_request_list *mdl_requests)
 Add MDL requests for exclusive lock on all foreign key names on the given table to the list. 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 mysql_rm_table (THD *thd, Table_ref *tables, bool if_exists, bool drop_temporary)
 
static void append_table_ident (const THD *thd, String *to, const Table_ref *table, bool force_db)
 Auxiliary function which appends to the string table identifier with proper quoting and schema part if necessary. More...
 
static void append_table_name (String *to, const Table_ref *table)
 Auxiliary function which appends to the string schema and table name for the table (without quoting). More...
 
static bool rm_table_sort_into_groups (THD *thd, Drop_tables_ctx *drop_ctx, Table_ref *tables)
 Auxiliary function which prepares for DROP TABLES execution by sorting tables to be dropped into groups according to their types. More...
 
static bool rm_table_eval_gtid_and_table_groups_state (THD *thd, Drop_tables_ctx *drop_ctx)
 Auxiliary function which evaluates in which situation DROP TABLES is regarding GTID and different table groups. More...
 
static bool rm_table_check_fks (THD *thd, Drop_tables_ctx *drop_ctx)
 Check if DROP TABLES or DROP DATABASE statement going to violate some foreign key constraint by dropping its parent table without dropping child at the same time. More...
 
static bool adjust_fk_children_for_parent_drop (THD *thd, const char *parent_table_db, const char *parent_table_name, const dd::Table *parent_table_def, handlerton *hton)
 Update the unique constraint names for FKs which reference table being dropped. More...
 
static bool validate_secondary_engine_option (THD *thd, const Alter_info &alter_info, const HA_CREATE_INFO &create_info, const TABLE &table)
 Validates the ALTER TABLE command with respect to any secondary engine operations. More...
 
static bool secondary_engine_load_table (THD *thd, const TABLE &table, bool *skip_metadata_update)
 Loads a table from its primary engine into its secondary engine. More...
 
static bool secondary_engine_unload_table (THD *thd, const char *db_name, const char *table_name, const dd::Table &table_def, bool error_if_not_loaded)
 Unloads a table from its secondary engine. More...
 
static bool drop_base_table (THD *thd, const Drop_tables_ctx &drop_ctx, Table_ref *table, bool atomic, std::set< handlerton * > *post_ddl_htons, Foreign_key_parents_invalidator *fk_invalidator, std::vector< MDL_ticket * > *safe_to_release_mdl, MEM_ROOT *foreach_table_root)
 Auxiliary function which drops single base table. More...
 
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 quick_rm_table (THD *thd, handlerton *base, const char *db, const char *table_name, uint flags)
 Quickly remove a table. More...
 
static bool check_duplicates_in_interval (THD *thd, const char *set_or_name, const char *name, TYPELIB *typelib, const CHARSET_INFO *cs, uint *dup_val_count)
 
bool prepare_pack_create_field (THD *thd, Create_field *sql_field, longlong table_flags)
 Prepare a create_table instance for packing. More...
 
TYPELIBcreate_typelib (MEM_ROOT *mem_root, Create_field *field_def)
 
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...
 
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...
 
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...
 
static bool check_duplicate_key (THD *thd, const char *error_schema_name, const char *error_table_name, const KEY *key, const KEY *key_info, uint key_count, Alter_info *alter_info)
 Check if there is a duplicate key. More...
 
static bool is_field_part_of_index (const Field &field, const Create_field &new_field, Alter_inplace_info *ha_alter_info)
 Scan the indexes of the new table (including the added ones), and check if the field is referred by any index. More...
 
static bool is_field_part_of_partition_expression (const Field &field, Alter_inplace_info *ha_alter_info)
 Scan the fields used in partition expressions of the new table (including the added ones), and check if the field is used by a partitioning expression. More...
 
static bool is_phony_blob (enum_field_types sql_type, uint decimals)
 Helper function which allows to detect column types for which we historically used key packing (optimization implemented only by MyISAM) under erroneous assumption that they have BLOB type. More...
 
static bool is_json_pk_on_external_table (const uint32 flags, const keytype keytype, const enum_field_types sql_type)
 Helper function which checks if external table has primary key on JSON column. 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...
 
static void calculate_field_offsets (List< Create_field > *create_list)
 
static bool count_keys (const Mem_root_array< Key_spec * > &key_list, uint *key_count, uint *key_parts, uint *fk_key_count, Mem_root_array< bool > *redundant_keys, handler::Table_flags se_index_flags)
 Count keys and key segments. More...
 
static bool prepare_key_column (THD *thd, HA_CREATE_INFO *create_info, List< Create_field > *create_list, const Key_spec *key, const Key_part_spec *column, const size_t column_nr, KEY *key_info, KEY_PART_INFO *key_part_info, const handler *file, int *auto_increment, const CHARSET_INFO **ft_key_charset)
 
template<class F >
static bool fk_is_key_exact_match_any_order (Alter_info *alter_info, uint fk_col_count, const F &fk_columns, const KEY *key)
 Check if candidate parent/supporting key contains exactly the same columns as the foreign key, possibly, in different order. More...
 
template<class F >
static uint fk_key_prefix_match_count (Alter_info *alter_info, uint fk_col_count, const F &fk_columns, const KEY *key, const KEY *hidden_cols_key)
 Count how many elements from the start of the candidate parent/supporting key match elements at the start of the foreign key (prefix parts are considered non-matching). More...
 
template<class F >
static bool fk_key_is_full_prefix_match (Alter_info *alter_info, uint fk_col_count, const F &fk_columns, const KEY *key, const KEY *hidden_cols_key)
 Check if candidate parent/supporting key contains all columns from the foreign key at its start and in the same order it is in the foreign key. More...
 
bool anonymous_namespace{sql_table.cc}::fk_is_key_exact_match_order (Alter_info *alter_info, FOREIGN_KEY *fk, const KEY *key)
 Check if candidate parent key contains exactly the same columns as the foreign key in same order. More...
 
void anonymous_namespace{sql_table.cc}::report_fk_index_error (THD *thd, const char *fk_name, const char *table_name)
 Report new error code ER_FK_NO_UNIQUE_INDEX_PARENT when session variable restrict_fk_on_non_standard_key is ON and ER_FK_NO_INDEX_PARENT when it if OFF. More...
 
void anonymous_namespace{sql_table.cc}::warn_fk_on_non_standard_key (THD *thd, const char *key_name)
 Raise warning when foreign key is created on non-unique key or partial key, increment the deprecated fk usage count, and last time stamp it occurred. More...
 
static bool prepare_self_ref_fk_parent_key (THD *thd, handlerton *hton, Alter_info *alter_info, const KEY *key_info_buffer, const uint key_count, const KEY *supporting_key, const dd::Table *old_fk_table, FOREIGN_KEY *fk)
 Check if parent key for self-referencing foreign key exists, set foreign key's unique constraint name accordingly. More...
 
static const KEYfind_fk_supporting_key (handlerton *hton, Alter_info *alter_info, const KEY *key_info_buffer, const uint key_count, const FOREIGN_KEY *fk)
 Find supporting key for the foreign key. More...
 
static bool adjust_foreign_key_names_for_old_table_version (THD *thd, const char *db_name, const char *backup_name)
 Make old table definition's foreign keys use temporary names. More...
 
static uint get_fk_max_generated_name_number (const char *table_name, const dd::Table *table_def, handlerton *hton)
 Find max value of number component among existing generated foreign key names for the table. More...
 
static void generate_fk_name (char *name_buff, size_t name_buff_size, const char *table_name, handlerton *hton, uint *fk_max_generated_name_number)
 Generate a foreign key name and store it in buffer provided. More...
 
static const char * generate_fk_name (const char *table_name, handlerton *hton, uint *fk_max_generated_name_number)
 Generate a foreign key name, allocate memory from thread's current memory root for it. More...
 
template<class F >
bool anonymous_namespace{sql_table.cc}::fk_is_key_exact_match_order (uint fk_col_count, const F &fk_columns, const dd::Index *idx)
 Check if candidate parent/supporting key contains exactly the same columns as the foreign key in same order. More...
 
template<class F >
static bool fk_is_key_exact_match_any_order (uint fk_col_count, const F &fk_columns, const dd::Index *idx)
 Check if candidate parent/supporting key contains exactly the same columns as the foreign key, possibly, in different order. More...
 
template<class F >
static uint fk_key_prefix_match_count (uint fk_col_count, const F &fk_columns, const dd::Index *idx, bool use_hidden)
 Count how many elements from the start of the candidate parent/supporting key match elements at the start of the foreign key (prefix parts are considered non-matching). More...
 
template<class F >
static bool fk_key_is_full_prefix_match (uint fk_col_count, const F &fk_columns, const dd::Index *idx, bool use_hidden)
 Check if candidate parent/supporting key contains all columns from the foreign key at its start and in the same order it is in the foreign key. More...
 
template<class F >
const dd::Indexanonymous_namespace{sql_table.cc}::find_fk_parent_key (THD *thd, handlerton *hton, const dd::Index *supporting_key, const dd::Table *parent_table_def, const char *fk_name, uint fk_col_count, const F &fk_columns)
 Find parent key which matches the foreign key. More...
 
bool anonymous_namespace{sql_table.cc}::prepare_fk_parent_key (THD *thd, handlerton *hton, const dd::Table *parent_table_def, FOREIGN_KEY *fk)
 
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)
 
static void fill_ha_fk_column_type (Ha_fk_column_type *fk_column_type, const Create_field *field)
 Helper which builds Ha_fk_column_type describing column type from its Create_field object. More...
 
static bool fill_ha_fk_column_type (Ha_fk_column_type *fk_column_type, const dd::Column *column)
 Helper which builds Ha_fk_column_type describing column type from its dd::Column object. More...
 
static bool prepare_foreign_key (THD *thd, HA_CREATE_INFO *create_info, Alter_info *alter_info, const char *db, const char *table_name, bool is_partitioned, KEY *key_info_buffer, uint key_count, const FOREIGN_KEY *fk_info_all, uint fk_number, bool se_supports_fks, bool find_parent_key, Foreign_key_spec *fk_key, uint *fk_max_generated_name_number, FOREIGN_KEY *fk_info)
 Prepare FOREIGN_KEY struct with info about a foreign key. More...
 
static bool prepare_preexisting_self_ref_foreign_key (THD *thd, HA_CREATE_INFO *create_info, Alter_info *alter_info, KEY *key_info, uint key_count, const KEY *supporting_key, const dd::Table *existing_fks_table, FOREIGN_KEY *fk, const Prealloced_array< Create_field *, 1 > &referencing_fields)
 Check that pre-existing self-referencing foreign key or an orphan non-self-referencing foreign key become non-orphan/adopted self-referencing foreign key as a result of table rename operation will be valid after ALTER TABLE, i.e. More...
 
static bool prepare_preexisting_foreign_key (THD *thd, HA_CREATE_INFO *create_info, Alter_info *alter_info, const char *schema_name, const char *table_name, KEY *key_info, uint key_count, const dd::Table *existing_fks_table, FOREIGN_KEY *fk)
 Check that pre-existing foreign key will be still valid after ALTER TABLE, i.e. More...
 
static bool prepare_key (THD *thd, const char *error_schema_name, const char *error_table_name, HA_CREATE_INFO *create_info, List< Create_field > *create_list, const Key_spec *key, KEY **key_info_buffer, KEY *key_info, KEY_PART_INFO **key_part_info, Mem_root_array< const KEY * > &keys_to_check, uint key_number, const handler *file, int *auto_increment)
 
static bool check_promoted_index (const handler *file, const KEY *key_info_buffer, uint key_count)
 Primary/unique key check. More...
 
static bool key_name_exists (const Mem_root_array< Key_spec * > &keys, const std::string &key_name, const Key_spec *key_to_ignore)
 Check if the given key name exists in the array of keys. More...
 
static bool column_name_exists (const List< Create_field > &fields, const string &column_name)
 Checks if a column with the given name exists in a list of fields. More...
 
static const char * make_functional_index_column_name (std::string_view key_name, unsigned key_part_number, const List< Create_field > &fields, MEM_ROOT *mem_root)
 Create a name for the hidden generated column that represents the functional key part. More...
 
static bool is_not_slave_or_master_sorts_functional_index_columns_last (uint32_t master_version)
 Whether or not we have a replication setup, and the master sorts functional index columns last in the table. More...
 
static Create_fieldadd_functional_index_to_create_list (THD *thd, Key_spec *key_spec, Alter_info *alter_info, Key_part_spec *kp, uint key_part_number, HA_CREATE_INFO *create_info)
 Prepares a functional index by adding a hidden indexed generated column for the key part. More...
 
static bool column_exists_in_create_list (const char *column_name, List< Create_field > &create_list)
 Check if the given column exists in the create list. 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...
 
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...
 
static bool set_table_default_charset (THD *thd, HA_CREATE_INFO *create_info, const dd::Schema &schema)
 
static Table_exists_result check_if_table_exists (THD *thd, const char *schema_name, const char *table_name, const char *alias, bool ha_lex_create_tmp_table, bool ha_create_if_not_exists, bool internal_tmp_table)
 Check if table already exists. More...
 
static bool create_table_impl (THD *thd, const dd::Schema &schema, const char *db, const char *table_name, const char *error_table_name, const char *path, HA_CREATE_INFO *create_info, Alter_info *alter_info, bool internal_tmp_table, uint select_field_count, bool find_parent_keys, bool no_ha_table, bool do_not_store_in_dd, bool *is_trans, KEY **key_info, uint *key_count, Alter_info::enum_enable_or_disable keys_onoff, FOREIGN_KEY **fk_key_info, uint *fk_key_count, FOREIGN_KEY *existing_fk_info, uint existing_fk_count, const dd::Table *existing_fk_table, uint fk_max_generated_name_number, std::unique_ptr< dd::Table > *table_def, handlerton **post_ddl_ht)
 Create a table. More...
 
static bool validate_table_encryption (THD *thd, HA_CREATE_INFO *create_info)
 
static void warn_on_deprecated_float_precision (THD *thd, const Create_field &sql_field)
 
static void warn_on_deprecated_float_unsigned (THD *thd, const Create_field &sql_field)
 
static void warn_on_deprecated_zerofill (THD *thd, const Create_field &sql_field)
 
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...
 
static bool fetch_fk_children_uncached_uncommitted_normalized (THD *thd, const char *parent_schema, const char *parent_name, const char *parent_engine, Normalized_fk_children *fk_children)
 Fetch names of all tables having a FK referring to the given table. More...
 
bool collect_fk_children (THD *thd, const char *db, const char *arg_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...
 
static bool reload_fk_parents_for_single_table (THD *thd, const char *db, const char *name)
 
bool adjust_fk_parents (THD *thd, const char *db, const char *name, bool reload_self, const Foreign_key_parents_invalidator *fk_invalidator)
 
static bool check_table_has_col_compatible_with_fk_ref_col (const dd::Table *parent_table_def, const dd::Foreign_key *fk, const dd::Foreign_key_element *fk_el, handlerton *hton)
 Check if foreign key's parent table has a column compatible with foreign key's referenced column. More...
 
static bool adjust_fk_child_after_parent_def_change (THD *thd, bool check_only, bool check_charsets, const char *child_table_db, const char *child_table_name, const char *parent_table_db, const char *parent_table_name, handlerton *hton, const dd::Table *parent_table_def, Alter_info *parent_alter_info, const dd::Table *old_parent_table_def)
 Check if new definition of parent table is compatible with foreign keys on child table which reference it. More...
 
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...
 
static bool check_fk_children_after_parent_def_change (THD *thd, const char *parent_table_db, const char *parent_table_name, handlerton *hton, const dd::Table *old_parent_table_def, const dd::Table *new_parent_table_def, Alter_info *parent_alter_info)
 Check if new definition of parent table is compatible with foreign keys which reference it. More...
 
static bool check_fk_children_after_parent_def_change (THD *thd, const char *parent_table_db, const char *parent_table_name, const char *old_parent_table_db, const char *old_parent_table_name, handlerton *hton, const dd::Table *parent_table_def)
 Check if new definition of parent table is compatible with foreign keys which reference it and were previously orphan. More...
 
static bool adjust_fk_children_after_parent_rename (THD *thd, const char *parent_table_db, const char *parent_table_name, handlerton *hton, const char *new_db, const char *new_table_name)
 Update the referenced schema- and/or table name for the referencing tables when the referenced table is renamed. 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 mysql_create_table (THD *thd, Table_ref *create_table, HA_CREATE_INFO *create_info, Alter_info *alter_info)
 Implementation of SQLCOM_CREATE_TABLE. More...
 
static bool rename_histograms (THD *thd, const char *old_schema_name, const char *old_table_name, const char *new_schema_name, const char *new_table_name)
 Rename histograms from an old table name to a new table name. More...
 
static bool alter_table_drop_histograms (THD *thd, Table_ref *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, histograms::columns_set &columns, const dd::Table *original_table_def, const dd::Table *altered_table_def)
 Drop histograms from a given table. More...
 
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_create_like_table (THD *thd, Table_ref *table, Table_ref *src_table, HA_CREATE_INFO *create_info)
 
static bool is_candidate_key (KEY *key)
 Check if key is a candidate key, i.e. More...
 
static KEYfind_key_ci (const char *key_name, KEY *key_start, KEY *key_end)
 Look-up KEY object by index name using case-insensitive comparison. More...
 
static KEYfind_key_cs (const char *key_name, KEY *key_start, KEY *key_end)
 Look-up KEY object by index name using case-sensitive comparison. More...
 
static bool has_index_def_changed (Alter_inplace_info *ha_alter_info, const KEY *table_key, const KEY *new_key)
 Check if index has changed in a new version of table (ignore possible rename of index). More...
 
static bool fill_alter_inplace_info (THD *thd, TABLE *table, Alter_inplace_info *ha_alter_info)
 Compare original and new versions of a table and fill Alter_inplace_info describing differences between those versions. More...
 
static void update_altered_table (const Alter_inplace_info &ha_alter_info, TABLE *altered_table)
 Mark fields participating in newly added indexes in TABLE object which corresponds to new version of altered table. More...
 
static void set_column_static_defaults (TABLE *altered_table, List< Create_field > &create)
 Initialize TABLE::field for the new table with appropriate column static defaults. 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...
 
static bool push_zero_date_warning (THD *thd, Create_field *datetime_field)
 Report a zero date warning if no default value is supplied for the DATE/DATETIME 'NOT NULL' field and 'NO_ZERO_DATE' sql_mode is enabled. More...
 
static bool alter_table_manage_keys (THD *thd, TABLE *table, int indexes_were_disabled, Alter_info::enum_enable_or_disable keys_onoff)
 
static bool is_inplace_alter_impossible (TABLE *table, HA_CREATE_INFO *create_info, const Alter_info *alter_info)
 Check if the pending ALTER TABLE operations support the in-place algorithm based on restrictions in the SQL layer or given the nature of the operations themselves. More...
 
static bool collect_fk_parents_for_dropped_fks (THD *thd, const Alter_info *alter_info, const dd::Table *table_def, handlerton *hton, MDL_request_list *mdl_requests, Foreign_key_parents_invalidator *fk_invalidator)
 Add MDL requests for exclusive lock on tables referenced by the foreign keys to be dropped by ALTER TABLE operation. More...
 
static bool collect_and_lock_fk_tables_for_complex_alter_table (THD *thd, Table_ref *table_list, const dd::Table *old_table_def, const Alter_table_ctx *alter_ctx, const Alter_info *alter_info, handlerton *old_hton, handlerton *new_hton, Foreign_key_parents_invalidator *fk_invalidator)
 Acquire exclusive metadata locks on tables which definitions need to be updated or invalidated due to foreign keys created or dropped as result of complex ALTER TABLE operation. More...
 
static bool adjust_fks_for_complex_alter_table (THD *thd, Table_ref *table_list, Alter_table_ctx *alter_ctx, Alter_info *alter_info, handlerton *new_hton, const Foreign_key_parents_invalidator *fk_invalidator)
 Update referenced table names and the unique constraint name for FKs affected by complex ALTER TABLE operation. More...
 
static bool collect_fk_names_for_rename_table (THD *thd, const char *db, const char *table_name, const dd::Table *table_def, handlerton *hton, const char *new_db, const char *new_table_name, MDL_request_list *mdl_requests)
 Add appropriate MDL requests on names of foreign keys on the table to be renamed to the requests list. More...
 
static bool check_fk_names_before_rename (THD *thd, Table_ref *table_list, const dd::Table &table_def, handlerton *hton, const dd::Schema &new_schema, const Alter_table_ctx &alter_ctx)
 Check if complex ALTER TABLE with RENAME clause results in foreign key names conflicts. More...
 
static bool table_is_empty (TABLE *table, bool *is_empty)
 Check if a table is empty, i.e., it has no rows. More...
 
static bool remove_secondary_engine (THD *thd, const Table_ref &table, const HA_CREATE_INFO &create_info, const dd::Table *old_table_def)
 Unloads table from secondary engine if SECONDARY_ENGINE = NULL. More...
 
static bool mysql_inplace_alter_table (THD *thd, const dd::Schema &schema, const dd::Schema &new_schema, const dd::Table *table_def, dd::Table *altered_table_def, Table_ref *table_list, TABLE *table, TABLE *altered_table, Alter_inplace_info *ha_alter_info, enum_alter_inplace_result inplace_supported, Alter_table_ctx *alter_ctx, histograms::columns_set &columns, FOREIGN_KEY *fk_key_info, uint fk_key_count, Foreign_key_parents_invalidator *fk_invalidator)
 Perform in-place alter table. More...
 
static fk_option to_fk_option (dd::Foreign_key::enum_rule rule)
 
static fk_match_opt to_fk_match_opt (dd::Foreign_key::enum_match_option match)
 
static void to_lex_cstring (MEM_ROOT *mem_root, LEX_CSTRING *target, const dd::String_type &source)
 
static bool transfer_preexisting_foreign_keys (THD *thd, const dd::Table *src_table, const char *src_db_name, const char *src_table_name, handlerton *hton, const Alter_info *alter_info, List< Create_field > *new_create_list, Alter_table_ctx *alter_ctx, Prealloced_array< const Alter_drop *, 1 > *drop_list)
 Remember information about pre-existing foreign keys so that they can be added to the new version of the table later. More...
 
static bool check_if_field_used_by_partitioning_func (TABLE *table, const Field *field, const Alter_info *alter_info)
 Check if the column being removed or renamed is in use by partitioning function for the table and that the partitioning is kept/partitioning function is unchanged by this ALTER TABLE, and report error if it is the case. More...
 
static bool alter_column_name_default_or_visibility (const Alter_info *alter_info, Prealloced_array< const Alter_column *, 1 > *alter_list, Create_field *def)
 Sets column default, drops default, renames or alters visibility. More...
 
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...
 
static const Create_fieldget_field_by_old_name (Alter_info *alter_info, const char *old_name)
 Get Create_field object for newly created table by its name in the old version of table. More...
 
template<class F >
static fk_column_change_type fk_check_column_changes (THD *thd, Alter_info *alter_info, uint fk_col_count, const F &fk_columns, const char **bad_column_name)
 Check that ALTER TABLE's changes on columns of a foreign key are allowed. More...
 
static bool fk_check_copy_alter_table (THD *thd, Table_ref *table_list, const dd::Table *table_def, Alter_info *alter_info)
 Check if ALTER TABLE we are about to execute using COPY algorithm is not supported as it might break referential integrity. 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...
 
static bool is_simple_rename_or_index_change (const Alter_info *alter_info)
 Check if ALTER TABLE in question is a simple ALTER TABLE RENAME or ALTER TABLE ENABLE/DISABLE KEYS. More...
 
static bool simple_rename_or_index_change (THD *thd, const dd::Schema &new_schema, Table_ref *table_list, Alter_info::enum_enable_or_disable keys_onoff, Alter_table_ctx *alter_ctx)
 Rename table and/or turn indexes on/off without touching .FRM. More...
 
static bool is_alter_geometry_column_valid (Alter_info *alter_info)
 Check if we are changing the SRID specification on a geometry column that has a spatial index. More...
 
static bool collect_fk_names_for_dropped_fks (THD *thd, const char *db, const Alter_info *alter_info, const dd::Table *table_def, MDL_request_list *mdl_requests)
 Add MDL requests for exclusive lock on names of the foreign keys to be dropped by ALTER TABLE operation to the lock requests list. More...
 
static bool handle_drop_functional_index (THD *thd, Alter_info *alter_info, Table_ref *table_list)
 This function will check if we are dropping a functional index. More...
 
static bool handle_rename_functional_index (THD *thd, Alter_info *alter_info, Table_ref *table_list)
 This function will check if we are renaming a functional index. 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_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_recreate_table (THD *thd, Table_ref *table_list, bool table_copy)
 
bool mysql_checksum_table (THD *thd, Table_ref *tables, HA_CHECK_OPT *check_opt)
 
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...
 
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 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...
 

Variables

std::atomic_ulong deprecated_use_fk_on_non_standard_key_count = 0
 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 = 0
 Last time fk is created on non standard index key, as usec since epoch. More...
 
static constexpr const int KEY_DEFAULT_PACK_LENGTH {8}
 Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). More...
 
static constexpr const int MAX_ENUM_VALUES {65535}
 
const char * primary_key_name = "PRIMARY"
 

Macro Definition Documentation

◆ ER_THD_OR_DEFAULT

#define ER_THD_OR_DEFAULT (   thd,
  X 
)     ((thd) ? ER_THD_NONCONST(thd, X) : ER_DEFAULT_NONCONST(X))

Typedef Documentation

◆ Normalized_fk_children

typedef std::set<std::pair<dd::String_type, dd::String_type> > Normalized_fk_children

Enumeration Type Documentation

◆ fk_column_change_type

Type of change to foreign key column,.

Enumerator
FK_COLUMN_NO_CHANGE 
FK_COLUMN_DATA_CHANGE 
FK_COLUMN_RENAMED 
FK_COLUMN_DROPPED 

Function Documentation

◆ add_functional_index_to_create_list()

static Create_field * add_functional_index_to_create_list ( THD thd,
Key_spec key_spec,
Alter_info alter_info,
Key_part_spec kp,
uint  key_part_number,
HA_CREATE_INFO create_info 
)
static

Prepares a functional index by adding a hidden indexed generated column for the key part.

A functional index is implemented as a hidden generated column over the expression specified in the index, and the hidden generated column is then indexed. This function adds a hidden generated column to the Create_list, and updates the key specification to point to this new column. The generated column is given a name that is a hash of the key name and the key part number.

Parameters
thdThe thread handler
key_specThe index that contains the key part.-
alter_infoA structure describing the changes to be carried out. This structure will be updated with the new generated column.
kpThe specification of the key part. This contains the expression we will create a generated column for, and it will be updated to point at the newly created generated column.
key_part_numberThe number of the key part.
create_infoA structure describing the table to be created
Returns
The newly added Create_field on success, of nullptr in case of errors

◆ add_identifier()

static char * add_identifier ( THD thd,
char *  to_p,
const char *  end_p,
const char *  name,
size_t  name_len 
)
static

Helper function for explain_filename.

Parameters
thdThread handle
to_pExplained name in system_charset_info
end_pEnd of the to_p buffer
nameName to be converted
name_lenLength of the name, in bytes

◆ 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_check_constraint_names_for_old_table_version()

static bool adjust_check_constraint_names_for_old_table_version ( THD thd,
const char *  old_table_db,
dd::Table old_table 
)
static

Make old table definition's check constraint use temporary names.

This is needed to avoid problems with duplicate check constraint names while we have two definitions of the same table. Method updates only dd::Table object. It is not stored or updated to data-dictionary in this method.

Parameters
thdThread context.
old_table_dbDatabase of old table.
old_tableOld table definition.
Returns
false - Success, true - Failure.

◆ adjust_fk_child_after_parent_def_change()

static bool adjust_fk_child_after_parent_def_change ( THD thd,
bool  check_only,
bool  check_charsets,
const char *  child_table_db,
const char *  child_table_name,
const char *  parent_table_db,
const char *  parent_table_name,
handlerton hton,
const dd::Table parent_table_def,
Alter_info parent_alter_info,
const dd::Table old_parent_table_def 
)
static

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

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

Parameters
thdThread handle.
check_onlyIndicates that we only need to check parent key existence and do not do real update.
check_charsetsIndicates whether we need to check charsets of columns participating in foreign keys.
child_table_dbChild table schema name.
child_table_nameChild table name.
parent_table_dbParent table schema name.
parent_table_nameParent table name.
htonHandlerton for tables' storage engine.
parent_table_defTable object representing the new version of referenced table.
parent_alter_infoAlter_info containing information about renames of parent columns. Can be nullptr if there are no such renames.
old_parent_table_defTable object representing the old version of referenced table. Can be nullptr if this is not ALTER TABLE. Used for error reporting.
Return values
operationoutcome, false if no error.

◆ adjust_fk_children_after_parent_def_change()

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_rename()

static bool adjust_fk_children_after_parent_rename ( THD thd,
const char *  parent_table_db,
const char *  parent_table_name,
handlerton hton,
const char *  new_db,
const char *  new_table_name 
)
static

Update the referenced schema- and/or table name for the referencing tables when the referenced table is renamed.

Parameters
thdThread handle.
parent_table_dbOld schema name.
parent_table_nameOld table name.
htonHandlerton for table's storage engine.
new_dbNew schema name.
new_table_nameNew table name.
Return values
operationoutcome, false if no error.

◆ adjust_fk_children_for_parent_drop()

static bool adjust_fk_children_for_parent_drop ( THD thd,
const char *  parent_table_db,
const char *  parent_table_name,
const dd::Table parent_table_def,
handlerton hton 
)
static

Update the unique constraint names for FKs which reference table being dropped.

Parameters
thdThread handle.
parent_table_dbSchema name for table being dropped.
parent_table_nameName of the table being dropped.
parent_table_defdd::Table object representing the dropped table.
htonHandlerton for table's storage engine.
Return values
operationoutcome, false if no error.

◆ 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_complex_alter_table()

static bool adjust_fks_for_complex_alter_table ( THD thd,
Table_ref table_list,
Alter_table_ctx alter_ctx,
Alter_info alter_info,
handlerton new_hton,
const Foreign_key_parents_invalidator fk_invalidator 
)
static

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

Parameters
thdThread handle.
table_listTable list element for table being ALTERed.
alter_ctxALTER TABLE operation context.
alter_infoAlter_info describing ALTER TABLE, specifically containing information about columns being renamed.
new_htonTable's new SE.
fk_invalidatorObject keeping track of which dd::Table objects to invalidate. Used to filter out which FK parents should have their FK parent information reloaded.
Return values
operationoutcome, false if no error.

◆ 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.

◆ adjust_foreign_key_names_for_old_table_version()

static bool adjust_foreign_key_names_for_old_table_version ( THD thd,
const char *  db_name,
const char *  backup_name 
)
static

Make old table definition's foreign keys use temporary names.

This is needed to avoid problems with duplicate foreign key names while we have two definitions of the same table.

Parameters
thdThread context.
db_nameDatabase where old table definition resides.
backup_nameTemporary name assigned to old table definition during ALTER TABLE.
Returns
False - Success, True - Failure.

◆ alter_column_name_default_or_visibility()

static bool alter_column_name_default_or_visibility ( const Alter_info alter_info,
Prealloced_array< const Alter_column *, 1 > *  alter_list,
Create_field def 
)
static

Sets column default, drops default, renames or alters visibility.

◆ alter_table_drop_histograms()

static bool alter_table_drop_histograms ( THD thd,
Table_ref table,
Alter_info alter_info,
HA_CREATE_INFO create_info,
histograms::columns_set columns,
const dd::Table original_table_def,
const dd::Table altered_table_def 
)
static

Drop histograms from a given table.

This function will check if an ALTER TABLE statement will make a histogram invalid:

  • Removing columns
  • Changing columns (data type, collation and such)
  • Adding UNIQUE index

If such change is found, remove any existing histogram for these columns.

Parameters
thdthread handler
tablethe table given in ALTER TABLE
alter_infothe alter changes to be carried out by ALTER TABLE
create_infothe alter changes to be carried out by ALTER TABLE
columnsa list of columns to be changed or dropped
original_table_defthe table definition, pre altering. Note that the name returned by original_table_def->name() might not be the same as table->table_name, since this may be a backup table object with an auto-generated name
altered_table_defthe table definition, post altering
Returns
false on success, true on error

◆ alter_table_manage_keys()

static bool alter_table_manage_keys ( THD thd,
TABLE table,
int  indexes_were_disabled,
Alter_info::enum_enable_or_disable  keys_onoff 
)
static

◆ append_table_ident()

static void append_table_ident ( const THD thd,
String to,
const Table_ref table,
bool  force_db 
)
static

Auxiliary function which appends to the string table identifier with proper quoting and schema part if necessary.

◆ append_table_name()

static void append_table_name ( String to,
const Table_ref table 
)
static

Auxiliary function which appends to the string schema and table name for the table (without quoting).

◆ blob_length_by_type()

static uint blob_length_by_type ( enum_field_types  type)
static

maximum possible length for certain blob types.

Parameters
[in]typeBlob type (e.g. MYSQL_TYPE_TINY_BLOB)
Returns
length

◆ build_table_filename()

size_t build_table_filename ( char *  buff,
size_t  bufflen,
const char *  db,
const char *  table_name,
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.

◆ calculate_field_offsets()

static void calculate_field_offsets ( List< Create_field > *  create_list)
static

◆ check_duplicate_key()

static bool check_duplicate_key ( THD thd,
const char *  error_schema_name,
const char *  error_table_name,
const KEY key,
const KEY key_info,
uint  key_count,
Alter_info alter_info 
)
static

Check if there is a duplicate key.

Report a warning for every duplicate key.

Parameters
thdThread context.
error_schema_nameSchema name of the table used for error reporting.
error_table_nameTable name used for error reporting.
keyKey to be checked.
key_infoArray with all keys for the table.
key_countNumber of keys in the table.
alter_infoAlter_info structure describing ALTER TABLE.
Note
Unlike has_index_def_changed() and similar code in mysql_compare_tables() this function compares KEY objects for the same table/created by the same mysql_prepare_create(). Hence difference in field number comparison. We also differentiate UNIQUE and PRIMARY keys.
Return values
falseOk.
trueError.

◆ check_duplicates_in_interval()

static bool check_duplicates_in_interval ( THD thd,
const char *  set_or_name,
const char *  name,
TYPELIB typelib,
const CHARSET_INFO cs,
uint *  dup_val_count 
)
static

◆ check_engine()

static bool check_engine ( const char *  db_name,
const char *  table_name,
HA_CREATE_INFO create_info 
)
static

Check if the table can be created in the specified storage engine.

Checks if the storage engine is enabled and supports the given table type (e.g. normal, temporary, system). May do engine substitution if the requested engine does not support temporary tables.

Parameters
db_nameDatabase name.
table_nameName of table to be created.
create_infoCreate info from parser, including engine.
Return values
trueEngine not available/supported, error has been reported.
falseEngine available/supported.

◆ check_fk_children_after_parent_def_change() [1/2]

static bool check_fk_children_after_parent_def_change ( THD thd,
const char *  parent_table_db,
const char *  parent_table_name,
const char *  old_parent_table_db,
const char *  old_parent_table_name,
handlerton hton,
const dd::Table parent_table_def 
)
static

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

Parameters
thdThread handle.
parent_table_dbParent table schema name.
parent_table_nameParent table name.
old_parent_table_dbOld parent table schema name, if table is renamed.
old_parent_table_nameOld parent table name, if table is renamed.
htonHandlerton for table's storage engine.
parent_table_defTable object representing the parent table.
Return values
operationoutcome, false if no error.

◆ check_fk_children_after_parent_def_change() [2/2]

static bool check_fk_children_after_parent_def_change ( THD thd,
const char *  parent_table_db,
const char *  parent_table_name,
handlerton hton,
const dd::Table old_parent_table_def,
const dd::Table new_parent_table_def,
Alter_info parent_alter_info 
)
static

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

Parameters
thdThread handle.
parent_table_dbParent table schema name.
parent_table_nameParent table name.
htonHandlerton for tables' storage engine.
old_parent_table_defTable object representing the old version of parent table.
new_parent_table_defTable object representing the new version of parent table.
parent_alter_infoAlter_info containing information about renames of parent columns.
Return values
operationoutcome, false if no error.

◆ check_fk_names_before_rename()

static bool check_fk_names_before_rename ( THD thd,
Table_ref table_list,
const dd::Table table_def,
handlerton hton,
const dd::Schema new_schema,
const Alter_table_ctx alter_ctx 
)
static

Check if complex ALTER TABLE with RENAME clause results in foreign key names conflicts.

Parameters
thdThread handle.
table_listTable list element for table altered.
table_defdd::Table object describing new version of table prior to rename operation.
htonTable's storage engine.
new_schemadd::Schema object for target schema.
alter_ctxALTER TABLE operation context.
Return values
Trueif error (e.g. due to foreign key name conflict), false - otherwise.

◆ check_if_field_used_by_generated_column_or_default()

static bool check_if_field_used_by_generated_column_or_default ( TABLE table,
const Field field,
const Alter_info alter_info 
)
static

Check if the column being removed or renamed is in use by a generated column, default or functional index, which will be kept around/unchanged by this ALTER TABLE, and report error which is appropriate for the case.

Parameters
tableTABLE object describing old table version.
fieldField object for column to be checked.
alter_infoAlter_info describing which columns, defaults or indexes are dropped or modified.
Returns
true The field is used by generated column/default or functional index, error was reported. false Otherwise.

◆ check_if_field_used_by_partitioning_func()

static bool check_if_field_used_by_partitioning_func ( TABLE table,
const Field field,
const Alter_info alter_info 
)
static

Check if the column being removed or renamed is in use by partitioning function for the table and that the partitioning is kept/partitioning function is unchanged by this ALTER TABLE, and report error if it is the case.

Parameters
tableTABLE object describing old table version.
fieldField object for column to be checked.
alter_infoAlter_info describing the ALTER TABLE.
Returns
true The field is used by partitioning function, error was reported. false Otherwise.

◆ check_if_keyname_exists()

static bool check_if_keyname_exists ( const char *  name,
KEY start,
KEY end 
)
static

◆ check_if_table_exists()

static Table_exists_result check_if_table_exists ( THD thd,
const char *  schema_name,
const char *  table_name,
const char *  alias,
bool  ha_lex_create_tmp_table,
bool  ha_create_if_not_exists,
bool  internal_tmp_table 
)
static

Check if table already exists.

Parameters
thdthread handle
schema_nameschema name.
table_nametable name.
aliasalt representation of table_name.
ha_lex_create_tmp_tabletrue if creating a tmp table.
ha_create_if_not_existstrue if this is CREATE IF NOT EXISTS.
internal_tmp_tabletrue if this is an internal tmp table.
Returns
false if successful, true otherwise.

◆ check_promoted_index()

static bool check_promoted_index ( const handler file,
const KEY key_info_buffer,
uint  key_count 
)
static

Primary/unique key check.

Checks that:

  • If the storage engine requires it, that there is an index that is candidate for promotion.
  • If such a promotion occurs, checks that the candidate index is not declared invisible.
Parameters
fileThe storage engine handler.
key_info_bufferAll indexes in the table.
key_countNumber of indexes.
Return values
falseOK.
trueAn error occurred and my_error() was called.

◆ check_table_has_col_compatible_with_fk_ref_col()

static bool check_table_has_col_compatible_with_fk_ref_col ( const dd::Table parent_table_def,
const dd::Foreign_key fk,
const dd::Foreign_key_element fk_el,
handlerton hton 
)
static

Check if foreign key's parent table has a column compatible with foreign key's referenced column.

Parameters
[in]parent_table_defData-dictionary object for parent table.
[in]fkData-dictionary object for foreign key.
[in]fk_elData-dictionary object for foreign key element.
[in]htonHandlerton for table's storage engine.
Return values
falseSuccess.
trueFailure.

◆ collect_and_lock_fk_tables_for_complex_alter_table()

static bool collect_and_lock_fk_tables_for_complex_alter_table ( THD thd,
Table_ref table_list,
const dd::Table old_table_def,
const Alter_table_ctx alter_ctx,
const Alter_info alter_info,
handlerton old_hton,
handlerton new_hton,
Foreign_key_parents_invalidator fk_invalidator 
)
static

Acquire exclusive metadata locks on tables which definitions need to be updated or invalidated due to foreign keys created or dropped as result of complex ALTER TABLE operation.

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

Parameters
thdThread handle.
table_listTable list element for table being ALTERed.
old_table_defOld table definition of table being ALTERed.
alter_ctxALTER TABLE operation context.
alter_infoAlter_info object with the lists of FKs to be added or dropped.
old_htonTable's old SE.
new_htonTable's new SE.
[in,out]fk_invalidatorObject keeping track of which dd::Table objects to invalidate.
Return values
operationoutcome, false if no error.

◆ 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() [1/2]

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_children() [2/2]

static bool collect_fk_children ( THD thd,
const dd::Table table_def,
enum_mdl_type  lock_type,
MDL_request_list mdl_requests 
)
static

Add MDL requests for specified lock type on all tables referencing the given table.

Parameters
thdThread handle.
table_defdd::Table object describing the table.
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()

static bool collect_fk_names ( THD thd,
const char *  db,
const dd::Table table_def,
MDL_request_list mdl_requests 
)
static

Add MDL requests for exclusive lock on all foreign key names on the given table to the list.

Parameters
thdThread context.
dbTable's schema name.
table_defTable definition.
[in,out]mdl_requestsList to which MDL requests are to be added.
Return values
operationoutcome, false if no error.

◆ collect_fk_names_for_dropped_fks()

static bool collect_fk_names_for_dropped_fks ( THD thd,
const char *  db,
const Alter_info alter_info,
const dd::Table table_def,
MDL_request_list mdl_requests 
)
static

Add MDL requests for exclusive lock on names of the foreign keys to be dropped by ALTER TABLE operation to the lock requests list.

Parameters
thdThread context.
dbTable's database before ALTER TABLE operation.
alter_infoAlter_info object with the list of FKs to be dropped.
table_defdd::Table describing the table before ALTER operation.
[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_names_for_rename_table()

static bool collect_fk_names_for_rename_table ( THD thd,
const char *  db,
const char *  table_name,
const dd::Table table_def,
handlerton hton,
const char *  new_db,
const char *  new_table_name,
MDL_request_list mdl_requests 
)
static

Add appropriate MDL requests on names of foreign keys on the table to be renamed to the requests list.

Parameters
thdThread handle.
dbTable's old schema.
table_nameTable's old name.
table_defTable definition of table being RENAMEd.
htonTable's storage engine.
new_dbTable's new schema.
new_table_nameTable's new name.
[in,out]mdl_requestsList to which MDL requests need to be added.
Return values
operationoutcome, false if no error.

◆ collect_fk_parents_for_all_fks()

static bool collect_fk_parents_for_all_fks ( THD thd,
const dd::Table table_def,
handlerton hton,
enum_mdl_type  lock_type,
MDL_request_list mdl_requests,
Foreign_key_parents_invalidator fk_invalidator 
)
static

Add MDL requests for specified lock type on all tables referenced by the given dd::Table object to the list.

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.
table_defdd::Table object.
lock_typeType of MDL requests to add.
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.

◆ collect_fk_parents_for_dropped_fks()

static bool collect_fk_parents_for_dropped_fks ( THD thd,
const Alter_info alter_info,
const dd::Table table_def,
handlerton hton,
MDL_request_list mdl_requests,
Foreign_key_parents_invalidator fk_invalidator 
)
static

Add MDL requests for exclusive lock on tables referenced by the foreign keys to be dropped by 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.
alter_infoAlter_info object with the list of FKs to be dropped.
table_defdd::Table describing the table before ALTER operation.
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.

◆ 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.

◆ column_exists_in_create_list()

static bool column_exists_in_create_list ( const char *  column_name,
List< Create_field > &  create_list 
)
static

Check if the given column exists in the create list.

Parameters
column_namethe column name to look for.
create_listthe create list where the search is performed.
Return values
truethe column exists in the create list.
falsethe column does not exist in the create list.

◆ column_name_exists()

static bool column_name_exists ( const List< Create_field > &  fields,
const string &  column_name 
)
static

Checks if a column with the given name exists in a list of fields.

◆ copy_data_between_tables()

static int copy_data_between_tables ( THD thd,
PSI_stage_progress psi,
TABLE from,
TABLE to,
List< Create_field > &  create,
ha_rows copied,
ha_rows deleted,
Alter_info::enum_enable_or_disable  keys_onoff,
Alter_table_ctx alter_ctx 
)
static

◆ count_keys()

static bool count_keys ( const Mem_root_array< Key_spec * > &  key_list,
uint *  key_count,
uint *  key_parts,
uint *  fk_key_count,
Mem_root_array< bool > *  redundant_keys,
handler::Table_flags  se_index_flags 
)
static

Count keys and key segments.

Note that FKs are ignored. Also mark redundant keys to be ignored.

Parameters
[in,out]key_listList of keys to count and possibly mark as ignored.
[out]key_countReturned number of keys counted (excluding FK).
[out]key_partsReturned number of key segments (excluding FK).
[out]fk_key_countReturned number of foreign keys.
[in,out]redundant_keysArray where keys to be ignored will be marked.
[in]se_index_flagsStorage's flags for index support

◆ create_table_impl()

static bool create_table_impl ( THD thd,
const dd::Schema schema,
const char *  db,
const char *  table_name,
const char *  error_table_name,
const char *  path,
HA_CREATE_INFO create_info,
Alter_info alter_info,
bool  internal_tmp_table,
uint  select_field_count,
bool  find_parent_keys,
bool  no_ha_table,
bool  do_not_store_in_dd,
bool *  is_trans,
KEY **  key_info,
uint *  key_count,
Alter_info::enum_enable_or_disable  keys_onoff,
FOREIGN_KEY **  fk_key_info,
uint *  fk_key_count,
FOREIGN_KEY existing_fk_info,
uint  existing_fk_count,
const dd::Table existing_fk_table,
uint  fk_max_generated_name_number,
std::unique_ptr< dd::Table > *  table_def,
handlerton **  post_ddl_ht 
)
static

Create a table.

Parameters
thdThread object
schemaDD schema object
dbDatabase
table_nameTable name
error_table_nameThe real table name in case table_name is a temporary table (ALTER). Used for error messages and for checking whether the table is a white listed system table.
pathPath to table (i.e. to its .FRM file without the extension).
create_infoCreate information (like MAX_ROWS)
alter_infoDescription of fields and keys for new table
internal_tmp_tableSet to true if this is an internal temporary table (From ALTER TABLE)
select_field_countNumber of fields coming from SELECT part of CREATE TABLE ... SELECT statement. Must be zero for standard create of table.
find_parent_keysIndicates whether we need to lookup name of unique constraint in parent table for foreign keys.
no_ha_tableIndicates that only .FRM file (and PAR file if table is partitioned) needs to be created and not a table in the storage engine.
do_not_store_in_ddIndicates that we should postpone storing table object in the data-dictionary. Requires SE supporting atomic DDL and no_ha_table flag set.
[out]is_transIdentifies the type of engine where the table was created: either trans or non-trans.
[out]key_infoArray of KEY objects describing keys in table which was created.
[out]key_countNumber of keys in table which was created.
keys_onoffEnable or disable keys.
[out]fk_key_infoArray of FOREIGN_KEY objects describing foreign keys in table which was created.
[out]fk_key_countNumber of foreign keys in table which was created.
[in]existing_fk_infoArray of FOREIGN_KEY objects for foreign keys which already existed in the table (in case of ALTER TABLE).
[in]existing_fk_countNumber of pre-existing foreign keys.
[in]existing_fk_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.
[out]table_defData-dictionary object describing the table created if do_not_store_in_dd option was used or because the table is temporary and was not open due to no_ha_table. Not set otherwise.
[out]post_ddl_htSet to handlerton for table's SE, if this SE supports atomic DDL, so caller can call SE post DDL hook after committing transaction.

If one creates a temporary table, this is automatically opened

Note that this function assumes that caller already have taken exclusive metadata lock on table being created or used some other way to ensure that concurrent operations won't intervene. mysql_create_table() is a wrapper that can be used for this.

Note
On failure, for engines supporting atomic DDL, the caller must rollback statement and transaction before doing anything else.
Return values
falseOK
trueerror

◆ create_typelib()

TYPELIB * create_typelib ( MEM_ROOT mem_root,
Create_field field_def 
)

◆ drop_base_table()

static bool drop_base_table ( THD thd,
const Drop_tables_ctx drop_ctx,
Table_ref table,
bool  atomic,
std::set< handlerton * > *  post_ddl_htons,
Foreign_key_parents_invalidator fk_invalidator,
std::vector< MDL_ticket * > *  safe_to_release_mdl,
MEM_ROOT foreach_table_root 
)
static

Auxiliary function which drops single base table.

Parameters
thdThread handler.
drop_ctxDROP TABLES runtime context.
tableTable to drop.
atomicIndicates whether table to be dropped is in SE which supports atomic DDL, so changes to the data-dictionary should not be committed.
[in,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.
[in,out]fk_invalidatorObject keeping track of which dd::Table objects need to be invalidated since the correspond to the parent tables for FKs on a table being dropped.
[in,out]safe_to_release_mdlUnder LOCK TABLES set of metadata locks on tables dropped which is safe to release after DROP operation.
foreach_table_rootMEM_ROOT which can be used for allocating objects which lifetime is limited to dropping of single table.
See also
mysql_rm_table_no_locks().
Return values
False- ok
True- error

◆ 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

◆ fetch_fk_children_uncached_uncommitted_normalized()

static bool fetch_fk_children_uncached_uncommitted_normalized ( THD thd,
const char *  parent_schema,
const char *  parent_name,
const char *  parent_engine,
Normalized_fk_children fk_children 
)
static

Fetch names of all tables having a FK referring to the given table.

Parameters
thdThread handle.
parent_schemaSchema name of the referenced table.
parent_nameName of the referenced table.
parent_engineName of the referenced table's storage engine.
[out]fk_childrenSet of unique schema qualified names of tables referring the given parent.

The children are fetched from the DD tables using uncommitted read. The names are normalized, i.e., if l_c_t_n == 2, the names are lowercased.

Return values
operationoutcome, false if no error.

◆ filename_to_tablename()

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

◆ fill_alter_inplace_info()

static bool fill_alter_inplace_info ( THD thd,
TABLE table,
Alter_inplace_info ha_alter_info 
)
static

Compare original and new versions of a table and fill Alter_inplace_info describing differences between those versions.

Parameters
thdThread
tableThe original table.
[in,out]ha_alter_infoData structure which already contains basic information about create options, field and keys for the new version of table and which should be completed with more detailed information needed for in-place ALTER.

First argument 'table' contains information of the original table, which includes all corresponding parts that the new table has in arguments create_list, key_list and create_info.

Compare the changes between the original and new table definitions. The result of this comparison is then passed to SE which determines whether it can carry out these changes in-place.

Mark any changes detected in the ha_alter_flags. We generally try to specify handler flags only if there are real changes. But in cases when it is cumbersome to determine if some attribute has really changed we might choose to set flag pessimistically, for example, relying on parser output only.

If there are no data changes, but index changes, 'index_drop_buffer' and/or 'index_add_buffer' are populated with offsets into table->key_info or key_info_buffer respectively for the indexes that need to be dropped and/or (re-)created.

Note that this function assumes that it is OK to change Alter_info and HA_CREATE_INFO which it gets. It is caller who is responsible for creating copies for this structures if he needs them unchanged.

Return values
trueerror
falsesuccess

◆ fill_ha_fk_column_type() [1/2]

static void fill_ha_fk_column_type ( Ha_fk_column_type fk_column_type,
const Create_field field 
)
static

Helper which builds Ha_fk_column_type describing column type from its Create_field object.

See also
fill_dd_columns_from_create_fields().

◆ fill_ha_fk_column_type() [2/2]

static bool fill_ha_fk_column_type ( Ha_fk_column_type fk_column_type,
const dd::Column column 
)
static

Helper which builds Ha_fk_column_type describing column type from its dd::Column object.

◆ find_fk_supporting_key() [1/2]

static const KEY * find_fk_supporting_key ( handlerton hton,
Alter_info alter_info,
const KEY key_info_buffer,
const uint  key_count,
const FOREIGN_KEY fk 
)
static

Find supporting key for the foreign key.

Parameters
htonHandlerton for table's storage engine.
alter_infoAlter_info object describing child table.
key_info_bufferArray describing keys in child table.
key_countNumber of keys in child table.
fkFOREIGN_KEY object describing the FK.
See also
find_fk_supporting_key(handlerton*, const dd::Table*, const dd::Foreign_key*)
Return values
non-nullptr- pointer to KEY object describing supporting key.
nullptr- if no supporting key were found.

◆ find_fk_supporting_key() [2/2]

static const dd::Index * find_fk_supporting_key ( handlerton hton,
const dd::Table table_def,
const dd::Foreign_key fk 
)
static

Find supporting key for the foreign key.

Parameters
htonHandlerton for tables' storage engine. Used to figure out what kind of supporting keys are allowed by the storage engine.
table_defdd::Table object describing the child table.
fkdd::Foreign_key object describing the foreign key.
See also
find_fk_supporting_key(handlerton*, Alter_info*, const KEY*, uint, const FOREIGN_KEY*)
Return values
non-nullptr- pointer to dd::Index object describing supporting key.
nullptr- if no supporting key were found.

◆ find_key_ci()

static KEY * find_key_ci ( const char *  key_name,
KEY key_start,
KEY key_end 
)
static

Look-up KEY object by index name using case-insensitive comparison.

Parameters
key_nameIndex name.
key_startStart of array of KEYs for table.
key_endEnd of array of KEYs for table.
Note
Skips indexes which are marked as renamed.
Case-insensitive comparison is necessary to correctly handle renaming of keys.
Return values
non-NULL- pointer to KEY object for index found.
NULL- no index with such name found (or it is marked as renamed).

◆ find_key_cs()

static KEY * find_key_cs ( const char *  key_name,
KEY key_start,
KEY key_end 
)
static

Look-up KEY object by index name using case-sensitive comparison.

Parameters
key_nameIndex name.
key_startStart of array of KEYs for table.
key_endEnd of array of KEYs for table.
Note
Skips indexes which are marked as renamed.
Case-sensitive comparison is necessary to correctly handle: ALTER TABLE t1 DROP KEY x, ADD KEY X(c). where new and old index are identical except case of their names (in this case index still needs to be re-created to keep case of the name in .FRM and storage-engine in sync).
Return values
non-NULL- pointer to KEY object for index found.
NULL- no index with such name found (or it is marked as renamed).

◆ fk_check_column_changes()

template<class F >
static fk_column_change_type fk_check_column_changes ( THD thd,
Alter_info alter_info,
uint  fk_col_count,
const F &  fk_columns,
const char **  bad_column_name 
)
static

Check that ALTER TABLE's changes on columns of a foreign key are allowed.

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check ALTER TABLE that changes parent or child table) column name by its index.
Parameters
[in]thdThread context.
[in]alter_infoAlter_info describing changes to be done by ALTER TABLE.
[in]fk_col_countNumber of columns in the foreign key.
[in]fk_columnsObject of F type bound to the specific foreign key for which check is carried out.
[out]bad_column_nameName of field on which ALTER TABLE tries to do prohibited operation.
Note
This function takes into account value of @foreign_key_checks setting.
Return values
FK_COLUMN_NO_CHANGENo significant changes are to be done on foreign key columns.
FK_COLUMN_DATA_CHANGEALTER TABLE might result in value change in foreign key column (and foreign_key_checks is on).
FK_COLUMN_RENAMEDForeign key column is renamed.
FK_COLUMN_DROPPEDForeign key column is dropped.

◆ fk_check_copy_alter_table()

static bool fk_check_copy_alter_table ( THD thd,
Table_ref table_list,
const dd::Table table_def,
Alter_info alter_info 
)
static

Check if ALTER TABLE we are about to execute using COPY algorithm is not supported as it might break referential integrity.

Note
If foreign_key_checks is disabled (=0), we allow to break referential integrity. But we still disallow some operations like dropping or renaming columns in foreign key since they are likely to break consistency of InnoDB data-dictionary and thus will end-up in error anyway.
Parameters
[in]thdThread context.
[in]table_listTable_ref element for the table to be altered.
[in]table_defdd::Table for old version of table to be altered.
[in]alter_infoLists of fields, keys to be changed, added or dropped.
Return values
falseSuccess.
trueError, ALTER - tries to do change which is not compatible with foreign key definitions on the table.

◆ fk_is_key_exact_match_any_order() [1/2]

template<class F >
static bool fk_is_key_exact_match_any_order ( Alter_info alter_info,
uint  fk_col_count,
const F &  fk_columns,
const KEY key 
)
static

Check if candidate parent/supporting key contains exactly the same columns as the foreign key, possibly, in different order.

Also check that columns usage by key is acceptable, i.e. key is not over column prefix.

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index.
Parameters
alter_infoAlter_info describing columns in parent or child table.
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent/supporting key check is carried out.
keyKEY object describing candidate parent/supporting key.
See also
fk_is_key_exact_match_any_order(uint, F, dd::Index).
Return values
True- Key is proper parent/supporting key for the foreign key.
False- Key can't be parent/supporting key for the foreign key.

◆ fk_is_key_exact_match_any_order() [2/2]

template<class F >
static bool fk_is_key_exact_match_any_order ( uint  fk_col_count,
const F &  fk_columns,
const dd::Index idx 
)
static

Check if candidate parent/supporting key contains exactly the same columns as the foreign key, possibly, in different order.

Also check that columns usage by key is acceptable, i.e. key is not over column prefix.

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index.
Parameters
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent/supporting key check is carried out.
idxdd::Index object describing candidate parent/ supporting key.
See also
fk_is_key_exact_match_any_order(Alter_info, uint, F, KEY).
Return values
True- Key is proper parent/supporting key for the foreign key.
False- Key can't be parent/supporting key for the foreign key.

◆ fk_key_is_full_prefix_match() [1/2]

template<class F >
static bool fk_key_is_full_prefix_match ( Alter_info alter_info,
uint  fk_col_count,
const F &  fk_columns,
const KEY key,
const KEY hidden_cols_key 
)
static

Check if candidate parent/supporting key contains all columns from the foreign key at its start and in the same order it is in the foreign key.

Also check that columns usage by key is acceptable, i.e. key is not over column prefix.

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index.
Parameters
alter_infoAlter_info describing columns in parent or child table.
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent/supporting key check is carried out.
keyKEY object describing candidate parent/supporting key.
hidden_cols_keyIf non-nullptr, points to KEY object representing primary key for the table, which columns are added to the candidate parent key and should be taken into account when considering this parent key.
See also
fk_key_is_full_prefix_match(uint, F, dd::Index, bool).
Return values
True- Key is proper parent/supporting key for the foreign key.
False- Key can't be parent/supporting key for the foreign key.

◆ fk_key_is_full_prefix_match() [2/2]

template<class F >
static bool fk_key_is_full_prefix_match ( uint  fk_col_count,
const F &  fk_columns,
const dd::Index idx,
bool  use_hidden 
)
static

Check if candidate parent/supporting key contains all columns from the foreign key at its start and in the same order it is in the foreign key.

Also check that columns usage by key is acceptable, i.e. key is not over column prefix.

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index.
Parameters
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent/supporting key check is carried out.
idxdd::Index object describing candidate parent/ supporting key.
use_hiddenUse hidden elements of the key as well.
See also
fk_key_is_full_prefix_match(Alter_info, uint, F, KEY, KEY).
Return values
True- Key is proper parent/supporting key for the foreign key.
False- Key can't be parent/supporting key for the foreign key.

◆ fk_key_prefix_match_count() [1/2]

template<class F >
static uint fk_key_prefix_match_count ( Alter_info alter_info,
uint  fk_col_count,
const F &  fk_columns,
const KEY key,
const KEY hidden_cols_key 
)
static

Count how many elements from the start of the candidate parent/supporting key match elements at the start of the foreign key (prefix parts are considered non-matching).

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index.
Parameters
alter_infoAlter_info describing columns in parent or child table.
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent/supporting key check is carried out.
keyKEY object describing candidate parent/supporting key.
hidden_cols_keyIf non-nullptr, points to KEY object representing primary key for the table, which columns are added to the candidate parent key and should be taken into account when considering this parent key.
See also
fk_key_prefix_match_count(uint, F, dd::Index, bool).
Return values
Numberof matching columns.

◆ fk_key_prefix_match_count() [2/2]

template<class F >
static uint fk_key_prefix_match_count ( uint  fk_col_count,
const F &  fk_columns,
const dd::Index idx,
bool  use_hidden 
)
static

Count how many elements from the start of the candidate parent/supporting key match elements at the start of the foreign key (prefix parts are considered non-matching).

Template Parameters
FFunction class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index.
Parameters
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent/supporting key check is carried out.
idxdd::Index object describing candidate parent/ supporting key.
use_hiddenUse hidden elements of the key as well.
See also
fk_key_prefix_match_count(Alter_info, uint, F, KEY, KEY).
Return values
Numberof matching columns.

◆ generate_check_constraint_name()

static bool generate_check_constraint_name ( THD thd,
const char *  table_name,
uint  ordinal_number,
LEX_STRING name,
bool  skip_validation 
)
static

Helper method to generate check constraint name.

Parameters
thdThread handle.
table_nameTable name.
ordinal_numberOrdinal number of the generated name.
[out]nameLEX_STRING instance to hold the generated check constraint name.
skip_validationSkip generated name validation.

◆ generate_fk_name() [1/2]

static void generate_fk_name ( char *  name_buff,
size_t  name_buff_size,
const char *  table_name,
handlerton hton,
uint *  fk_max_generated_name_number 
)
static

Generate a foreign key name and store it in buffer provided.

Note
Foreign key names have to be unique for a given schema. This function is used when the user has not specified neither constraint name nor foreign key name.
We generated names according to the pattern: (table name)(SE-specific or default FK name suffix)(counter) The counter is 1-based and per table. The number chosen for the counter is 1 higher than the highest number currently in use. For InnoDB "_ibfk_" is used as suffix, so names are compatible with names generated by InnoDB in 5.7. For NDB, suffix "_fk_" is used and compatibility is not preserved (as in 5.7 NDB uses radically different approach anyway).
Parameters
name_buffBuffer for generated name.
name_buff_sizeSize of name buffer, if buffer is too small generated name will be truncated.
table_nameTable name.
htonTable storage engine.
[in,out]fk_max_generated_name_numberMax value of number component among existing generated foreign key names.

◆ generate_fk_name() [2/2]

static const char * generate_fk_name ( const char *  table_name,
handlerton hton,
uint *  fk_max_generated_name_number 
)
static

Generate a foreign key name, allocate memory from thread's current memory root for it.

Note
Foreign key names have to be unique for a given schema. This function is used when the user has not specified neither constraint name nor foreign key name.
We generated names according to the pattern: (table name)(SE-specific or default FK name suffix)(counter) The counter is 1-based and per table. The number chosen for the counter is 1 higher than the highest number currently in use. For InnoDB "_ibfk_" is used as suffix, so names are compatible with names generated by InnoDB in 5.7. For NDB, suffix "_fk_" is used and compatibility is not preserved (as in 5.7 NDB uses radically different approach anyway).
Parameters
table_nameTable name.
htonTable storage engine.
[in,out]fk_max_generated_name_numberMax value of number component among existing generated foreign key names.
Return values
Generatedname

◆ get_field_by_index()

static const Create_field * get_field_by_index ( Alter_info alter_info,
uint  idx 
)
static

Get Create_field object for newly created table by field index.

Parameters
alter_infoAlter_info describing newly created table.
idxField index.

◆ get_field_by_old_name()

static const Create_field * get_field_by_old_name ( Alter_info alter_info,
const char *  old_name 
)
static

Get Create_field object for newly created table by its name in the old version of table.

Parameters
alter_infoAlter_info describing newly created table.
old_nameName of field in old table.
Returns
Pointer to Create_field object, NULL - if field is not present in new version of table.

◆ get_fk_max_generated_name_number()

static uint get_fk_max_generated_name_number ( const char *  table_name,
const dd::Table table_def,
handlerton hton 
)
static

Find max value of number component among existing generated foreign key names for the table.

Parameters
table_nameTable name (should be already in lowercase if l_c_t_n > 0).
table_defTable definition.
htonTable storage engine.
Note
We assume that generated names follow pattern: (table name)(SE-specific or default FK name suffix)(number) E.g. "table_name_ibfk_####" for InnoDB. This function is in sync with generate_fk_name() and dd::rename_foreign_keys().
This function mimics dict_table_get_highest_foreign_id() from 5.7.

◆ 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).

◆ handle_drop_functional_index()

static bool handle_drop_functional_index ( THD thd,
Alter_info alter_info,
Table_ref table_list 
)
static

This function will check if we are dropping a functional index.

In that case, the function will add any related hidden generated columns to the drop list as well.

Parameters
thdThread handler
alter_infoThe changes to be carried out
table_listThe current table reference
Return values
trueon error (my_error is already called)
falseon success

◆ handle_rename_functional_index()

static bool handle_rename_functional_index ( THD thd,
Alter_info alter_info,
Table_ref table_list 
)
static

This function will check if we are renaming a functional index.

In that case, the function will add a "change column" operation to the create list that renames any affected hidden generated column(s). The reason is that the hidden generated column name is generated by MD5(key name + key part number), so a change in the index name will change the name of the column.

Parameters
thdthread handler
alter_infothe changes to be carried out.
table_lista reference to the current table
Return values
trueOOM
falsesuccess

◆ has_index_def_changed()

static bool has_index_def_changed ( Alter_inplace_info ha_alter_info,
const KEY table_key,
const KEY new_key 
)
static

Check if index has changed in a new version of table (ignore possible rename of index).

Also changes to the comment field of the key is marked with a flag in the ha_alter_info.

Parameters
[in,out]ha_alter_infoStructure describing changes to be done by ALTER TABLE and holding data used during in-place alter.
table_keyDescription of key in old version of table.
new_keyDescription of key in new version of table.
Returns
True - if index has changed, false -otherwise.

◆ is_alter_geometry_column_valid()

static bool is_alter_geometry_column_valid ( Alter_info alter_info)
static

Check if we are changing the SRID specification on a geometry column that has a spatial index.

If that is the case, reject the change since allowing geometries with different SRIDs in a spatial index will make the index useless.

Parameters
alter_infoStructure describing the changes to be carried out.
Return values
trueif all of the geometry columns can be altered/changed as requested
falseif the change is considered invalid

◆ is_any_check_constraints_evaluation_required()

static bool is_any_check_constraints_evaluation_required ( const Alter_info alter_info)
static

Helper method to check if any check constraints (re-)evaluation is required.

If any check constraint re-evaluation is required then in-place alter is not possible as it is done in the SQL-layer. This method is called by is_inplace_alter_impossible() to check inplace alter is possible.

Check constraint (re-)evaluation is required when 1) New check constraint is added in ENFORCED state. 2) Any existing check constraint is ENFORCED. 3) Type of column used by any enforced check constraint is changed. 4) check constraints expression depends on DEFAULT function on a column and default is changed as part of alter operation.

Parameters
alter_infoData related to detected changes.
Return values
trueCheck constraint (re-)evaluation required.
falseOtherwise.

◆ is_candidate_key()

static bool is_candidate_key ( KEY key)
static

Check if key is a candidate key, i.e.

a unique index with no index fields partial, nullable or virtual generated.

◆ is_field_part_of_index()

static bool is_field_part_of_index ( const Field field,
const Create_field new_field,
Alter_inplace_info ha_alter_info 
)
static

Scan the indexes of the new table (including the added ones), and check if the field is referred by any index.

Parameters
fieldField in old table.
new_fieldField in new table (create field).
ha_alter_infoAlter inplace info structure.
Return values
trueField changes collation, and is indexed.
falseOtherwise.

◆ is_field_part_of_partition_expression()

static bool is_field_part_of_partition_expression ( const Field field,
Alter_inplace_info ha_alter_info 
)
static

Scan the fields used in partition expressions of the new table (including the added ones), and check if the field is used by a partitioning expression.

◆ is_inplace_alter_impossible()

static bool is_inplace_alter_impossible ( TABLE table,
HA_CREATE_INFO create_info,
const Alter_info alter_info 
)
static

Check if the pending ALTER TABLE operations support the in-place algorithm based on restrictions in the SQL layer or given the nature of the operations themselves.

If in-place isn't supported, it won't be necessary to check with the storage engine.

Parameters
tableThe original TABLE.
create_infoInformation from the parsing phase about new table properties.
alter_infoData related to detected changes.
Returns
false In-place is possible, check with storage engine.
true Incompatible operations, must use table copy.

◆ is_json_pk_on_external_table()

static bool is_json_pk_on_external_table ( const uint32  flags,
const keytype  keytype,
const enum_field_types  sql_type 
)
inlinestatic

Helper function which checks if external table has primary key on JSON column.

◆ is_not_slave_or_master_sorts_functional_index_columns_last()

static bool is_not_slave_or_master_sorts_functional_index_columns_last ( uint32_t  master_version)
static

Whether or not we have a replication setup, and the master sorts functional index columns last in the table.

Sorting said columns last was introduced in version 8.0.18, and this function helps us keep consistent behavior in a OLD->NEW replication setup.

Returns
false if we have a replication setup, and the server is on a old version that doesn't sort functional index columns last.

◆ is_phony_blob()

static bool is_phony_blob ( enum_field_types  sql_type,
uint  decimals 
)
static

Helper function which allows to detect column types for which we historically used key packing (optimization implemented only by MyISAM) under erroneous assumption that they have BLOB type.

◆ is_simple_rename_or_index_change()

static bool is_simple_rename_or_index_change ( const Alter_info alter_info)
static

Check if ALTER TABLE in question is a simple ALTER TABLE RENAME or ALTER TABLE ENABLE/DISABLE KEYS.

Parameters
alter_infoAlter_info describing ALTER.

◆ key_name_exists()

static bool key_name_exists ( const Mem_root_array< Key_spec * > &  keys,
const std::string &  key_name,
const Key_spec key_to_ignore 
)
static

Check if the given key name exists in the array of keys.

The lookup is case insensitive.

Parameters
keysthe array to check for the key name in
key_namethe key name to look for.
key_to_ignorea pointer to the key we don't want to check against. This is used when checking for duplicate functional index names.
Return values
trueif the key name exists in the array
falseif the key name doesn't exist in the array

◆ 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

◆ make_functional_index_column_name()

static const char * make_functional_index_column_name ( std::string_view  key_name,
unsigned  key_part_number,
const List< Create_field > &  fields,
MEM_ROOT mem_root 
)
static

Create a name for the hidden generated column that represents the functional key part.

The name is a string on the form !hidden!index_name!key_part!counter. The counter is usually 0, but is incremented until a unique name is found, in the unlikely event that there is another column with the same name. The index_name part may be truncated to make sure the column name does not exceed the maximum column name length (NAME_CHAR_LEN).

Parameters
key_namethe name of the index.
key_part_numberthe key part number, starting from zero.
fieldsthe other columns in the table
mem_rootthe MEM_ROOT where the column name should be allocated.
Returns
the name for the hidden generated column, allocated on the supplied MEM_ROOT

◆ make_unique_key_name()

static const char * make_unique_key_name ( const char *  field_name,
KEY start,
KEY end 
)
static

◆ 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 tables,
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_inplace_alter_table()

static bool mysql_inplace_alter_table ( THD thd,
const dd::Schema schema,
const dd::Schema new_schema,
const dd::Table table_def,
dd::Table altered_table_def,
Table_ref table_list,
TABLE table,
TABLE altered_table,
Alter_inplace_info ha_alter_info,
enum_alter_inplace_result  inplace_supported,
Alter_table_ctx alter_ctx,
histograms::columns_set columns,
FOREIGN_KEY fk_key_info,
uint  fk_key_count,
Foreign_key_parents_invalidator fk_invalidator 
)
static

Perform in-place alter table.

Parameters
thdThread handle.
schemaSource schema.
new_schemaTarget schema.
table_defTable object for the original table.
altered_table_defTable object for the new version of the table.
table_listTable_ref for the table to change.
tableThe original TABLE.
altered_tableTABLE object for new version of the table.
ha_alter_infoStructure describing ALTER TABLE to be carried out and serving as a storage place for data used during different phases.
inplace_supportedEnum describing the locking requirements.
alter_ctxALTER TABLE runtime context.
columnsA list of columns to be modified. This is needed for removal/renaming of histogram statistics.
fk_key_infoArray of FOREIGN_KEY objects describing foreign keys in new table version.
fk_key_countNumber of foreign keys in new table version.
[out]fk_invalidatorSet of parent tables which participate in FKs together with table being altered and which entries in DD cache need to be invalidated.
Return values
trueError
falseSuccess
Note
If mysql_alter_table does not need to copy the table, it is either an alter table where the storage engine does not need to know about the change, only the frm will change, or the storage engine supports performing the alter table operation directly, in-place without mysql having to copy the table.
This function frees the TABLE object associated with the new version of the table and removes the .FRM file for it in case of both success and failure.

◆ 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_blob_field()

static bool prepare_blob_field ( THD thd,
Create_field sql_field,
bool  convert_character_set 
)
static

◆ prepare_check_constraints_for_alter()

static bool prepare_check_constraints_for_alter ( THD thd,
const TABLE table,
Alter_info alter_info,
Alter_table_ctx alter_tbl_ctx 
)
static

Method to prepare check constraints for the ALTER TABLE operation.

Method prepares check constraints specifications from the existing list of check constraints on the table, appends new check constraints to list, updates state (enforced/not enforced) and drop any existing check constraint from the list.

Parameters
thdThread handle.
tableTABLE instance of source table.
alter_infoAlter_info object to prepare list of check constraint spec for table being altered.
alter_tbl_ctxRuntime context for ALTER TABLE.
Return values
falseSuccess.
trueFailure.

◆ 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_check_constraints_for_create_like_table()

static bool prepare_check_constraints_for_create_like_table ( THD thd,
Table_ref src_table,
Table_ref target_table,
Alter_info alter_info 
)
static

Method to prepare check constraints for the CREATE TABLE LIKE operation.

If check constraints are defined on the source table then check constraints specifications are prepared for the table being created from it. To avoid name conflicts, names are generated for all the check constraints prepared for the table being created.

Parameters
thdThread handle.
src_tableTable_ref instance for source table.
target_tableTable_ref instance for target table.
alter_infoAlter_info instance to prepare list of check constraint spec for table being 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_enum_field()

static bool prepare_enum_field ( THD thd,
Create_field sql_field 
)
static

◆ 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 ( 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 
)

◆ prepare_foreign_key()

static bool prepare_foreign_key ( THD thd,
HA_CREATE_INFO create_info,
Alter_info alter_info,
const char *  db,
const char *  table_name,
bool  is_partitioned,
KEY key_info_buffer,
uint  key_count,
const FOREIGN_KEY fk_info_all,
uint  fk_number,
bool  se_supports_fks,
bool  find_parent_key,
Foreign_key_spec fk_key,
uint *  fk_max_generated_name_number,
FOREIGN_KEY fk_info 
)
static

Prepare FOREIGN_KEY struct with info about a foreign key.

Parameters
thdThread handle.
create_infoCreate info from parser.
alter_infoAlter_info structure describing ALTER TABLE.
dbDatabase name.
table_nameTable name.
is_partitionedIndicates whether table is partitioned.
key_info_bufferArray of indexes.
key_countNumber of indexes.
fk_info_allFOREIGN_KEY array with foreign keys which were already processed.
fk_numberNumber of foreign keys which were already processed.
se_supports_fksIndicates whether SE supports FKs. If not only basic FK validation is performed.
find_parent_keyIndicates whether we need to lookup name of unique constraint in parent table for the FK.
[in,out]fk_keyParser info about new FK to prepare.
[in,out]fk_max_generated_name_numberMax value of number component among existing generated foreign key names.
[out]fk_infoStruct to populate.
Return values
trueif error (error reported), false otherwise.

◆ prepare_key()

static bool prepare_key ( THD thd,
const char *  error_schema_name,
const char *  error_table_name,
HA_CREATE_INFO create_info,
List< Create_field > *  create_list,
const Key_spec key,
KEY **  key_info_buffer,
KEY key_info,
KEY_PART_INFO **  key_part_info,
Mem_root_array< const KEY * > &  keys_to_check,
uint  key_number,
const handler file,
int *  auto_increment 
)
static

◆ prepare_key_column()

static bool prepare_key_column ( THD thd,
HA_CREATE_INFO create_info,
List< Create_field > *  create_list,
const Key_spec key,
const Key_part_spec column,
const size_t  column_nr,
KEY key_info,
KEY_PART_INFO key_part_info,
const handler file,
int *  auto_increment,
const CHARSET_INFO **  ft_key_charset 
)
static

◆ 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_preexisting_foreign_key()

static bool prepare_preexisting_foreign_key ( THD thd,
HA_CREATE_INFO create_info,
Alter_info alter_info,
const char *  schema_name,
const char *  table_name,
KEY key_info,
uint  key_count,
const dd::Table existing_fks_table,
FOREIGN_KEY fk 
)
static

Check that pre-existing foreign key will be still valid after ALTER TABLE, i.e.

that table still has supporting index and types of child and parent columns are still compatible. Also if necessary check that there is parent index and update DD.UNIQUE_CONSTRAINT_NAME accordingly.

Parameters
thdThread context..
create_infoHA_CREATE_INFO describing table.
alter_infoAlter_info structure describing ALTER TABLE.
schema_nameTable schema name.
table_nameTable name.
key_infoArray of indexes.
key_countNumber of indexes.
existing_fks_tabledd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting.
[in,out]fkFOREIGN_KEY object describing pre-existing foreign key.
Return values
trueif error (error reported), false otherwise.

◆ prepare_preexisting_self_ref_foreign_key()

static bool prepare_preexisting_self_ref_foreign_key ( THD thd,
HA_CREATE_INFO create_info,
Alter_info alter_info,
KEY key_info,
uint  key_count,
const KEY supporting_key,
const dd::Table existing_fks_table,
FOREIGN_KEY fk,
const Prealloced_array< Create_field *, 1 > &  referencing_fields 
)
static

Check that pre-existing self-referencing foreign key or an orphan non-self-referencing foreign key become non-orphan/adopted self-referencing foreign key as a result of table rename operation will be valid after ALTER TABLE, i.e.

that table has parent index and types of child and parent columns are compatible. Also update DD.UNIQUE_CONSTRAINT_NAME accordingly.

Parameters
thdThread context..
create_infoHA_CREATE_INFO describing table.
alter_infoAlter_info structure describing table.
key_infoArray of indexes.
key_countNumber of indexes.
supporting_keySupporting key for the foreign key.
existing_fks_tabledd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting.
referencing_fieldsList of foreign key referencing fields.
[in,out]fkFOREIGN_KEY object describing pre-existing foreign key.
Return values
trueif error (error reported), false otherwise.

◆ prepare_self_ref_fk_parent_key()

static bool prepare_self_ref_fk_parent_key ( THD thd,
handlerton hton,
Alter_info alter_info,
const KEY key_info_buffer,
const uint  key_count,
const KEY supporting_key,
const dd::Table old_fk_table,
FOREIGN_KEY fk 
)
static

Check if parent key for self-referencing foreign key exists, set foreign key's unique constraint name accordingly.

Emit error if no parent key found.

Note
Prefer unique key if possible. If parent key is non-unique unique constraint name is set to NULL.
Explicitly skip the supporting index as a candidate parent index to maintain previous behavior for engines that require the two indexes to be different.
Parameters
thdThread handle.
htonHandlerton for table's storage engine.
alter_infoAlter_info object describing parent table.
key_info_bufferArray describing keys in parent table.
key_countNumber of keys in parent table.
supporting_keyPointer to KEY representing the supporting index.
old_fk_tabledd::Table object from which pre-existing FK comes from. nullptr if this FK is newly added.
[in,out]fkFOREIGN_KEY object describing the FK, its unique_index_name member will be updated if matching unique constraint is found.
Return values
Operationresult. False if success.

◆ prepare_set_field()

static bool prepare_set_field ( THD thd,
Create_field sql_field 
)
static

◆ 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.

◆ push_check_constraint_mdl_request_to_list()

static bool push_check_constraint_mdl_request_to_list ( THD thd,
const char *  db,
const char *  cc_name,
MDL_request_list cc_mdl_request_list 
)
static

Helper method to create MDL_request for check constraint names.

Check constraint names are case insensitive. Hence names are lowercased in MDL_request and pushed to MDL_request_list.

Parameters
thdThread handle.
dbDatabase name.
cc_nameCheck constraint name.
[out]cc_mdl_request_listMDL request list.
Return values
falseSuccess.
trueFailure.

◆ push_zero_date_warning()

static bool push_zero_date_warning ( THD thd,
Create_field datetime_field 
)
static

Report a zero date warning if no default value is supplied for the DATE/DATETIME 'NOT NULL' field and 'NO_ZERO_DATE' sql_mode is enabled.

Parameters
thdThread handle.
datetime_fieldDATE/DATETIME column definition.

◆ 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.

◆ rea_create_base_table()

static bool rea_create_base_table ( THD thd,
const char *  path,
const dd::Schema sch_obj,
const char *  db,
const char *  table_name,
HA_CREATE_INFO create_info,
List< Create_field > &  create_fields,
uint  keys,
KEY key_info,
Alter_info::enum_enable_or_disable  keys_onoff,
uint  fk_keys,
FOREIGN_KEY fk_key_info,
const Sql_check_constraint_spec_list check_cons_spec,
handler file,
bool  no_ha_table,
bool  do_not_store_in_dd,
partition_info part_info,
bool *  binlog_to_trx_cache,
std::unique_ptr< dd::Table > *  table_def_ptr,
handlerton **  post_ddl_ht 
)
static

Create table definition in the Data Dictionary.

The table is also created in the storage engine, depending on the 'no_ha_table' argument.

Parameters
thdThread handler
pathName of file (including database)
sch_objSchema.
dbSchema name. Cannot use dd::Schema::name() directly due to LCTN.
table_nameTable name
create_infocreate info parameters
create_fieldsFields to create
keysnumber of keys to create
key_infoKeys to create
keys_onoffEnable or disable keys.
fk_keysNumber of foreign keys to create
fk_key_infoForeign keys to create
check_cons_specList of check constraint specifications.
fileHandler to use
no_ha_tableIndicates that only definitions needs to be created and not a table in the storage engine.
do_not_store_in_ddIndicates that we should postpone storing table object in the data-dictionary. Requires SE supporting atomic DDL and no_ha_table flag set.
part_infoReference to partitioning data structure.
[out]binlog_to_trx_cacheWhich binlog cache should be used? If true => trx cache If false => stmt cache
[out]table_def_ptrdd::Table object describing the table created if do_not_store_in_dd option was used. Not set otherwise.
[out]post_ddl_htSet to handlerton for table's SE, if this SE supports atomic DDL, so caller can call SE post DDL hook after committing transaction.
Note
For engines supporting atomic DDL the caller must rollback both statement and transaction on failure. This must be done before any further accesses to DD.
See also
dd::create_table().
Return values
falseok
trueerror

◆ rea_create_tmp_table()

static bool rea_create_tmp_table ( THD thd,
const char *  path,
const dd::Schema sch_obj,
const char *  db,
const char *  table_name,
HA_CREATE_INFO create_info,
List< Create_field > &  create_fields,
uint  keys,
KEY key_info,
Alter_info::enum_enable_or_disable  keys_onoff,
const Sql_check_constraint_spec_list check_cons_spec,
handler file,
bool  no_ha_table,
bool *  binlog_to_trx_cache,
std::unique_ptr< dd::Table > *  tmp_table_def 
)
static

Create a dd::Table-object specifying the temporary table definition, but do not put it into the Data Dictionary.

The created dd::Table-instance is returned via tmp_table_def out-parameter. The temporary table is also created in the storage engine, depending on the 'no_ha_table' argument.

Parameters
thdThread handler
pathName of file (including database)
sch_objSchema.
dbSchema name. Cannot use dd::Schema::name() directly due to LCTN.
table_nameTable name
create_infocreate info parameters
create_fieldsFields to create
keysnumber of keys to create
key_infoKeys to create
keys_onoffEnable or disable keys.
check_cons_specList of check constraint specification.
fileHandler to use
no_ha_tableIndicates that only definitions needs to be created and not a table in the storage engine.
[out]binlog_to_trx_cacheWhich binlog cache should be used? If true => trx cache If false => stmt cache
[out]tmp_table_defData-dictionary object for temporary table which was created. Is not set if no_ha_table was false.
Return values
falseok
trueerror

◆ reload_fk_parents_for_single_table()

static bool reload_fk_parents_for_single_table ( THD thd,
const char *  db,
const char *  name 
)
static

◆ remove_secondary_engine()

static bool remove_secondary_engine ( THD thd,
const Table_ref table,
const HA_CREATE_INFO create_info,
const dd::Table old_table_def 
)
static

Unloads table from secondary engine if SECONDARY_ENGINE = NULL.

Parameters
thdThread handler.
tableTable opened in primary storage engine.
create_infoInformation from the parsing phase about new table properties.
old_table_defDefinition of table before the alter statement.
Returns
True if error, false otherwise.

◆ rename_histograms()

static bool rename_histograms ( THD thd,
const char *  old_schema_name,
const char *  old_table_name,
const char *  new_schema_name,
const char *  new_table_name 
)
static

Rename histograms from an old table name to a new table name.

Parameters
thdThread handle
old_schema_nameThe old schema name
old_table_nameThe old table name
new_schema_nameThe new schema name
new_table_nameThe new table name
Returns
false on success, true on error

◆ reset_check_constraints_alter_mode()

static void reset_check_constraints_alter_mode ( dd::Table new_table)
static

Reset alter mode of check constraints.

Method updates only dd::Table object. It is not stored or updated to data-dictionary in this method.

Parameters
new_tableNew table definition.

◆ rm_table_check_fks()

static bool rm_table_check_fks ( THD thd,
Drop_tables_ctx drop_ctx 
)
static

Check if DROP TABLES or DROP DATABASE statement going to violate some foreign key constraint by dropping its parent table without dropping child at the same time.

◆ 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.

◆ rm_table_eval_gtid_and_table_groups_state()

static bool rm_table_eval_gtid_and_table_groups_state ( THD thd,
Drop_tables_ctx drop_ctx 
)
static

Auxiliary function which evaluates in which situation DROP TABLES is regarding GTID and different table groups.

◆ rm_table_sort_into_groups()

static bool rm_table_sort_into_groups ( THD thd,
Drop_tables_ctx drop_ctx,
Table_ref tables 
)
static

Auxiliary function which prepares for DROP TABLES execution by sorting tables to be dropped into groups according to their types.

◆ secondary_engine_load_table()

static bool secondary_engine_load_table ( THD thd,
const TABLE table,
bool *  skip_metadata_update 
)
static

Loads a table from its primary engine into its secondary engine.

Note
An MDL_EXCLUSIVE lock on the table must have been acquired prior to calling this function to ensure that all currently running DML statements commit before load begins.
Parameters
thdThread handler.
tableTable in primary storage engine.
[out]skip_metadata_updateShould the DD metadata be updated for the load of this table
Returns
True if error, false otherwise.

◆ secondary_engine_unload_table()

static bool secondary_engine_unload_table ( THD thd,
const char *  db_name,
const char *  table_name,
const dd::Table table_def,
bool  error_if_not_loaded 
)
static

Unloads a table from its secondary engine.

Note
An MDL_EXCLUSIVE or stronger lock on the table must have been acquired prior to calling this function to ensure that queries already offloaded to the secondary engine finished execution before unloading the table.
Parameters
thdThread handler.
db_nameDatabase name.
table_nameTable name.
table_defTable definition.
error_if_not_loadedIf true and the table is not loaded in the secondary engine, this function will return an error. If false, this function will not return an error if the table is not loaded in the secondary engine.
Returns
True if error, false otherwise.

◆ set_check_constraints_alter_mode()

static void set_check_constraints_alter_mode ( dd::Table new_table,
Alter_info alter_info 
)
static

During alter table operation, check constraints of a new table are marked as in alter mode.

If a table object is stored to the data-dictionary in this mode then alias name is stored to avoid name conflicts due to two versions of table objects. dd::Table object of a new table read from the data-dictionary contains only alias name. So dd::Table object of a new table is patched up here with the real name and alter mode to reflect the fact the check constraint is in alter_mode as this information is not stored parsistently.

Parameters
new_tableNew table definition.
alter_infoAlter_info object containing list of list of check constraint spec for table being altered.

◆ set_column_static_defaults()

static void set_column_static_defaults ( TABLE altered_table,
List< Create_field > &  create 
)
static

Initialize TABLE::field for the new table with appropriate column static defaults.

Note
Can be plain default values from TABLE_SHARE::default_values or datetime function defaults. We don't handle general expression defaults here as their values need to be evaluated for each row and such evaluation might result in error.
Parameters
altered_tableTABLE object for the new version of the table.
createCreate_field list for new version of the table, which is used for identifying new columns.

◆ set_table_default_charset()

static bool set_table_default_charset ( THD thd,
HA_CREATE_INFO create_info,
const dd::Schema schema 
)
static

◆ simple_rename_or_index_change()

static bool simple_rename_or_index_change ( THD thd,
const dd::Schema new_schema,
Table_ref table_list,
Alter_info::enum_enable_or_disable  keys_onoff,
Alter_table_ctx alter_ctx 
)
static

Rename table and/or turn indexes on/off without touching .FRM.

Parameters
thdThread handler
new_schemaTarget schema.
table_listTable_ref for the table to change
keys_onoffENABLE or DISABLE KEYS?
alter_ctxALTER TABLE runtime context.
Returns
Operation status
Return values
falseSuccess
trueFailure

Update mysql.tables.options with keys_disabled=1/0 based on keys_onoff. This will used by INFORMATION_SCHEMA.STATISTICS system view to display keys were disabled.

◆ table_is_empty()

static bool table_is_empty ( TABLE table,
bool *  is_empty 
)
static

Check if a table is empty, i.e., it has no rows.

Parameters
[in]tableThe table.
[out]is_emptySet to true if the table is empty.
Return values
falseSuccess.
trueAn error occurred (and has been reported with print_error).

◆ tablename_to_filename()

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

◆ to_fk_match_opt()

static fk_match_opt to_fk_match_opt ( dd::Foreign_key::enum_match_option  match)
static

◆ to_fk_option()

static fk_option to_fk_option ( dd::Foreign_key::enum_rule  rule)
static

◆ to_lex_cstring()

static void to_lex_cstring ( MEM_ROOT mem_root,
LEX_CSTRING target,
const dd::String_type source 
)
static

◆ trans_intermediate_ddl_commit()

static bool trans_intermediate_ddl_commit ( THD thd,
bool  error 
)
static

◆ transfer_preexisting_foreign_keys()

static bool transfer_preexisting_foreign_keys ( THD thd,
const dd::Table src_table,
const char *  src_db_name,
const char *  src_table_name,
handlerton hton,
const Alter_info alter_info,
List< Create_field > *  new_create_list,
Alter_table_ctx alter_ctx,
Prealloced_array< const Alter_drop *, 1 > *  drop_list 
)
static

Remember information about pre-existing foreign keys so that they can be added to the new version of the table later.

Omit foreign keys to be dropped. Also check that the foreign keys to be kept are still valid.

Note
This function removes pre-existing foreign keys from the drop_list, while Alter_info::drop_list is kept intact. A non-empty drop_list upon return of this function indicates an error, and means that the statement tries to drop a foreign key that did not exist in the first place.
Parameters
[in]thdThread handle.
[in]src_tableThe source table.
[in]src_db_nameOriginal database name of table.
[in]src_table_nameOriginal table name of table.
[in]htonOriginal storage engine.
[in]alter_infoInfo about ALTER TABLE statement.
[in]new_create_listList of new columns, used for rename check.
[in,out]drop_listCopy of list of foreign keys to be dropped.
[in,out]alter_ctxRuntime context for ALTER TABLE to which information about pre-existing foreign keys is added.

◆ update_altered_table()

static void update_altered_table ( const Alter_inplace_info ha_alter_info,
TABLE altered_table 
)
static

Mark fields participating in newly added indexes in TABLE object which corresponds to new version of altered table.

Parameters
ha_alter_infoAlter_inplace_info describing in-place ALTER.
altered_tableTABLE object for new version of TABLE in which fields should be marked.

◆ 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

◆ validate_secondary_engine_option()

static bool validate_secondary_engine_option ( THD thd,
const Alter_info alter_info,
const HA_CREATE_INFO create_info,
const TABLE table 
)
static

Validates the ALTER TABLE command with respect to any secondary engine operations.

Parameters
alter_infoAlter table operations.
create_infoTable option changes.
tableThe table that is being altered.
Returns
True if invalid, false otherwise.

◆ validate_table_encryption()

static bool validate_table_encryption ( THD thd,
HA_CREATE_INFO create_info 
)
static

◆ warn_on_deprecated_float_precision()

static void warn_on_deprecated_float_precision ( THD thd,
const Create_field sql_field 
)
static

◆ warn_on_deprecated_float_unsigned()

static void warn_on_deprecated_float_unsigned ( THD thd,
const Create_field sql_field 
)
static

◆ warn_on_deprecated_zerofill()

static void warn_on_deprecated_zerofill ( THD thd,
const Create_field sql_field 
)
static

◆ write_bin_log()

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

Variable Documentation

◆ deprecated_use_fk_on_non_standard_key_count

std::atomic_ulong deprecated_use_fk_on_non_standard_key_count = 0

Count number of times foreign key is created on non standard index keys.

◆ deprecated_use_fk_on_non_standard_key_last_timestamp

std::atomic_ullong deprecated_use_fk_on_non_standard_key_last_timestamp = 0

Last time fk is created on non standard index key, as usec since epoch.

◆ KEY_DEFAULT_PACK_LENGTH

constexpr const int KEY_DEFAULT_PACK_LENGTH {8}
staticconstexpr

Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used).

◆ MAX_ENUM_VALUES

constexpr const int MAX_ENUM_VALUES {65535}
staticconstexpr

◆ primary_key_name

const char* primary_key_name = "PRIMARY"