MySQL 8.4.0
Source Code Documentation
anonymous_namespace{sql_table.cc} Namespace Reference

Classes

struct  Handlerton_pair
 
class  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  sort_keys
 
struct  Viability
 

Typedefs

using Viability_error_emitter = std::function< void(const char *engine_name)>
 
using Viability_substitution_warning_emitter = std::function< void(THD *, const char *requested_engine_name, const char *substituted_engine_name, const char *table_name)>
 

Functions

bool is_temp_table (const HA_CREATE_INFO &ci)
 
bool is_engine_specified (const HA_CREATE_INFO &ci)
 
handlertondefault_handlerton (THD *thd, const HA_CREATE_INFO &ci)
 
handlertonrequested_handlerton (THD *thd, const HA_CREATE_INFO &ci)
 
Viability get_viability (const handlerton &hton, const HA_CREATE_INFO &ci)
 
handlertonget_viable_handlerton_for_create_impl (THD *thd, const char *table_name, const HA_CREATE_INFO &ci, Handlerton_pair hp)
 
handlertonget_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...
 
handlertonget_viable_handlerton_for_alter (THD *thd, const HA_CREATE_INFO &ci, handlerton *existing)
 Does nothing (returns existing) unless ALTER changes the ENGINE. More...
 
const dd::Indexfind_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...
 
bool 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 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 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...
 
template<class F >
bool 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 >
const dd::Indexfind_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 prepare_fk_parent_key (THD *thd, handlerton *hton, const dd::Table *parent_table_def, FOREIGN_KEY *fk)
 

Typedef Documentation

◆ Viability_error_emitter

using anonymous_namespace{sql_table.cc}::Viability_error_emitter = typedef std::function<void(const char *engine_name)>

◆ Viability_substitution_warning_emitter

using anonymous_namespace{sql_table.cc}::Viability_substitution_warning_emitter = typedef std::function<void( THD *, const char *requested_engine_name, const char *substituted_engine_name, const char *table_name)>

Function Documentation

◆ default_handlerton()

handlerton * anonymous_namespace{sql_table.cc}::default_handlerton ( THD thd,
const HA_CREATE_INFO ci 
)

◆ find_fk_parent_key() [1/2]

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.

Prefer unique key if possible.

Template Parameters
FFunction class which returns foreign key's column name by its index.
Parameters
thdThread handle.
htonHandlerton for tables' storage engine. Used to figure out what kind of parent keys are supported by the storage engine..
supporting_keySupporting key of the child. Needed to skip supporting keys as candidate parent keys for self referencing FKs.
parent_table_defdd::Table object describing the parent table.
fk_nameForeign key name.
fk_col_countNumber of columns in the foreign key.
fk_columnsObject of F type bound to the specific foreign key for which parent key check is carried out.
Return values
non-nullptr- pointer to dd::Index object describing the parent key.
nullptr- if no parent key were found.

◆ find_fk_parent_key() [2/2]

const dd::Index *anonymous_namespace sql_table anonymous_namespace{sql_table.cc}::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.

Prefer unique key if possible.

Parameters
htonHandlerton for tables' storage engine.
supporting_keySupporting key of the child. Needed to skip supporting keys as candidate parent keys for self referencing FKs.
parent_table_defdd::Table object describing the parent table.
fkdd::Foreign_key object describing the foreign key.
Return values
non-nullptr- pointer to dd::Index object describing the parent key.
nullptr- if no parent key were found.

◆ fk_is_key_exact_match_order() [1/2]

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.

Parameters
alter_infoAlter_info object describing parent table.
fkFOREIGN_KEY object describing the foreign key.
keyPointer to KEY representing the parent index.
Return values
True- Key is proper parent key for the foreign key.
False- Key can't be parent key for the foreign key.

◆ fk_is_key_exact_match_order() [2/2]

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.

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

◆ get_viability()

Viability anonymous_namespace{sql_table.cc}::get_viability ( const handlerton hton,
const HA_CREATE_INFO ci 
)

◆ get_viable_handlerton_for_alter()

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.

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

If the specified handleton is not viable it falls back to existing if substitution is allowed. existing is used without further checking, and ER_UNKNOWN_STORAGE_ENGINE is emitted as warning.

Parameters
thdThread handler.
cicreate info struct from parser.
existingHandlerton requested by query.
Return values
existingif ENGINE is not specified or is the same as existing, or if ENGINE is not viable and substitution is permitted.
Handlertonof specified engine if this is viable.
nullptrif error (specified engine not viable and substitution not permitted).

◆ get_viable_handlerton_for_create_impl()

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 
)

◆ get_viable_handlerton_for_create_like()

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.

If not; falls back to the default (tmp) storage engine if substitution is allowed, unless this is also disabled.

Otherwise, if substitution does take place, ER_DISABLED_STORAGE_ENGINE and ER_USING_OTHER_HANDLER are emitted as warnings.

For temporary tables the above also applies, and in addition the source handlerton is checked to see if it supports temporary tables.

Note that this substitution is allowed even when no_substitution is ON, but will fail if the default handlerton for temporary tables is disabled or does not support temporary tables (unlikely).

Parameters
thdThread handler.
table_nameTable name.
cicreate info struct from parser.
sourceHandlerton requested by query.
Return values
sourceif this is viable.
Thedefault hton if viable and engine substitution is allowed.
Thedefault temp hton if viable and a temporary table and source does not support temporary tables.
nullptrif error (source not viable and substitution not possible).

◆ is_engine_specified()

bool anonymous_namespace{sql_table.cc}::is_engine_specified ( const HA_CREATE_INFO ci)

◆ is_temp_table()

bool anonymous_namespace{sql_table.cc}::is_temp_table ( const HA_CREATE_INFO ci)

◆ prepare_fk_parent_key()

bool anonymous_namespace{sql_table.cc}::prepare_fk_parent_key ( THD thd,
handlerton hton,
const dd::Table parent_table_def,
FOREIGN_KEY fk 
)

◆ report_fk_index_error()

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.

Parameters
thdThread handle.
fk_nameName of the foreign key.
table_nameName of the referenced table name.

◆ requested_handlerton()

handlerton * anonymous_namespace{sql_table.cc}::requested_handlerton ( THD thd,
const HA_CREATE_INFO ci 
)

◆ warn_fk_on_non_standard_key()

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.

Parameters
thdThread handle.
key_nameName of the index key name.