MySQL 9.0.0
Source Code Documentation
|
#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) |
handlerton * | anonymous_namespace{sql_table.cc}::default_handlerton (THD *thd, const HA_CREATE_INFO &ci) |
handlerton * | anonymous_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) |
handlerton * | anonymous_namespace{sql_table.cc}::get_viable_handlerton_for_create_impl (THD *thd, const char *table_name, const HA_CREATE_INFO &ci, Handlerton_pair hp) |
handlerton * | anonymous_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... | |
handlerton * | anonymous_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... | |
handlerton * | get_viable_handlerton_for_create (THD *thd, const char *table_name, const HA_CREATE_INFO &ci) |
Checks if the handlerton for the specified ENGINE is enabled AND NOT explicitly disabled (listed in the disabled_storages_engines system variable). More... | |
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::Index * | find_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::Index * | anonymous_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_field * | get_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... | |
TYPELIB * | create_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_INFO * | get_sql_field_charset (const Create_field *sql_field, const HA_CREATE_INFO *create_info) |
Get the character set from field object generated by the parser, using default values when not set. More... | |
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 KEY * | find_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::Index * | anonymous_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_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) |
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 KEY * | find_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 KEY * | find_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_field * | get_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" |
#define ER_THD_OR_DEFAULT | ( | thd, | |
X | |||
) | ((thd) ? ER_THD_NONCONST(thd, X) : ER_DEFAULT_NONCONST(X)) |
typedef std::set<std::pair<dd::String_type, dd::String_type> > Normalized_fk_children |
|
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.
thd | The thread handler |
key_spec | The index that contains the key part.- |
alter_info | A structure describing the changes to be carried out. This structure will be updated with the new generated column. |
kp | The 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_number | The number of the key part. |
create_info | A structure describing the table to be created |
|
static |
Helper function for explain_filename.
thd | Thread handle |
to_p | Explained name in system_charset_info |
end_p | End of the to_p buffer |
name | Name to be converted |
name_len | Length of the name, in bytes |
bool adjust_adopted_self_ref_fk_for_simple_rename_table | ( | THD * | thd, |
const char * | db, | ||
const char * | table_name, | ||
const char * | new_db, | ||
const char * | new_table_name, | ||
handlerton * | hton | ||
) |
As a result of simple rename table operation, orphan non-self-referencing foreign keys may become non-orphan/adopted self-referencing foreign keys.
For such transformed foreign key, check that table has compatible referenced column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.
thd | Thread handle. |
db | Table's old schema. |
table_name | Table's old name. |
new_db | Table's new schema. |
new_table_name | Table's new name. |
hton | Table's SE. |
operation | outcome, false if no error. |
|
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.
thd | Thread context. |
old_table_db | Database of old table. |
old_table | Old table definition. |
|
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.
thd | Thread handle. |
check_only | Indicates that we only need to check parent key existence and do not do real update. |
check_charsets | Indicates whether we need to check charsets of columns participating in foreign keys. |
child_table_db | Child table schema name. |
child_table_name | Child table name. |
parent_table_db | Parent table schema name. |
parent_table_name | Parent table name. |
hton | Handlerton for tables' storage engine. |
parent_table_def | Table object representing the new version of referenced table. |
parent_alter_info | Alter_info containing information about renames of parent columns. Can be nullptr if there are no such renames. |
old_parent_table_def | Table object representing the old version of referenced table. Can be nullptr if this is not ALTER TABLE. Used for error reporting. |
operation | outcome, false if no error. |
bool adjust_fk_children_after_parent_def_change | ( | THD * | thd, |
bool | check_charsets, | ||
const char * | parent_table_db, | ||
const char * | parent_table_name, | ||
handlerton * | hton, | ||
const dd::Table * | parent_table_def, | ||
Alter_info * | parent_alter_info, | ||
bool | invalidate_tdc | ||
) |
Check if new definition of parent table is compatible with foreign keys which reference it.
Update the unique constraint names and referenced column names for the foreign keys accordingly.
thd | Thread handle. |
check_charsets | Indicates whether we need to check charsets of columns participating in foreign keys. |
parent_table_db | Parent table schema name. |
parent_table_name | Parent table name. |
hton | Handlerton for table's storage engine. |
parent_table_def | Table object representing the referenced table. |
parent_alter_info | Alter_info containing information about renames of parent columns. Can be nullptr if there are no such renames. |
invalidate_tdc | Indicates whether we need to invalidate TDC for referencing tables after updating their definitions. |
operation | outcome, false if no error. |
|
static |
Update the referenced schema- and/or table name for the referencing tables when the referenced table is renamed.
thd | Thread handle. |
parent_table_db | Old schema name. |
parent_table_name | Old table name. |
hton | Handlerton for table's storage engine. |
new_db | New schema name. |
new_table_name | New table name. |
operation | outcome, false if no error. |
|
static |
Update the unique constraint names for FKs which reference table being dropped.
thd | Thread handle. |
parent_table_db | Schema name for table being dropped. |
parent_table_name | Name of the table being dropped. |
parent_table_def | dd::Table object representing the dropped table. |
hton | Handlerton for table's storage engine. |
operation | outcome, false if no error. |
bool adjust_fk_parents | ( | THD * | thd, |
const char * | db, | ||
const char * | name, | ||
bool | reload_self, | ||
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.
thd | Thread handle. |
table_list | Table list element for table being ALTERed. |
alter_ctx | ALTER TABLE operation context. |
alter_info | Alter_info describing ALTER TABLE, specifically containing information about columns being renamed. |
new_hton | Table's new SE. |
fk_invalidator | Object keeping track of which dd::Table objects to invalidate. Used to filter out which FK parents should have their FK parent information reloaded. |
operation | outcome, false if no error. |
bool adjust_fks_for_rename_table | ( | THD * | thd, |
const char * | db, | ||
const char * | table_name, | ||
const char * | new_db, | ||
const char * | new_table_name, | ||
handlerton * | hton | ||
) |
Update referenced table names and the unique constraint name for FKs affected by RENAME TABLE operation.
thd | Thread handle. |
db | Table's old schema. |
table_name | Table's old name. |
new_db | Table's new schema. |
new_table_name | Table's new name. |
hton | Table's SE. |
operation | outcome, false if no error. |
|
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.
thd | Thread context. |
db_name | Database where old table definition resides. |
backup_name | Temporary name assigned to old table definition during ALTER TABLE. |
|
static |
Sets column default, drops default, renames or alters visibility.
|
static |
Drop histograms from a given table.
This function will check if an ALTER TABLE statement will make a histogram invalid:
If such change is found, remove any existing histogram for these columns.
thd | thread handler |
table | the table given in ALTER TABLE |
alter_info | the alter changes to be carried out by ALTER TABLE |
create_info | the alter changes to be carried out by ALTER TABLE |
columns | a list of columns to be changed or dropped |
original_table_def | the 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_def | the table definition, post altering |
|
static |
|
static |
Auxiliary function which appends to the string table identifier with proper quoting and schema part if necessary.
Auxiliary function which appends to the string schema and table name for the table (without quoting).
|
static |
maximum possible length for certain blob types.
[in] | type | Blob type (e.g. MYSQL_TYPE_TINY_BLOB) |
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
size_t build_tmptable_filename | ( | THD * | thd, |
char * | buff, | ||
size_t | bufflen | ||
) |
Create path to a temporary table, like mysql_tmpdir/#sql1234_12_1 (i.e.
to its .FRM file but without an extension).
thd | The thread handle. |
buff | Where to write result in my_charset_filename. |
bufflen | buff size |
|
static |
|
static |
Check if there is a duplicate key.
Report a warning for every duplicate key.
thd | Thread context. |
error_schema_name | Schema name of the table used for error reporting. |
error_table_name | Table name used for error reporting. |
key | Key to be checked. |
key_info | Array with all keys for the table. |
key_count | Number of keys in the table. |
alter_info | Alter_info structure describing ALTER TABLE. |
false | Ok. |
true | Error. |
|
static |
|
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.
db_name | Database name. |
table_name | Name of table to be created. |
create_info | Create info from parser, including engine. |
true | Engine not available/supported, error has been reported. |
false | Engine available/supported. |
|
static |
Check if new definition of parent table is compatible with foreign keys which reference it and were previously orphan.
thd | Thread handle. |
parent_table_db | Parent table schema name. |
parent_table_name | Parent table name. |
old_parent_table_db | Old parent table schema name, if table is renamed. |
old_parent_table_name | Old parent table name, if table is renamed. |
hton | Handlerton for table's storage engine. |
parent_table_def | Table object representing the parent table. |
operation | outcome, false if no error. |
|
static |
Check if new definition of parent table is compatible with foreign keys which reference it.
thd | Thread handle. |
parent_table_db | Parent table schema name. |
parent_table_name | Parent table name. |
hton | Handlerton for tables' storage engine. |
old_parent_table_def | Table object representing the old version of parent table. |
new_parent_table_def | Table object representing the new version of parent table. |
parent_alter_info | Alter_info containing information about renames of parent columns. |
operation | outcome, false if no error. |
|
static |
Check if complex ALTER TABLE with RENAME clause results in foreign key names conflicts.
thd | Thread handle. |
table_list | Table list element for table altered. |
table_def | dd::Table object describing new version of table prior to rename operation. |
hton | Table's storage engine. |
new_schema | dd::Schema object for target schema. |
alter_ctx | ALTER TABLE operation context. |
True | if error (e.g. due to foreign key name conflict), false - otherwise. |
|
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.
table | TABLE object describing old table version. |
field | Field object for column to be checked. |
alter_info | Alter_info describing which columns, defaults or indexes are dropped or modified. |
|
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.
table | TABLE object describing old table version. |
field | Field object for column to be checked. |
alter_info | Alter_info describing the ALTER TABLE. |
|
static |
Check if table already exists.
thd | thread handle |
schema_name | schema name. |
table_name | table name. |
alias | alt representation of table_name. |
ha_lex_create_tmp_table | true if creating a tmp table. |
ha_create_if_not_exists | true if this is CREATE IF NOT EXISTS. |
internal_tmp_table | true if this is an internal tmp table. |
|
static |
Primary/unique key check.
Checks that:
file | The storage engine handler. |
key_info_buffer | All indexes in the table. |
key_count | Number of indexes. |
false | OK. |
true | An error occurred and my_error() was called. |
|
static |
Check if foreign key's parent table has a column compatible with foreign key's referenced column.
[in] | parent_table_def | Data-dictionary object for parent table. |
[in] | fk | Data-dictionary object for foreign key. |
[in] | fk_el | Data-dictionary object for foreign key element. |
[in] | hton | Handlerton for table's storage engine. |
false | Success. |
true | Failure. |
|
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.
thd | Thread handle. | |
table_list | Table list element for table being ALTERed. | |
old_table_def | Old table definition of table being ALTERed. | |
alter_ctx | ALTER TABLE operation context. | |
alter_info | Alter_info object with the lists of FKs to be added or dropped. | |
old_hton | Table's old SE. | |
new_hton | Table's new SE. | |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
bool collect_and_lock_fk_tables_for_rename_table | ( | THD * | thd, |
const char * | db, | ||
const char * | table_name, | ||
const dd::Table * | table_def, | ||
const char * | new_db, | ||
const char * | new_table_name, | ||
handlerton * | hton, | ||
Foreign_key_parents_invalidator * | fk_invalidator | ||
) |
Acquire exclusive metadata locks on tables which definitions need to be updated or invalidated since they are related through foreign keys to the table to be renamed, Also add the referenced table names for the FKs on this table to the foreign key invalidator, to be used at a later stage to invalidate the dd::Table objects.
thd | Thread handle. | |
db | Table's old schema. | |
table_name | Table's old name. | |
table_def | Table definition of table being RENAMEd. | |
new_db | Table's new schema. | |
new_table_name | Table's new name. | |
hton | Table's SE. | |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
bool collect_fk_children | ( | THD * | thd, |
const char * | schema, | ||
const char * | table_name, | ||
handlerton * | hton, | ||
enum_mdl_type | lock_type, | ||
MDL_request_list * | mdl_requests | ||
) |
Add MDL requests for specified lock type on all tables referencing the given schema qualified table name to the list.
thd | Thread handle. | |
schema | Schema name. | |
table_name | Table name. | |
hton | Handlerton for table's storage engine. | |
lock_type | Type of MDL requests to add. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
|
static |
Add MDL requests for specified lock type on all tables referencing the given table.
thd | Thread handle. | |
table_def | dd::Table object describing the table. | |
lock_type | Type of MDL requests to add. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
|
static |
Add MDL requests for exclusive lock on all foreign key names on the given table to the list.
thd | Thread context. | |
db | Table's schema name. | |
table_def | Table definition. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
|
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.
thd | Thread context. | |
db | Table's database before ALTER TABLE operation. | |
alter_info | Alter_info object with the list of FKs to be dropped. | |
table_def | dd::Table describing the table before ALTER operation. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
bool collect_fk_names_for_new_fks | ( | THD * | thd, |
const char * | db_name, | ||
const char * | table_name, | ||
const Alter_info * | alter_info, | ||
handlerton * | hton, | ||
uint | fk_max_generated_name_number, | ||
MDL_request_list * | mdl_requests | ||
) |
Add MDL requests for exclusive metadata locks on names of foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
thd | Thread context. | |
db_name | Table's database name. | |
table_name | Table name. | |
alter_info | Alter_info object with the list of FKs to be added. | |
hton | Table's storage engine. | |
fk_max_generated_name_number | Max value of number component among existing generated foreign key names. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
operation | outcome, false if no error. |
|
static |
Add appropriate MDL requests on names of foreign keys on the table to be renamed to the requests list.
thd | Thread handle. | |
db | Table's old schema. | |
table_name | Table's old name. | |
table_def | Table definition of table being RENAMEd. | |
hton | Table's storage engine. | |
new_db | Table's new schema. | |
new_table_name | Table's new name. | |
[in,out] | mdl_requests | List to which MDL requests need to be added. |
operation | outcome, false if no error. |
|
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.
thd | Thread handle. | |
table_def | dd::Table object. | |
lock_type | Type of MDL requests to add. | |
hton | Handlerton for table's storage engine. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
|
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.
thd | Thread handle. | |
alter_info | Alter_info object with the list of FKs to be dropped. | |
table_def | dd::Table describing the table before ALTER operation. | |
hton | Handlerton for table's storage engine. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
bool collect_fk_parents_for_new_fks | ( | THD * | thd, |
const char * | db_name, | ||
const char * | table_name, | ||
const Alter_info * | alter_info, | ||
enum_mdl_type | lock_type, | ||
handlerton * | hton, | ||
MDL_request_list * | mdl_requests, | ||
Foreign_key_parents_invalidator * | fk_invalidator | ||
) |
Add MDL requests for lock of specified type on tables referenced by the foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
Also add the referenced table names to the foreign key invalidator, to be used at a later stage to invalidate the dd::Table objects.
thd | Thread handle. | |
db_name | Table's database name. | |
table_name | Table name. | |
alter_info | Alter_info object with the list of FKs to be added. | |
lock_type | Type of metadata lock to be requested. | |
hton | Handlerton for table's storage engine. | |
[in,out] | mdl_requests | List to which MDL requests are to be added. |
[in,out] | fk_invalidator | Object keeping track of which dd::Table objects to invalidate. |
operation | outcome, false if no error. |
|
static |
Check if the given column exists in the create list.
column_name | the column name to look for. |
create_list | the create list where the search is performed. |
true | the column exists in the create list. |
false | the column does not exist in the create list. |
|
static |
Checks if a column with the given name exists in a list of fields.
|
static |
|
static |
Count keys and key segments.
Note that FKs are ignored. Also mark redundant keys to be ignored.
[in,out] | key_list | List of keys to count and possibly mark as ignored. |
[out] | key_count | Returned number of keys counted (excluding FK). |
[out] | key_parts | Returned number of key segments (excluding FK). |
[out] | fk_key_count | Returned number of foreign keys. |
[in,out] | redundant_keys | Array where keys to be ignored will be marked. |
[in] | se_index_flags | Storage's flags for index support |
|
static |
Create a table.
thd | Thread object | |
schema | DD schema object | |
db | Database | |
table_name | Table name | |
error_table_name | The 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. | |
path | Path to table (i.e. to its .FRM file without the extension). | |
create_info | Create information (like MAX_ROWS) | |
alter_info | Description of fields and keys for new table | |
internal_tmp_table | Set to true if this is an internal temporary table (From ALTER TABLE) | |
select_field_count | Number of fields coming from SELECT part of CREATE TABLE ... SELECT statement. Must be zero for standard create of table. | |
find_parent_keys | Indicates whether we need to lookup name of unique constraint in parent table for foreign keys. | |
no_ha_table | Indicates 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_dd | Indicates that we should postpone storing table object in the data-dictionary. Requires SE supporting atomic DDL and no_ha_table flag set. | |
[out] | is_trans | Identifies the type of engine where the table was created: either trans or non-trans. |
[out] | key_info | Array of KEY objects describing keys in table which was created. |
[out] | key_count | Number of keys in table which was created. |
keys_onoff | Enable or disable keys. | |
[out] | fk_key_info | Array of FOREIGN_KEY objects describing foreign keys in table which was created. |
[out] | fk_key_count | Number of foreign keys in table which was created. |
[in] | existing_fk_info | Array of FOREIGN_KEY objects for foreign keys which already existed in the table (in case of ALTER TABLE). |
[in] | existing_fk_count | Number of pre-existing foreign keys. |
[in] | existing_fk_table | dd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting. |
[in] | fk_max_generated_name_number | Max value of number component among existing generated foreign key names. |
[out] | table_def | Data-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_ht | Set 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.
false | OK |
true | error |
TYPELIB * create_typelib | ( | MEM_ROOT * | mem_root, |
Create_field * | field_def | ||
) |
|
static |
Auxiliary function which drops single base table.
thd | Thread handler. | |
drop_ctx | DROP TABLES runtime context. | |
table | Table to drop. | |
atomic | Indicates 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_htons | Set of handlertons for tables in SEs supporting atomic DDL for which post-DDL hook needs to be called after statement commit or rollback. |
[in,out] | fk_invalidator | Object 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_mdl | Under LOCK TABLES set of metadata locks on tables dropped which is safe to release after DROP operation. |
foreach_table_root | MEM_ROOT which can be used for allocating objects which lifetime is limited to dropping of single table. |
False | - ok |
True | - error |
size_t explain_filename | ( | THD * | thd, |
const char * | from, | ||
char * | to, | ||
size_t | to_length, | ||
enum_explain_filename_mode | explain_mode | ||
) |
Explain a path name by split it to database, table etc.
Break down the path name to its logic parts (database, table, partition, subpartition). filename_to_tablename cannot be used on partitions, due to the #P# part. There can be up to 6 '#', #P# for partition, #SP# for subpartition and #TMP# or #REN# for temporary or renamed partitions. This should be used when something should be presented to a user in a diagnostic, error etc. when it would be useful to know what a particular file [and directory] means. Such as SHOW ENGINE STATUS, error messages etc.
thd | Thread handle |
from | Path name in my_charset_filename Null terminated in my_charset_filename, normalized to use '/' as directory separation character. |
to | Explained name in system_charset_info |
to_length | Size of to buffer |
explain_mode | Requested output format. EXPLAIN_ALL_VERBOSE -> [Database db , ]Table tbl [,[ Temporary| Renamed] Partition p [, Subpartition sp ]] EXPLAIN_PARTITIONS_VERBOSE -> db .tbl [[ Temporary| Renamed] Partition p [, Subpartition sp ]] EXPLAIN_PARTITIONS_AS_COMMENT -> db .tbl |* [,[ Temporary| Renamed] Partition p [, Subpartition sp ]] *| (| is really a /, and it is all in one line) |
Length | of returned string |
|
static |
Fetch names of all tables having a FK referring to the given table.
thd | Thread handle. | |
parent_schema | Schema name of the referenced table. | |
parent_name | Name of the referenced table. | |
parent_engine | Name of the referenced table's storage engine. | |
[out] | fk_children | Set 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.
operation | outcome, false if no error. |
size_t filename_to_tablename | ( | const char * | from, |
char * | to, | ||
size_t | to_length, | ||
bool | stay_quiet, | ||
bool * | has_errors | ||
) |
|
static |
Compare original and new versions of a table and fill Alter_inplace_info describing differences between those versions.
thd | Thread | |
table | The original table. | |
[in,out] | ha_alter_info | Data 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.
true | error |
false | success |
|
static |
Helper which builds Ha_fk_column_type describing column type from its Create_field object.
|
static |
Helper which builds Ha_fk_column_type describing column type from its dd::Column object.
|
static |
Find supporting key for the foreign key.
hton | Handlerton for table's storage engine. |
alter_info | Alter_info object describing child table. |
key_info_buffer | Array describing keys in child table. |
key_count | Number of keys in child table. |
fk | FOREIGN_KEY object describing the FK. |
non-nullptr | - pointer to KEY object describing supporting key. |
nullptr | - if no supporting key were found. |
|
static |
Find supporting key for the foreign key.
hton | Handlerton for tables' storage engine. Used to figure out what kind of supporting keys are allowed by the storage engine. |
table_def | dd::Table object describing the child table. |
fk | dd::Foreign_key object describing the foreign key. |
non-nullptr | - pointer to dd::Index object describing supporting key. |
nullptr | - if no supporting key were found. |
Look-up KEY object by index name using case-insensitive comparison.
key_name | Index name. |
key_start | Start of array of KEYs for table. |
key_end | End of array of KEYs for table. |
non-NULL | - pointer to KEY object for index found. |
NULL | - no index with such name found (or it is marked as renamed). |
Look-up KEY object by index name using case-sensitive comparison.
key_name | Index name. |
key_start | Start of array of KEYs for table. |
key_end | End of array of KEYs for table. |
non-NULL | - pointer to KEY object for index found. |
NULL | - no index with such name found (or it is marked as renamed). |
|
static |
Check that ALTER TABLE's changes on columns of a foreign key are allowed.
F | Function 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. |
[in] | thd | Thread context. |
[in] | alter_info | Alter_info describing changes to be done by ALTER TABLE. |
[in] | fk_col_count | Number of columns in the foreign key. |
[in] | fk_columns | Object of F type bound to the specific foreign key for which check is carried out. |
[out] | bad_column_name | Name of field on which ALTER TABLE tries to do prohibited operation. |
FK_COLUMN_NO_CHANGE | No significant changes are to be done on foreign key columns. |
FK_COLUMN_DATA_CHANGE | ALTER TABLE might result in value change in foreign key column (and foreign_key_checks is on). |
FK_COLUMN_RENAMED | Foreign key column is renamed. |
FK_COLUMN_DROPPED | Foreign key column is dropped. |
|
static |
Check if ALTER TABLE we are about to execute using COPY algorithm is not supported as it might break referential integrity.
[in] | thd | Thread context. |
[in] | table_list | Table_ref element for the table to be altered. |
[in] | table_def | dd::Table for old version of table to be altered. |
[in] | alter_info | Lists of fields, keys to be changed, added or dropped. |
false | Success. |
true | Error, ALTER - tries to do change which is not compatible with foreign key definitions on the table. |
|
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.
F | Function class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index. |
alter_info | Alter_info describing columns in parent or child table. |
fk_col_count | Number of columns in the foreign key. |
fk_columns | Object of F type bound to the specific foreign key for which parent/supporting key check is carried out. |
key | KEY object describing candidate parent/supporting key. |
True | - Key is proper parent/supporting key for the foreign key. |
False | - Key can't be parent/supporting key for the foreign 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.
F | Function class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index. |
fk_col_count | Number of columns in the foreign key. |
fk_columns | Object of F type bound to the specific foreign key for which parent/supporting key check is carried out. |
idx | dd::Index object describing candidate parent/ supporting key. |
True | - Key is proper parent/supporting key for the foreign key. |
False | - Key can't be parent/supporting key for the foreign 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.
F | Function class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index. |
alter_info | Alter_info describing columns in parent or child table. |
fk_col_count | Number of columns in the foreign key. |
fk_columns | Object of F type bound to the specific foreign key for which parent/supporting key check is carried out. |
key | KEY object describing candidate parent/supporting key. |
hidden_cols_key | If 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. |
True | - Key is proper parent/supporting key for the foreign key. |
False | - Key can't be parent/supporting key for the foreign 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.
F | Function class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index. |
fk_col_count | Number of columns in the foreign key. |
fk_columns | Object of F type bound to the specific foreign key for which parent/supporting key check is carried out. |
idx | dd::Index object describing candidate parent/ supporting key. |
use_hidden | Use hidden elements of the key as well. |
True | - Key is proper parent/supporting key for the foreign key. |
False | - Key can't be parent/supporting key for the foreign 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).
F | Function class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index. |
alter_info | Alter_info describing columns in parent or child table. |
fk_col_count | Number of columns in the foreign key. |
fk_columns | Object of F type bound to the specific foreign key for which parent/supporting key check is carried out. |
key | KEY object describing candidate parent/supporting key. |
hidden_cols_key | If 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. |
Number | of matching columns. |
|
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).
F | Function class which returns foreign key's referenced or referencing (depending on whether we check candidate parent or supporting key) column name by its index. |
fk_col_count | Number of columns in the foreign key. |
fk_columns | Object of F type bound to the specific foreign key for which parent/supporting key check is carried out. |
idx | dd::Index object describing candidate parent/ supporting key. |
use_hidden | Use hidden elements of the key as well. |
Number | of matching columns. |
|
static |
Helper method to generate check constraint name.
thd | Thread handle. | |
table_name | Table name. | |
ordinal_number | Ordinal number of the generated name. | |
[out] | name | LEX_STRING instance to hold the generated check constraint name. |
skip_validation | Skip generated name validation. |
|
static |
Generate a foreign key name and store it in buffer provided.
name_buff | Buffer for generated name. | |
name_buff_size | Size of name buffer, if buffer is too small generated name will be truncated. | |
table_name | Table name. | |
hton | Table storage engine. | |
[in,out] | fk_max_generated_name_number | Max value of number component among existing generated foreign key names. |
|
static |
Generate a foreign key name, allocate memory from thread's current memory root for it.
table_name | Table name. | |
hton | Table storage engine. | |
[in,out] | fk_max_generated_name_number | Max value of number component among existing generated foreign key names. |
Generated | name |
|
static |
Get Create_field object for newly created table by field index.
alter_info | Alter_info describing newly created table. |
idx | Field index. |
|
static |
Get Create_field object for newly created table by its name in the old version of table.
alter_info | Alter_info describing newly created table. |
old_name | Name of field in old table. |
|
static |
Find max value of number component among existing generated foreign key names for the table.
table_name | Table name (should be already in lowercase if l_c_t_n > 0). |
table_def | Table definition. |
hton | Table storage engine. |
const CHARSET_INFO * get_sql_field_charset | ( | const Create_field * | sql_field, |
const HA_CREATE_INFO * | create_info | ||
) |
Get the character set from field object generated by the parser, using default values when not set.
sql_field | The sql_field object |
create_info | Info generated by parser |
handlerton * get_viable_handlerton_for_create | ( | THD * | thd, |
const char * | table_name, | ||
const HA_CREATE_INFO & | ci | ||
) |
Checks if the handlerton for the specified ENGINE is enabled AND NOT explicitly disabled (listed in the disabled_storages_engines system variable).
In the case of temporary tables the handlerton must also support those to be viable.
When returning a handlerton different from the one specified ER_DISABLED_STORAGE_ENGINE and ER_USING_OTHER_HANDLER are emitted as warnings.
thd | Thread handler. |
table_name | Table name. |
ci | create_info struct from parser. |
Handlerton | for specified ENGINE if this is viable. |
The | default (tmp) handlerton if viable and engine substitution is allowed. |
nullptr | if error (specified ENGINE not viable and substitution not permitted). |
|
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.
thd | Thread handler |
alter_info | The changes to be carried out |
table_list | The current table reference |
true | on error (my_error is already called) |
false | on success |
|
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.
thd | thread handler |
alter_info | the changes to be carried out. |
table_list | a reference to the current table |
true | OOM |
false | success |
|
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.
[in,out] | ha_alter_info | Structure describing changes to be done by ALTER TABLE and holding data used during in-place alter. |
table_key | Description of key in old version of table. | |
new_key | Description of key in new version of table. |
|
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.
alter_info | Structure describing the changes to be carried out. |
true | if all of the geometry columns can be altered/changed as requested |
false | if the change is considered invalid |
|
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.
alter_info | Data related to detected changes. |
true | Check constraint (re-)evaluation required. |
false | Otherwise. |
|
static |
Check if key is a candidate key, i.e.
a unique index with no index fields partial, nullable or virtual generated.
|
static |
Scan the indexes of the new table (including the added ones), and check if the field is referred by any index.
field | Field in old table. |
new_field | Field in new table (create field). |
ha_alter_info | Alter inplace info structure. |
true | Field changes collation, and is indexed. |
false | Otherwise. |
|
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.
|
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.
table | The original TABLE. |
create_info | Information from the parsing phase about new table properties. |
alter_info | Data related to detected changes. |
|
inlinestatic |
Helper function which checks if external table has primary key on JSON column.
|
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.
|
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.
|
static |
Check if ALTER TABLE in question is a simple ALTER TABLE RENAME or ALTER TABLE ENABLE/DISABLE KEYS.
alter_info | Alter_info describing ALTER. |
|
static |
Check if the given key name exists in the array of keys.
The lookup is case insensitive.
keys | the array to check for the key name in |
key_name | the key name to look for. |
key_to_ignore | a pointer to the key we don't want to check against. This is used when checking for duplicate functional index names. |
true | if the key name exists in the array |
false | if the key name doesn't exist in the array |
Method to collect check constraint names for the all the tables and acquire MDL lock on them.
[in] | thd | Thread handle. |
[in] | tables | Check constraints of tables to be locked. |
false | Success. |
true | Failure. |
bool lock_check_constraint_names_for_rename | ( | THD * | thd, |
const char * | db, | ||
const char * | table_name, | ||
const dd::Table * | table_def, | ||
const char * | target_db, | ||
const char * | target_table_name | ||
) |
Method to lock check constraint names for rename table operation.
Method acquire locks on the constraint names of source table and also on the name of check constraint in the target table.
[in] | thd | Thread handle. |
[in] | db | Database name. |
[in] | table_name | Table name. |
[in] | table_def | DD table object of source table. |
[in] | target_db | Target database name. |
[in] | target_table_name | Target table name. |
false | Success. |
true | Failure. |
Acquire metadata lock on triggers associated with a list of tables.
[in] | thd | Current thread context |
[in] | tables | Tables for that associated triggers have to locked. |
false | Success |
true | Failure |
|
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).
key_name | the name of the index. |
key_part_number | the key part number, starting from zero. |
fields | the other columns in the table |
mem_root | the MEM_ROOT where the column name should be allocated. |
bool mysql_alter_table | ( | THD * | thd, |
const char * | new_db, | ||
const char * | new_name, | ||
HA_CREATE_INFO * | create_info, | ||
Table_ref * | table_list, | ||
Alter_info * | alter_info | ||
) |
Alter table.
thd | Thread handle |
new_db | If there is a RENAME clause |
new_name | If there is a RENAME clause |
create_info | Information from the parsing phase about new table properties. |
table_list | The table to change. |
alter_info | Lists of fields, keys to be changed, added or dropped. |
true | Error |
false | Success |
This is a veery long function and is everything but the kitchen sink :) It is used to alter a table and not only by ALTER TABLE but also CREATE|DROP INDEX are mapped on this function.
When the ALTER TABLE statement just does a RENAME or ENABLE|DISABLE KEYS, or both, then this function short cuts its operation by renaming the table and/or enabling/disabling the keys. In this case, the FRM is not changed, directly by mysql_alter_table. However, if there is a RENAME + change of a field, or an index, the short cut is not used. See how create_list
is used to generate the new FRM regarding the structure of the fields. The same is done for the indices of the table.
Altering a table can be done in two ways. The table can be modified directly using an in-place algorithm, or the changes can be done using an intermediate temporary table (copy). In-place is the preferred algorithm as it avoids copying table data. The storage engine selects which algorithm to use in check_if_supported_inplace_alter() based on information about the table changes from fill_alter_inplace_info().
bool mysql_checksum_table | ( | THD * | thd, |
Table_ref * | tables, | ||
HA_CHECK_OPT * | check_opt | ||
) |
bool mysql_compare_tables | ( | THD * | thd, |
TABLE * | table, | ||
Alter_info * | alter_info, | ||
HA_CREATE_INFO * | create_info, | ||
bool * | metadata_equal | ||
) |
Compare two tables to see if their metadata are compatible.
One table specified by a TABLE instance, the other using Alter_info and HA_CREATE_INFO.
thd | Thread handler | |
[in] | table | The first table. |
[in] | alter_info | Alter options, fields and keys for the second table. |
[in] | create_info | Create options for the second table. |
[out] | metadata_equal | Result of comparison. |
true | error |
false | success |
bool mysql_create_like_table | ( | THD * | thd, |
Table_ref * | table, | ||
Table_ref * | src_table, | ||
HA_CREATE_INFO * | create_info | ||
) |
bool mysql_create_table | ( | THD * | thd, |
Table_ref * | create_table, | ||
HA_CREATE_INFO * | create_info, | ||
Alter_info * | alter_info | ||
) |
Implementation of SQLCOM_CREATE_TABLE.
Take the metadata locks (including a shared lock on the affected schema) and create the table. Is written to be called from mysql_execute_command(), to which it delegates the common parts with other commands (i.e. implicit commit before and after, close of thread tables.
bool mysql_create_table_no_lock | ( | THD * | thd, |
const char * | db, | ||
const char * | table_name, | ||
HA_CREATE_INFO * | create_info, | ||
Alter_info * | alter_info, | ||
uint | select_field_count, | ||
bool | find_parent_keys, | ||
bool * | is_trans, | ||
handlerton ** | post_ddl_ht | ||
) |
Simple wrapper around create_table_impl() to be used in various version of CREATE TABLE statement.
|
static |
Perform in-place alter table.
thd | Thread handle. | |
schema | Source schema. | |
new_schema | Target schema. | |
table_def | Table object for the original table. | |
altered_table_def | Table object for the new version of the table. | |
table_list | Table_ref for the table to change. | |
table | The original TABLE. | |
altered_table | TABLE object for new version of the table. | |
ha_alter_info | Structure describing ALTER TABLE to be carried out and serving as a storage place for data used during different phases. | |
inplace_supported | Enum describing the locking requirements. | |
alter_ctx | ALTER TABLE runtime context. | |
columns | A list of columns to be modified. This is needed for removal/renaming of histogram statistics. | |
fk_key_info | Array of FOREIGN_KEY objects describing foreign keys in new table version. | |
fk_key_count | Number of foreign keys in new table version. | |
[out] | fk_invalidator | Set of parent tables which participate in FKs together with table being altered and which entries in DD cache need to be invalidated. |
true | Error |
false | Success |
bool mysql_prepare_alter_table | ( | THD * | thd, |
const dd::Table * | src_table, | ||
TABLE * | table, | ||
HA_CREATE_INFO * | create_info, | ||
Alter_info * | alter_info, | ||
Alter_table_ctx * | alter_ctx | ||
) |
Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
This function transforms parse output of ALTER TABLE - lists of columns and keys to add, drop or modify into, essentially, CREATE TABLE definition - a list of columns and keys of the new table. While doing so, it also performs some (bug not all) semantic checks.
This function is invoked when we know that we're going to perform ALTER TABLE via a temporary table – i.e. in-place ALTER TABLE is not possible, perhaps because the ALTER statement contains instructions that require change in table data, not only in table definition or indexes.
[in,out] | thd | thread handle. Used as a memory pool and source of environment information. |
[in] | src_table | DD table object for the table to be created/altered. Will be nullptr for temporary tables. |
[in] | table | the source table, open and locked Used as an interface to the storage engine to acquire additional information about the original table. |
[in,out] | create_info | A blob with CREATE/ALTER TABLE parameters |
[in,out] | alter_info | Another blob with ALTER/CREATE parameters. Originally create_info was used only in CREATE TABLE and alter_info only in ALTER TABLE. But since ALTER might end-up doing CREATE, this distinction is gone and we just carry around two structures. |
[in,out] | alter_ctx | Runtime context for ALTER TABLE. |
true | error, out of memory or a semantical error in ALTER TABLE instructions |
false | success |
bool mysql_prepare_create_table | ( | THD * | thd, |
const char * | error_schema_name, | ||
const char * | error_table_name, | ||
HA_CREATE_INFO * | create_info, | ||
Alter_info * | alter_info, | ||
handler * | file, | ||
bool | is_partitioned, | ||
KEY ** | key_info_buffer, | ||
uint * | key_count, | ||
FOREIGN_KEY ** | fk_key_info_buffer, | ||
uint * | fk_key_count, | ||
FOREIGN_KEY * | existing_fks, | ||
uint | existing_fks_count, | ||
const dd::Table * | existing_fks_table, | ||
uint | fk_max_generated_name_number, | ||
int | select_field_count, | ||
bool | find_parent_keys | ||
) |
Prepares the table and key structures for table creation.
thd | Thread object. | |
error_schema_name | Schema name of the table to create/alter, only error reporting. | |
error_table_name | Name of table to create/alter, only used for error reporting. | |
create_info | Create information (like MAX_ROWS). | |
alter_info | List of columns and indexes to create | |
file | The handler for the new table. | |
is_partitioned | Indicates whether table is partitioned. | |
[out] | key_info_buffer | An array of KEY structs for the indexes. |
[out] | key_count | The number of elements in the array. |
[out] | fk_key_info_buffer | An array of FOREIGN_KEY structs for the foreign keys. |
[out] | fk_key_count | The number of elements in the array. |
[in] | existing_fks | An array of pre-existing FOREIGN KEYS (in case of ALTER). |
[in] | existing_fks_count | The number of pre-existing foreign keys. |
[in] | existing_fks_table | dd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting. |
[in] | fk_max_generated_name_number | Max value of number component among existing generated foreign key names. |
select_field_count | The number of fields coming from a select table. | |
find_parent_keys | Indicates whether we need to lookup name of unique constraint in parent table for foreign keys. |
false | OK |
true | error |
bool mysql_rename_table | ( | THD * | thd, |
handlerton * | base, | ||
const char * | old_db, | ||
const char * | old_name, | ||
const char * | old_fk_db, | ||
const char * | old_fk_name, | ||
const dd::Schema & | new_schema, | ||
const char * | new_db, | ||
const char * | new_name, | ||
uint | flags | ||
) |
Rename a table.
thd | Thread handle |
base | The handlerton handle. |
old_db | The old database name. |
old_name | The old table name. |
old_fk_db | The old table db to be used for identifying self-referencing FKs which need to be updated. |
old_fk_name | The old table name to be used for identifying generated FK names and self-referencing FKs which need to be updated. |
new_schema | DD object for the new schema. |
new_db | The new database name. |
new_name | The new table name. |
flags | flags FN_FROM_IS_TMP old_name is temporary. FN_TO_IS_TMP new_name is temporary. NO_FK_CHECKS Don't check FK constraints during rename. NO_DD_COMMIT Don't commit transaction after updating data-dictionary. NO_FK_RENAME Don't change generated foreign key names during rename. NO_CC_RENAME Don't change generated check constraint names during rename. |
bool mysql_rm_table_no_locks | ( | THD * | thd, |
Table_ref * | tables, | ||
bool | if_exists, | ||
bool | drop_temporary, | ||
bool | drop_database, | ||
bool * | dropped_non_atomic_flag, | ||
std::set< handlerton * > * | post_ddl_htons, | ||
Foreign_key_parents_invalidator * | fk_invalidator, | ||
std::vector< MDL_ticket * > * | safe_to_release_mdl | ||
) |
Execute the drop of a normal or temporary table.
thd | Thread handler | |
tables | Tables to drop | |
if_exists | If set, don't give an error if table doesn't exists. In this case we give an warning of level 'NOTE' | |
drop_temporary | Only drop temporary tables | |
drop_database | This is DROP DATABASE statement. Drop views and handle binary logging in a special way. | |
[out] | dropped_non_atomic_flag | Indicates whether we have dropped some tables in SEs which don't support atomic DDL. |
[out] | post_ddl_htons | Set of handlertons for tables in SEs supporting atomic DDL for which post-DDL hook needs to be called after statement commit or rollback. |
[out] | fk_invalidator | Set of parent tables which participate in FKs together with tables dropped and which entries in DD cache need to be invalidated as result of DROP operation. |
[out] | safe_to_release_mdl | Under LOCK TABLES set of metadata locks on tables dropped which is safe to release after DROP operation. |
False | - ok |
True | - error |
bool mysql_trans_commit_alter_copy_data | ( | THD * | thd | ) |
Commit the copy phase of the alter table.
bool mysql_trans_prepare_alter_copy_data | ( | THD * | thd | ) |
Prepare the transaction for the alter table's copy phase.
|
static |
|
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.
thd | Thread handle. |
table | TABLE instance of source table. |
alter_info | Alter_info object to prepare list of check constraint spec for table being altered. |
alter_tbl_ctx | Runtime context for ALTER TABLE. |
false | Success. |
true | Failure. |
bool prepare_check_constraints_for_create | ( | THD * | thd, |
const char * | db_name, | ||
const char * | table_name, | ||
Alter_info * | alter_info | ||
) |
Method to prepare check constraints for the CREATE operation.
If name of the check constraint is not specified then name is generated, check constraint is pre-validated and MDL on check constraint is acquired.
thd | Thread handle. |
db_name | Database name. |
table_name | Table name. |
alter_info | Alter_info object with list of check constraints to be created. |
false | Success. |
true | Failure. |
|
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.
thd | Thread handle. |
src_table | Table_ref instance for source table. |
target_table | Table_ref instance for target table. |
alter_info | Alter_info instance to prepare list of check constraint spec for table being created. |
false | Success. |
true | Failure. |
bool prepare_create_field | ( | THD * | thd, |
const char * | error_schema_name, | ||
const char * | error_table_name, | ||
HA_CREATE_INFO * | create_info, | ||
List< Create_field > * | create_list, | ||
int * | select_field_pos, | ||
handler * | file, | ||
Create_field * | sql_field, | ||
int | field_no | ||
) |
Prepares the column definitions for table creation.
thd | Thread object. | |
error_schema_name | Schema name of the table used for error reporting. | |
error_table_name | Table name used for error reporting. | |
create_info | Create information. | |
[in,out] | create_list | List of columns to create. |
[in,out] | select_field_pos | Position where the SELECT columns start for CREATE TABLE ... SELECT. |
file | The handler for the new table. | |
[in,out] | sql_field | Create_field to populate. |
field_no | Column number. |
false | OK |
true | error |
|
static |
bool prepare_fields_and_keys | ( | THD * | thd, |
const dd::Table * | src_table, | ||
TABLE * | table, | ||
HA_CREATE_INFO * | create_info, | ||
Alter_info * | alter_info, | ||
Alter_table_ctx * | alter_ctx, | ||
const uint & | used_fields | ||
) |
Prepare Create_field and Key_spec objects for ALTER and upgrade.
[in,out] | thd | thread handle. Used as a memory pool and source of environment information. |
[in] | src_table | DD table object. Will be nullptr for temporary tables and during upgrade. |
[in] | table | the source table, open and locked Used as an interface to the storage engine to acquire additional information about the original table. |
[in,out] | create_info | A blob with CREATE/ALTER TABLE parameters |
[in,out] | alter_info | Another blob with ALTER/CREATE parameters. Originally create_info was used only in CREATE TABLE and alter_info only in ALTER TABLE. But since ALTER might end-up doing CREATE, this distinction is gone and we just carry around two structures. |
[in,out] | alter_ctx | Runtime context for ALTER TABLE. |
[in] | used_fields | used_fields from HA_CREATE_INFO. |
true | error, out of memory or a semantical error in ALTER TABLE instructions |
false | success |
bool prepare_fk_parent_key | ( | THD * | thd, |
handlerton * | hton, | ||
const dd::Table * | parent_table_def, | ||
const dd::Table * | old_parent_table_def, | ||
const dd::Table * | old_child_table_def, | ||
bool | is_self_referencing_fk, | ||
dd::Foreign_key * | fk | ||
) |
|
static |
Prepare FOREIGN_KEY struct with info about a foreign key.
thd | Thread handle. | |
create_info | Create info from parser. | |
alter_info | Alter_info structure describing ALTER TABLE. | |
db | Database name. | |
table_name | Table name. | |
is_partitioned | Indicates whether table is partitioned. | |
key_info_buffer | Array of indexes. | |
key_count | Number of indexes. | |
fk_info_all | FOREIGN_KEY array with foreign keys which were already processed. | |
fk_number | Number of foreign keys which were already processed. | |
se_supports_fks | Indicates whether SE supports FKs. If not only basic FK validation is performed. | |
find_parent_key | Indicates whether we need to lookup name of unique constraint in parent table for the FK. | |
[in,out] | fk_key | Parser info about new FK to prepare. |
[in,out] | fk_max_generated_name_number | Max value of number component among existing generated foreign key names. |
[out] | fk_info | Struct to populate. |
true | if error (error reported), false otherwise. |
|
static |
|
static |
bool prepare_pack_create_field | ( | THD * | thd, |
Create_field * | sql_field, | ||
longlong | table_flags | ||
) |
Prepare a create_table instance for packing.
thd | Thread handle | |
[in,out] | sql_field | field to prepare for packing |
table_flags | table flags |
|
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.
thd | Thread context.. | |
create_info | HA_CREATE_INFO describing table. | |
alter_info | Alter_info structure describing ALTER TABLE. | |
schema_name | Table schema name. | |
table_name | Table name. | |
key_info | Array of indexes. | |
key_count | Number of indexes. | |
existing_fks_table | dd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting. | |
[in,out] | fk | FOREIGN_KEY object describing pre-existing foreign key. |
true | if error (error reported), false otherwise. |
|
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.
thd | Thread context.. | |
create_info | HA_CREATE_INFO describing table. | |
alter_info | Alter_info structure describing table. | |
key_info | Array of indexes. | |
key_count | Number of indexes. | |
supporting_key | Supporting key for the foreign key. | |
existing_fks_table | dd::Table object for table version from which pre-existing foreign keys come from. Needed for error reporting. | |
referencing_fields | List of foreign key referencing fields. | |
[in,out] | fk | FOREIGN_KEY object describing pre-existing foreign key. |
true | if error (error reported), false otherwise. |
|
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.
thd | Thread handle. | |
hton | Handlerton for table's storage engine. | |
alter_info | Alter_info object describing parent table. | |
key_info_buffer | Array describing keys in parent table. | |
key_count | Number of keys in parent table. | |
supporting_key | Pointer to KEY representing the supporting index. | |
old_fk_table | dd::Table object from which pre-existing FK comes from. nullptr if this FK is newly added. | |
[in,out] | fk | FOREIGN_KEY object describing the FK, its unique_index_name member will be updated if matching unique constraint is found. |
Operation | result. False if success. |
|
static |
bool prepare_sp_create_field | ( | THD * | thd, |
Create_field * | field_def | ||
) |
Prepare an instance of Create_field for field creation (fill all necessary attributes).
Only used for stored programs.
[in] | thd | Thread handle |
[out] | field_def | An instance of initialized create_field |
void promote_first_timestamp_column | ( | List< Create_field > * | column_definitions | ) |
Modifies the first column definition whose SQL type is TIMESTAMP by adding the features DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.
column_definitions | The list of column definitions, in the physical order in which they appear in the table. |
|
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.
thd | Thread handle. | |
db | Database name. | |
cc_name | Check constraint name. | |
[out] | cc_mdl_request_list | MDL request list. |
false | Success. |
true | Failure. |
|
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.
thd | Thread handle. |
datetime_field | DATE/DATETIME column definition. |
bool quick_rm_table | ( | THD * | thd, |
handlerton * | base, | ||
const char * | db, | ||
const char * | table_name, | ||
uint | flags | ||
) |
Quickly remove a table.
thd | Thread context. |
base | The handlerton handle. |
db | The database name. |
table_name | The table name. |
flags | Flags for build_table_filename(). |
|
static |
Create table definition in the Data Dictionary.
The table is also created in the storage engine, depending on the 'no_ha_table' argument.
thd | Thread handler | |
path | Name of file (including database) | |
sch_obj | Schema. | |
db | Schema name. Cannot use dd::Schema::name() directly due to LCTN. | |
table_name | Table name | |
create_info | create info parameters | |
create_fields | Fields to create | |
keys | number of keys to create | |
key_info | Keys to create | |
keys_onoff | Enable or disable keys. | |
fk_keys | Number of foreign keys to create | |
fk_key_info | Foreign keys to create | |
check_cons_spec | List of check constraint specifications. | |
file | Handler to use | |
no_ha_table | Indicates that only definitions needs to be created and not a table in the storage engine. | |
do_not_store_in_dd | Indicates that we should postpone storing table object in the data-dictionary. Requires SE supporting atomic DDL and no_ha_table flag set. | |
part_info | Reference to partitioning data structure. | |
[out] | binlog_to_trx_cache | Which binlog cache should be used? If true => trx cache If false => stmt cache |
[out] | table_def_ptr | dd::Table object describing the table created if do_not_store_in_dd option was used. Not set otherwise. |
[out] | post_ddl_ht | Set to handlerton for table's SE, if this SE supports atomic DDL, so caller can call SE post DDL hook after committing transaction. |
false | ok |
true | error |
|
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.
thd | Thread handler | |
path | Name of file (including database) | |
sch_obj | Schema. | |
db | Schema name. Cannot use dd::Schema::name() directly due to LCTN. | |
table_name | Table name | |
create_info | create info parameters | |
create_fields | Fields to create | |
keys | number of keys to create | |
key_info | Keys to create | |
keys_onoff | Enable or disable keys. | |
check_cons_spec | List of check constraint specification. | |
file | Handler to use | |
no_ha_table | Indicates that only definitions needs to be created and not a table in the storage engine. | |
[out] | binlog_to_trx_cache | Which binlog cache should be used? If true => trx cache If false => stmt cache |
[out] | tmp_table_def | Data-dictionary object for temporary table which was created. Is not set if no_ha_table was false. |
false | ok |
true | error |
|
static |
|
static |
Unloads table from secondary engine if SECONDARY_ENGINE = NULL.
thd | Thread handler. |
table | Table opened in primary storage engine. |
create_info | Information from the parsing phase about new table properties. |
old_table_def | Definition of table before the alter statement. |
|
static |
Rename histograms from an old table name to a new table name.
thd | Thread handle |
old_schema_name | The old schema name |
old_table_name | The old table name |
new_schema_name | The new schema name |
new_table_name | The new table name |
|
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.
new_table | New table definition. |
|
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.
Discover missing tables in SE and acquire locks on tables which participate in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions will have to be updated or invalidated during this operation.
thd | Thread context. |
tables | Tables to be dropped by DROP TABLES/DATABASE. |
False | - Success. |
True | - Failure. |
|
static |
Auxiliary function which evaluates in which situation DROP TABLES is regarding GTID and different table groups.
|
static |
Auxiliary function which prepares for DROP TABLES execution by sorting tables to be dropped into groups according to their types.
|
static |
Loads a table from its primary engine into its secondary engine.
thd | Thread handler. | |
table | Table in primary storage engine. | |
[out] | skip_metadata_update | Should the DD metadata be updated for the load of this table |
|
static |
Unloads a table from its secondary engine.
thd | Thread handler. |
db_name | Database name. |
table_name | Table name. |
table_def | Table definition. |
error_if_not_loaded | If 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. |
|
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.
new_table | New table definition. |
alter_info | Alter_info object containing list of list of check constraint spec for table being altered. |
|
static |
Initialize TABLE::field for the new table with appropriate column static defaults.
altered_table | TABLE object for the new version of the table. |
create | Create_field list for new version of the table, which is used for identifying new columns. |
|
static |
|
static |
Rename table and/or turn indexes on/off without touching .FRM.
thd | Thread handler |
new_schema | Target schema. |
table_list | Table_ref for the table to change |
keys_onoff | ENABLE or DISABLE KEYS? |
alter_ctx | ALTER TABLE runtime context. |
false | Success |
true | Failure |
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.
|
static |
Check if a table is empty, i.e., it has no rows.
[in] | table | The table. |
[out] | is_empty | Set to true if the table is empty. |
false | Success. |
true | An error occurred (and has been reported with print_error). |
size_t tablename_to_filename | ( | const char * | from, |
char * | to, | ||
size_t | to_length | ||
) |
|
static |
|
static |
|
static |
|
static |
|
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.
[in] | thd | Thread handle. |
[in] | src_table | The source table. |
[in] | src_db_name | Original database name of table. |
[in] | src_table_name | Original table name of table. |
[in] | hton | Original storage engine. |
[in] | alter_info | Info about ALTER TABLE statement. |
[in] | new_create_list | List of new columns, used for rename check. |
[in,out] | drop_list | Copy of list of foreign keys to be dropped. |
[in,out] | alter_ctx | Runtime context for ALTER TABLE to which information about pre-existing foreign keys is added. |
|
static |
Mark fields participating in newly added indexes in TABLE object which corresponds to new version of altered table.
ha_alter_info | Alter_inplace_info describing in-place ALTER. |
altered_table | TABLE object for new version of TABLE in which fields should be marked. |
bool validate_comment_length | ( | THD * | thd, |
const char * | comment_str, | ||
size_t * | comment_len, | ||
uint | max_len, | ||
uint | err_code, | ||
const char * | comment_name | ||
) |
check comment length of table, column, index and partition
If comment length is more than the standard length truncate it and store the comment length up to the standard comment length size
thd | Thread handle | |
comment_str | Comment string | |
[in,out] | comment_len | Comment length |
max_len | Maximum allowed comment length | |
err_code | Error message | |
comment_name | Type of comment |
true | Error found |
false | On success |
|
static |
Validates the ALTER TABLE command with respect to any secondary engine operations.
alter_info | Alter table operations. |
create_info | Table option changes. |
table | The table that is being altered. |
|
static |
|
static |
|
static |
|
static |
int write_bin_log | ( | THD * | thd, |
bool | clear_error, | ||
const char * | query, | ||
size_t | query_length, | ||
bool | is_trans | ||
) |
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.
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.
|
staticconstexpr |
Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used).
|
staticconstexpr |
const char* primary_key_name = "PRIMARY" |