MySQL 8.3.0
Source Code Documentation
handler0alter.cc File Reference

Smart ALTER TABLE. More...

#include <algorithm>
#include <bit>
#include <assert.h>
#include <current_thd.h>
#include <debug_sync.h>
#include <key_spec.h>
#include <log.h>
#include <mysql/plugin.h>
#include <sql_class.h>
#include <sql_lex.h>
#include <sql_table.h>
#include <sql_thd_internal_api.h>
#include <sys/types.h>
#include "ha_prototypes.h"
#include "db0err.h"
#include "dd/cache/dictionary_client.h"
#include "dd/dd.h"
#include "dd/dictionary.h"
#include "dd/impl/properties_impl.h"
#include "dd/impl/types/column_impl.h"
#include "dd/properties.h"
#include "dd/types/column.h"
#include "dd/types/column_type_element.h"
#include "dd/types/index.h"
#include "dd/types/index_element.h"
#include "dd/types/partition.h"
#include "dd/types/partition_index.h"
#include "dd/types/table.h"
#include "dd/types/tablespace_file.h"
#include "dd_table_share.h"
#include "btr0sea.h"
#include "ddl0bulk.h"
#include "dict0crea.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "dict0inst.h"
#include "dict0priv.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
#include "fsp0sysspace.h"
#include "fts0plugin.h"
#include "fts0priv.h"
#include "ha_innodb.h"
#include "ha_innopart.h"
#include "handler0alter.h"
#include "lex_string.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "log0ddl.h"
#include "my_dbug.h"
#include "my_io.h"
#include "mysql/strings/m_ctype.h"
#include "clone0api.h"
#include "ddl0ddl.h"
#include "lock0lock.h"
#include "mysqld_error.h"
#include "pars0pars.h"
#include "partition_info.h"
#include "rem0types.h"
#include "row0ins.h"
#include "row0log.h"
#include "row0sel.h"
#include "sql/create_field.h"
#include "srv0mon.h"
#include "trx0roll.h"
#include "trx0trx.h"
#include "ut0new.h"
#include "ut0stage.h"

Classes

struct  ha_innobase_inplace_ctx
 
struct  alter_table_old_info_t
 Structure to remember table information for updating DD. More...
 
class  ha_innopart_inplace_ctx
 Helper class for in-place alter partitioned table, see handler.h. More...
 
class  Altered_partitions
 Helper class for encapsulating new/altered partitions during ADD(HASH/KEY)/COALESCE/REORGANIZE PARTITION. More...
 
class  alter_part
 Class(interface) which manages the operations for partitions of states in different categories during ALTER PARTITION. More...
 
class  alter_part_factory
 Construct all necessary alter_part_* objects according to the given partition states in both old and new tables. More...
 
class  alter_parts
 Helper class for in-place alter partitions, see handler.h. More...
 
class  alter_part_normal
 Class which handles the partition of state PART_NORMAL. More...
 
class  alter_part_add
 Class which handles the partition of the state PART_TO_BE_ADDED. More...
 
class  alter_part_drop
 Class which handles the partition of states PART_TO_BE_DROPPED, PART_TO_BE_REORGED and PART_REORGED_DROPPED. More...
 
class  alter_part_change
 Class which handles the partition of the state PART_CHANGED. More...
 

Typedefs

typedef std::set< ulint, std::less< ulint >, ut::allocator< ulint > > col_set
 Set of column numbers. More...
 
typedef std::vector< alter_part *, ut::allocator< alter_part * > > alter_part_array
 

Functions

uint16_t instant_type_to_int (Instant_Type type)
 Function to convert the Instant_Type to a comparable int. More...
 
static UNIV_COLD void my_error_innodb (dberr_t error, const char *table, uint32_t flags)
 
static bool innobase_fulltext_exist (const TABLE *table)
 Determine if fulltext indexes exist in a given table. More...
 
static bool innobase_spatial_exist (const TABLE *table)
 Determine if spatial indexes exist in a given table. More...
 
static dd::Columnget_renamed_col (const Alter_inplace_info *ha_alter_info, const dd::Column *old_dd_column, const dd::Table *new_dd_tab)
 Get col in new table def of renamed column. More...
 
static uint32_t get_num_cols_added (const Alter_inplace_info *ha_alter_info)
 Get the number of columns being added using ALTER TABLE. More...
 
static void dd_inplace_alter_copy_instant_metadata (const Alter_inplace_info *ha_alter_info, const dd::Table *old_dd_tab, dd::Table *new_dd_tab)
 Copy metadata of dd::Table and dd::Columns from old table to new table. More...
 
static bool check_v_col_in_order (const TABLE *table, const TABLE *altered_table, const Alter_inplace_info *ha_alter_info)
 Check if virtual column in old and new table are in order, excluding those dropped column. More...
 
void innobase_discard_table (THD *thd, dict_table_t *table)
 Drop the statistics for a specified table, and mark it as discard after DDL. More...
 
static bool ok_to_rename_column (const Alter_inplace_info *ha_alter_info, const TABLE *old_table, const TABLE *altered_table, const dict_table_t *dict_table, bool instant, bool report_error)
 
static Instant_Type innobase_support_instant (const Alter_inplace_info *ha_alter_info, const dict_table_t *table, const TABLE *old_table, const TABLE *altered_table)
 Determine if one ALTER TABLE can be done instantly on the table. More...
 
static bool is_instant (const Alter_inplace_info *ha_alter_info)
 Determine if this is an instant ALTER TABLE. More...
 
static bool innobase_need_rebuild (const Alter_inplace_info *ha_alter_info)
 Determine if ALTER TABLE needs to rebuild the table. More...
 
template<typename Table >
static bool dd_prepare_inplace_alter_table (THD *thd, const dict_table_t *old_table, dict_table_t *new_table, const Table *old_dd_tab)
 Update the metadata in prepare phase. More...
 
template<typename Table >
static void dd_commit_inplace_alter_table (const alter_table_old_info_t &old_info, dict_table_t *new_table, const Table *old_dd_tab, Table *new_dd_tab)
 Update metadata in commit phase. More...
 
template<typename Table >
static void dd_commit_inplace_no_change (const Alter_inplace_info *ha_alter_info, const Table *old_dd_tab, Table *new_dd_tab, bool ignore_fts)
 Update metadata in commit phase when the alter table does no change to the table. More...
 
static void dd_commit_inplace_update_instant_meta (const dict_table_t *table, const dd::Table *old_dd_tab, dd::Table *new_dd_tab)
 Update table level instant metadata in commit phase. More...
 
static void dd_commit_inplace_update_partition_instant_meta (const Ha_innopart_share *part_share, uint16_t n_parts, const dd::Table *old_dd_tab, dd::Table *new_dd_tab)
 Update instant metadata in commit phase for partitioned table. More...
 
static bool innobase_init_foreign (dict_foreign_t *foreign, const char *constraint_name, dict_table_t *table, dict_index_t *index, const char **column_names, ulint num_field, const char *referenced_table_name, dict_table_t *referenced_table, dict_index_t *referenced_index, const char **referenced_column_names, ulint referenced_num_field)
 Initialize the dict_foreign_t structure with supplied info. More...
 
static bool innobase_check_fk_option (const dict_foreign_t *foreign)
 Check whether the foreign key options is legit. More...
 
static bool innobase_set_foreign_key_option (dict_foreign_t *foreign, const Foreign_key_spec *fk_key)
 Set foreign key options. More...
 
static const KEYinnobase_find_equiv_index (const char *const *col_names, uint n_cols, const KEY *keys, const uint *add, uint n_add)
 Check if a foreign key constraint can make use of an index that is being created. More...
 
static dict_index_tinnobase_find_fk_index (dict_table_t *table, const char **col_names, dict_index_t **drop_index, ulint n_drop_index, const char **columns, ulint n_cols)
 Find an index whose first fields are the columns in the array in the same order and is not marked for deletion. More...
 
static bool innobase_col_check_fk (const char *col_name, const dict_table_t *table, dict_s_col_list *s_cols)
 Check whether given column is a base of stored column. More...
 
static bool innobase_check_fk_stored (const dict_foreign_t *foreign, const dict_table_t *table, dict_s_col_list *s_cols)
 Check whether the foreign key constraint is on base of any stored columns. More...
 
static bool innobase_get_foreign_key_info (Alter_inplace_info *ha_alter_info, const TABLE_SHARE *table_share, dict_table_t *table, const char **col_names, dict_index_t **drop_index, ulint n_drop_index, dict_foreign_t **add_fk, ulint *n_add_fk, const trx_t *trx, dict_s_col_list *s_cols)
 Create InnoDB foreign key structure from MySQL alter_info. More...
 
static void innobase_col_to_mysql (const dict_col_t *col, const uchar *data, ulint len, Field *field)
 Copies an InnoDB column to a MySQL field. More...
 
void innobase_rec_to_mysql (struct TABLE *table, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
 Copies an InnoDB record to table->record[0]. More...
 
void innobase_fields_to_mysql (struct TABLE *table, const dict_index_t *index, const dfield_t *fields)
 Copies an InnoDB index entry to table->record[0]. More...
 
void innobase_row_to_mysql (struct TABLE *table, const dict_table_t *itab, const dtuple_t *row)
 Copies an InnoDB row to table->record[0]. More...
 
void innobase_rec_reset (TABLE *table)
 Resets table->record[0]. More...
 
static int innobase_check_index_keys (const Alter_inplace_info *info, const dict_table_t *innodb_table)
 This function checks that index keys are sensible. More...
 
static void innobase_create_index_field_def (const TABLE *altered_table, const KEY_PART_INFO *key_part, ddl::Index_field *index_field, bool new_clustered)
 Create index field definition for key part. More...
 
template<typename Index >
const dd::Indexget_dd_index (const Index *index)
 
template<>
const dd::Indexget_dd_index< dd::Index > (const dd::Index *dd_index)
 
template<>
const dd::Indexget_dd_index< dd::Partition_index > (const dd::Partition_index *dd_index)
 
template<typename Table >
static void innobase_create_index_def (const TABLE *altered_table, const Table *new_dd_tab, const KEY *keys, ulint key_number, bool new_clustered, bool key_clustered, ddl::Index_defn *index_def, mem_heap_t *heap)
 Create index definition for key. More...
 
bool innobase_fts_check_doc_id_col (const dict_table_t *table, const TABLE *altered_table, ulint *fts_doc_col_no, ulint *num_v)
 Check whether the table has the FTS_DOC_ID column. More...
 
enum fts_doc_id_index_enum innobase_fts_check_doc_id_index (const dict_table_t *table, const TABLE *altered_table, ulint *fts_doc_col_no)
 Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME on the Doc ID column. More...
 
enum fts_doc_id_index_enum innobase_fts_check_doc_id_index_in_def (ulint n_key, const KEY *key_info)
 Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME on the Doc ID column in MySQL create index definition. More...
 
template<typename Table >
static ddl::Index_defninnobase_create_key_defs (mem_heap_t *heap, const Alter_inplace_info *ha_alter_info, const TABLE *altered_table, const Table *new_dd_table, ulint &n_add, ulint &n_fts_add, bool got_default_clust, ulint &fts_doc_id_col, bool &add_fts_doc_id, bool &add_fts_doc_idx)
 Create an index table where indexes are ordered as follows: More...
 
static bool innobase_check_column_length (ulint max_col_len, const KEY *key_info)
 Check each index column size, make sure they do not exceed the max limit. More...
 
static bool check_col_exists_in_indexes (const dict_table_t *table, ulint col_no, bool is_v)
 Search for a given column in each index that is not being dropped. More...
 
static void reset_column_ord_part (dict_table_t *table)
 Reset dict_col_t::ord_part for those columns that fail to be indexed, Check every existing column to see if any current index references them. More...
 
static void online_retry_drop_dict_indexes (dict_table_t *table, bool locked)
 Drop in-memory metadata for index (dict_index_t) left from previous online ALTER operation. More...
 
bool innobase_dropping_foreign (const dict_foreign_t *foreign, dict_foreign_t **drop_fk, ulint n_drop_fk)
 Determines if InnoDB is dropping a foreign key constraint. More...
 
static void innobase_build_col_map_add (mem_heap_t *heap, dfield_t *dfield, const Field *field, ulint comp)
 Convert a default value for ADD COLUMN. More...
 
static const ulintinnobase_build_col_map (Alter_inplace_info *ha_alter_info, const TABLE *altered_table, const TABLE *table, const dict_table_t *new_table, const dict_table_t *old_table, dtuple_t *add_cols, mem_heap_t *heap)
 Construct the translation table for reordering, dropping or adding columns. More...
 
static dberr_t innobase_drop_fts_index_table (dict_table_t *table, trx_t *trx)
 Drop newly create FTS index related auxiliary table during FIC create index process, before fts_add_index is called. More...
 
static const char ** innobase_get_col_names (Alter_inplace_info *ha_alter_info, const TABLE *altered_table, const TABLE *table, const dict_table_t *user_table, mem_heap_t *heap)
 Get the new non-virtual column names if any columns were renamed. More...
 
static lint innobase_pk_col_prefix_compare (ulint new_prefix_len, ulint old_prefix_len)
 Check whether the column prefix is increased, decreased, or unchanged. More...
 
static bool innobase_pk_col_is_existing (const ulint new_col_no, const ulint *col_map, const ulint col_map_size)
 Check whether the column is existing in old table. More...
 
static bool innobase_pk_order_preserved (const ulint *col_map, const dict_index_t *old_clust_index, const dict_index_t *new_clust_index)
 Determine whether both the indexes have same set of primary key fields arranged in the same order. More...
 
static dberr_t innobase_check_gis_columns (Alter_inplace_info *ha_alter_info, dict_table_t *table)
 Check if we are creating spatial indexes on GIS columns, which are legacy columns from earlier MySQL, such as 5.6. More...
 
static bool prepare_inplace_change_implicit_tablespace_option (THD *thd, Alter_inplace_info *ha_alter_info, const dict_table_t *table)
 Update the attributes for the implicit tablespaces. More...
 
static bool prepare_inplace_add_virtual (Alter_inplace_info *ha_alter_info, const TABLE *altered_table, const TABLE *table)
 Collect virtual column info for its addition. More...
 
static bool prepare_inplace_drop_virtual (Alter_inplace_info *ha_alter_info, const TABLE *table)
 Collect virtual column info for its addition. More...
 
static void innodb_v_adjust_idx_col (const Alter_inplace_info *ha_alter_info, const TABLE *old_table, ulint num_v_dropped, ddl::Index_defn *index_def)
 Adjust the create index column number from "New table" to "old InnoDB table" while we are doing dropping virtual column. More...
 
static void replace_table_name (const char *filename, char *new_filename, const char *table_name)
 Replace the table name in filename with the specified one. More...
 
static bool innobase_check_index_len (const TABLE *form, ulint max_len)
 Check if a new table's index will exceed the index limit for the table row format. More...
 
template<typename Table >
static bool prepare_inplace_alter_table_dict (Alter_inplace_info *ha_alter_info, const TABLE *altered_table, const TABLE *old_table, const Table *old_dd_tab, Table *new_dd_tab, const char *table_name, uint32_t flags, uint32_t flags2, ulint fts_doc_id_col, bool add_fts_doc_id, bool add_fts_doc_id_idx)
 Update internal structures with concurrent writes blocked, while preparing ALTER TABLE. More...
 
static bool innobase_check_foreign_key_index (Alter_inplace_info *ha_alter_info, dict_index_t *index, dict_table_t *indexed_table, const char **col_names, trx_t *trx, dict_foreign_t **drop_fk, ulint n_drop_fk)
 
static void rename_index_in_cache (dict_index_t *index, const char *new_name)
 Rename a given index in the InnoDB data dictionary cache. More...
 
static void rename_indexes_in_cache (const ha_innobase_inplace_ctx *ctx, const Alter_inplace_info *ha_alter_info)
 Rename all indexes in data dictionary cache of a given table that are specified in ha_alter_info. More...
 
static void alter_fill_stored_column (const TABLE *altered_table, dict_table_t *table, dict_s_col_list **s_cols, mem_heap_t **s_heap)
 Fill the stored column information in s_cols list. More...
 
template<typename Table >
static void adjust_row_format (TABLE *old_table, TABLE *altered_table, const Table *old_dd_tab, Table *new_dd_tab)
 
static bool dict_col_in_v_indexes (dict_table_t *table, dict_col_t *col)
 Check that the column is part of a virtual index(index contains virtual column) in the table. More...
 
static bool alter_templ_needs_rebuild (TABLE *altered_table, Alter_inplace_info *ha_alter_info, dict_table_t *table)
 
static const char * get_error_key_name (ulint error_key_num, const Alter_inplace_info *ha_alter_info, const dict_table_t *table)
 Get the name of an erroneous key. More...
 
static void innobase_online_rebuild_log_free (dict_table_t *table)
 Free the modification log for online table rebuild. More...
 
static void innobase_rollback_sec_index (dict_table_t *user_table, const TABLE *table, bool locked, trx_t *trx)
 Rollback a secondary index creation, drop the indexes with temporary index prefix. More...
 
bool rollback_inplace_alter_table (const Alter_inplace_info *ha_alter_info, const TABLE *table, row_prebuilt_t *prebuilt)
 Roll back the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the storage engine. More...
 
static void innobase_rename_or_enlarge_columns_cache (Alter_inplace_info *ha_alter_info, const TABLE *table, dict_table_t *user_table)
 Rename or enlarge columns in the data dictionary cache as part of commit_cache_norebuild(). More...
 
static bool commit_get_autoinc (Alter_inplace_info *ha_alter_info, ha_innobase_inplace_ctx *ctx, const TABLE *altered_table, const TABLE *old_table)
 Get the auto-increment value of the table on commit. More...
 
static bool innobase_update_foreign_try (ha_innobase_inplace_ctx *ctx, trx_t *trx, const char *table_name)
 Add or drop foreign key constraints to the data dictionary tables, but do not touch the data dictionary cache. More...
 
static dberr_t innobase_update_foreign_cache (ha_innobase_inplace_ctx *ctx, THD *user_thd, dd::Table *dd_table)
 Update the foreign key constraint definitions in the data dictionary cache after the changes to data dictionary tables were committed. More...
 
static void innobase_rename_col_discard_foreign (Alter_inplace_info *ha_alter_info, const TABLE *mysql_table, dict_table_t *old_table)
 Discard the foreign key cache if anyone is affected by current column rename. More...
 
bool commit_try_rebuild (Alter_inplace_info *ha_alter_info, ha_innobase_inplace_ctx *ctx, TABLE *altered_table, const TABLE *old_table, trx_t *trx, const char *table_name)
 Commit the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the data dictionary tables, when rebuilding the table. More...
 
void commit_cache_rebuild (ha_innobase_inplace_ctx *ctx)
 Apply the changes made during commit_try_rebuild(), to the data dictionary cache and the file system. More...
 
static void get_col_list_to_be_dropped (const ha_innobase_inplace_ctx *ctx, col_set &drop_col_list, col_set &drop_v_col_list)
 Store the column number of the columns in a list belonging to indexes which are not being dropped. More...
 
bool commit_try_norebuild (Alter_inplace_info *ha_alter_info, ha_innobase_inplace_ctx *ctx, trx_t *trx, const char *table_name)
 Commit the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the data dictionary tables, when not rebuilding the table. More...
 
bool commit_cache_norebuild (ha_innobase_inplace_ctx *ctx, trx_t *trx)
 Commit the changes to the data dictionary cache after a successful commit_try_norebuild() call. More...
 
static void alter_stats_norebuild (Alter_inplace_info *ha_alter_info, ha_innobase_inplace_ctx *ctx, const char *table_name, THD *thd)
 Adjust the persistent statistics after non-rebuilding ALTER TABLE. More...
 
static void alter_stats_rebuild (dict_table_t *table, const char *table_name, THD *thd)
 Adjust the persistent statistics after rebuilding ALTER TABLE. More...
 
static bool is_drop_state (partition_state s)
 Check if the specified partition_state is of drop state. More...
 
static bool is_common_state (partition_state s)
 Check if the specified partition_state is of common state. More...
 
static Instant_Type innopart_support_instant (const Alter_inplace_info *ha_alter_info, uint16_t num_parts, const Ha_innopart_share *part_share, const TABLE *old_table, const TABLE *altered_table)
 Determine if one ALTER TABLE can be done instantly on the partitioned table. More...
 
static bool dd_part_has_datadir (const dd::Partition *dd_part)
 Check if the DATA DIRECTORY is specified (implicitly or explicitly) More...
 
void exchange_partition_adjust_datadir (dict_table_t *table_p, dict_table_t *table_s)
 Adjust data directory for exchange partition. More...
 

Variables

static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ONLINE_CREATE
 Operations for creating secondary indexes (no rebuild needed) More...
 
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD
 Operations for rebuilding a table in place. More...
 
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_DATA
 Operations that require changes to data. More...
 
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_INPLACE_IGNORE
 Operations for altering a table that InnoDB does not care about. More...
 
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_INSTANT_ALLOWED
 Operation allowed with ALGORITHM=INSTANT. More...
 
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_FOREIGN_OPERATIONS
 Operations on foreign key definitions (changing the schema only) More...
 
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_NOREBUILD
 Operations that InnoDB cares about and can perform without rebuild. More...
 

Detailed Description

Smart ALTER TABLE.

Typedef Documentation

◆ alter_part_array

typedef std::vector<alter_part *, ut::allocator<alter_part *> > alter_part_array

◆ col_set

typedef std::set<ulint, std::less<ulint>, ut::allocator<ulint> > col_set

Set of column numbers.

Function Documentation

◆ adjust_row_format()

template<typename Table >
static void adjust_row_format ( TABLE old_table,
TABLE altered_table,
const Table *  old_dd_tab,
Table *  new_dd_tab 
)
static

◆ alter_fill_stored_column()

static void alter_fill_stored_column ( const TABLE altered_table,
dict_table_t table,
dict_s_col_list **  s_cols,
mem_heap_t **  s_heap 
)
static

Fill the stored column information in s_cols list.

Parameters
[in]altered_tablemysql table object
[in]tableinnodb table object
[out]s_colslist of stored column
[out]s_heapheap for storing stored column information.

◆ alter_stats_norebuild()

static void alter_stats_norebuild ( Alter_inplace_info ha_alter_info,
ha_innobase_inplace_ctx ctx,
const char *  table_name,
THD thd 
)
static

Adjust the persistent statistics after non-rebuilding ALTER TABLE.

Remove statistics for dropped indexes, add statistics for created indexes and rename statistics for renamed indexes.

Parameters
ha_alter_infoData used during in-place alter
ctxIn-place ALTER TABLE context
table_nameTable name in MySQL
thdMySQL connection

◆ alter_stats_rebuild()

static void alter_stats_rebuild ( dict_table_t table,
const char *  table_name,
THD thd 
)
static

Adjust the persistent statistics after rebuilding ALTER TABLE.

Remove statistics for dropped indexes, add statistics for created indexes and rename statistics for renamed indexes.

Parameters
tableInnoDB table that was rebuilt by ALTER TABLE
table_nameTable name in MySQL
thdMySQL connection

◆ alter_templ_needs_rebuild()

static bool alter_templ_needs_rebuild ( TABLE altered_table,
Alter_inplace_info ha_alter_info,
dict_table_t table 
)
static

◆ check_col_exists_in_indexes()

static bool check_col_exists_in_indexes ( const dict_table_t table,
ulint  col_no,
bool  is_v 
)
static

Search for a given column in each index that is not being dropped.

Return true if the column is part of any of the active indexes or it is a system column.

Parameters
[in]tabletable object
[in]col_nocolumn number of the column which is to be checked
[in]is_vif this is a virtual column
Return values
truethe column exists or it is a system column
falsecolumn does not exist

◆ check_v_col_in_order()

static bool check_v_col_in_order ( const TABLE table,
const TABLE altered_table,
const Alter_inplace_info ha_alter_info 
)
static

Check if virtual column in old and new table are in order, excluding those dropped column.

This is needed because when we drop a virtual column, ALTER_VIRTUAL_COLUMN_ORDER is also turned on, so we can't decide if this is a real ORDER change or just DROP COLUMN

Parameters
[in]tableold TABLE
[in]altered_tablenew TABLE
[in]ha_alter_infoStructure describing changes to be done by ALTER TABLE and holding data used during in-place alter.
Returns
true is all columns in order, false otherwise.

◆ commit_cache_norebuild()

bool commit_cache_norebuild ( ha_innobase_inplace_ctx ctx,
trx_t trx 
)
inline

Commit the changes to the data dictionary cache after a successful commit_try_norebuild() call.

Parameters
ctxIn-place ALTER TABLE context
trxData dictionary transaction object (will be started and committed)
Returns
whether all replacements were found for dropped indexes

◆ commit_cache_rebuild()

void commit_cache_rebuild ( ha_innobase_inplace_ctx ctx)
inline

Apply the changes made during commit_try_rebuild(), to the data dictionary cache and the file system.

Parameters
ctxIn-place ALTER TABLE context

◆ commit_get_autoinc()

static bool commit_get_autoinc ( Alter_inplace_info ha_alter_info,
ha_innobase_inplace_ctx ctx,
const TABLE altered_table,
const TABLE old_table 
)
static

Get the auto-increment value of the table on commit.

Parameters
[in]ha_alter_infoData used during in-place alter
[in,out]ctxIn-place ALTER TABLE context return autoinc value in ctx->max_autoinc
[in]altered_tableMySQL table that is being altered
[in]old_tableMySQL table as it is before the ALTER operation
Return values
trueFailure
falseSuccess

◆ commit_try_norebuild()

bool commit_try_norebuild ( Alter_inplace_info ha_alter_info,
ha_innobase_inplace_ctx ctx,
trx_t trx,
const char *  table_name 
)
inline

Commit the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the data dictionary tables, when not rebuilding the table.

Parameters
[in]ha_alter_infoData used during in-place alter
[in]ctxIn-place ALTER TABLE context
[in]trxData dictionary transaction
[in]table_nameTable name in MySQL
Return values
trueFailure
falseSuccess

◆ commit_try_rebuild()

bool commit_try_rebuild ( Alter_inplace_info ha_alter_info,
ha_innobase_inplace_ctx ctx,
TABLE altered_table,
const TABLE old_table,
trx_t trx,
const char *  table_name 
)
inline

Commit the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the data dictionary tables, when rebuilding the table.

Parameters
ha_alter_infoData used during in-place alter
ctxIn-place ALTER TABLE context
altered_tableMySQL table that is being altered
old_tableMySQL table as it is before the ALTER operation
trxData dictionary transaction
table_nameTable name in MySQL
Return values
trueFailure
falseSuccess

◆ dd_commit_inplace_alter_table()

template<typename Table >
static void dd_commit_inplace_alter_table ( const alter_table_old_info_t old_info,
dict_table_t new_table,
const Table *  old_dd_tab,
Table *  new_dd_tab 
)
static

Update metadata in commit phase.

Note this function should only update the metadata which would not result in failure

Parameters
[in]old_infoSome table information for the old table
[in,out]new_tableNew InnoDB table object
[in]old_dd_tabOld dd::Table or dd::Partition
[in,out]new_dd_tabNew dd::Table or dd::Partition

◆ dd_commit_inplace_no_change()

template<typename Table >
static void dd_commit_inplace_no_change ( const Alter_inplace_info ha_alter_info,
const Table *  old_dd_tab,
Table *  new_dd_tab,
bool  ignore_fts 
)
static

Update metadata in commit phase when the alter table does no change to the table.

Parameters
[in]ha_alter_infothe DDL operation
[in]old_dd_tabOld dd::Table or dd::Partition
[in]new_dd_tabNew dd::Table or dd::Partition
[in]ignore_ftsignore FTS update if true

◆ dd_commit_inplace_update_instant_meta()

static void dd_commit_inplace_update_instant_meta ( const dict_table_t table,
const dd::Table old_dd_tab,
dd::Table new_dd_tab 
)
static

Update table level instant metadata in commit phase.

Update table level instant metadata in commit phase of INPLACE ALTER.

Parameters
[in]tableInnoDB table object
[in]old_dd_tabold dd::Table
[in]new_dd_tabnew dd::Table

◆ dd_commit_inplace_update_partition_instant_meta()

static void dd_commit_inplace_update_partition_instant_meta ( const Ha_innopart_share part_share,
uint16_t  n_parts,
const dd::Table old_dd_tab,
dd::Table new_dd_tab 
)
static

Update instant metadata in commit phase for partitioned table.

Parameters
[in]part_sharepartition share object to get each partitioned table
[in]n_partsnumber of partitions
[in]old_dd_tabold dd::Table
[in]new_dd_tabnew dd::Table

◆ dd_inplace_alter_copy_instant_metadata()

static void dd_inplace_alter_copy_instant_metadata ( const Alter_inplace_info ha_alter_info,
const dd::Table old_dd_tab,
dd::Table new_dd_tab 
)
static

Copy metadata of dd::Table and dd::Columns from old table to new table.

This is done during inplce alter table when table is not rebuilt.

Parameters
[in]ha_alter_infoinplace alter info
[in]old_dd_tabold table definition
[in,out]new_dd_tabnew table definition

◆ dd_part_has_datadir()

static bool dd_part_has_datadir ( const dd::Partition dd_part)
static

Check if the DATA DIRECTORY is specified (implicitly or explicitly)

Parameters
[in]dd_partThe dd::Partition to be checked
Return values
truethe DATA DIRECTORY is specified (implicitly or explicitly)
falseotherwise

◆ dd_prepare_inplace_alter_table()

template<typename Table >
static bool dd_prepare_inplace_alter_table ( THD thd,
const dict_table_t old_table,
dict_table_t new_table,
const Table *  old_dd_tab 
)
static

Update the metadata in prepare phase.

This only check if dd::Tablespace should be removed or(and) created, because to remove and store dd::Tablespace could fail, so it's better to do it earlier, to prevent a late rollback

Parameters
[in,out]thdMySQL connection
[in]old_tableOld InnoDB table object
[in,out]new_tableNew InnoDB table object
[in]old_dd_tabOld dd::Table or dd::Partition
Returns
false On success
Return values
trueOn failure

◆ dict_col_in_v_indexes()

static bool dict_col_in_v_indexes ( dict_table_t table,
dict_col_t col 
)
static

Check that the column is part of a virtual index(index contains virtual column) in the table.

Parameters
[in]tableTable containing column
[in]colcolumn to be checked
Returns
true if this column is indexed with other virtual columns

◆ exchange_partition_adjust_datadir()

void exchange_partition_adjust_datadir ( dict_table_t table_p,
dict_table_t table_s 
)

Adjust data directory for exchange partition.

Special handling of dict_table_t::data_dir_path is necessary if DATA DIRECTORY is specified. For example if DATA DIRECTORY Is '/tmp', the data directory for normal table is '/tmp/t1', while for partition is '/tmp'. So rename, the postfix table name 't1' should either be truncated or appended.

Parameters
[in]table_ppartition table
[in]table_sswap table

◆ get_col_list_to_be_dropped()

static void get_col_list_to_be_dropped ( const ha_innobase_inplace_ctx ctx,
col_set drop_col_list,
col_set drop_v_col_list 
)
static

Store the column number of the columns in a list belonging to indexes which are not being dropped.

Parameters
[in]ctxIn-place ALTER TABLE context
[in,out]drop_col_listlist which will be set, containing columns which is part of index being dropped
[in,out]drop_v_col_listlist which will be set, containing virtual columns which is part of index being dropped

◆ get_dd_index()

template<typename Index >
const dd::Index * get_dd_index ( const Index *  index)

◆ get_dd_index< dd::Index >()

template<>
const dd::Index * get_dd_index< dd::Index > ( const dd::Index dd_index)

◆ get_dd_index< dd::Partition_index >()

template<>
const dd::Index * get_dd_index< dd::Partition_index > ( const dd::Partition_index dd_index)

◆ get_error_key_name()

static const char * get_error_key_name ( ulint  error_key_num,
const Alter_inplace_info ha_alter_info,
const dict_table_t table 
)
static

Get the name of an erroneous key.

Parameters
[in]error_key_numInnoDB number of the erroneous key
[in]ha_alter_infochanges that were being performed
[in]tableInnoDB table
Returns
the name of the erroneous key

◆ get_num_cols_added()

static uint32_t get_num_cols_added ( const Alter_inplace_info ha_alter_info)
static

Get the number of columns being added using ALTER TABLE.

Parameters
[in]ha_alter_infoinplace alter info
Returns
number of columns added using ALTER TABLE

◆ get_renamed_col()

static dd::Column * get_renamed_col ( const Alter_inplace_info ha_alter_info,
const dd::Column old_dd_column,
const dd::Table new_dd_tab 
)
static

Get col in new table def of renamed column.

Parameters
[in]ha_alter_infoinplace alter info
[in]old_dd_columncolumn in old table
[in]new_dd_tabnew table definition
Returns
column if renamed, NULL otherwise

◆ innobase_build_col_map()

static const ulint * innobase_build_col_map ( Alter_inplace_info ha_alter_info,
const TABLE altered_table,
const TABLE table,
const dict_table_t new_table,
const dict_table_t old_table,
dtuple_t add_cols,
mem_heap_t heap 
)
static

Construct the translation table for reordering, dropping or adding columns.

Parameters
ha_alter_infoData used during in-place alter
altered_tableMySQL table that is being altered
tableMySQL table as it is before the ALTER operation
new_tableInnoDB table corresponding to MySQL altered_table
old_tableInnoDB table corresponding to MYSQL table
add_colsDefault values for ADD COLUMN, or NULL if no ADD COLUMN
heapMemory heap where allocated
Returns
array of integers, mapping column numbers in the table to column numbers in altered_table

◆ innobase_build_col_map_add()

static void innobase_build_col_map_add ( mem_heap_t heap,
dfield_t dfield,
const Field field,
ulint  comp 
)
static

Convert a default value for ADD COLUMN.

Parameters
heapMemory heap where allocated
dfieldInnoDB data field to copy to
fieldMySQL value for the column
compnonzero if in compact format

◆ innobase_check_column_length()

static bool innobase_check_column_length ( ulint  max_col_len,
const KEY key_info 
)
static

Check each index column size, make sure they do not exceed the max limit.

Returns
true if index column size exceeds limit
Parameters
max_col_lenin: maximum column length
key_infoin: Indexes to be created

◆ innobase_check_fk_option()

static bool innobase_check_fk_option ( const dict_foreign_t foreign)
static

Check whether the foreign key options is legit.

Returns
true if it is
Parameters
foreignin: foreign key

◆ innobase_check_fk_stored()

static bool innobase_check_fk_stored ( const dict_foreign_t foreign,
const dict_table_t table,
dict_s_col_list s_cols 
)
static

Check whether the foreign key constraint is on base of any stored columns.

Parameters
[in]foreignForeign key constraint information
[in]tabletable to which the foreign key objects to be added
[in]s_colslist of stored column information in the table.
Returns
true if yes, otherwise false.

◆ innobase_check_foreign_key_index()

static bool innobase_check_foreign_key_index ( Alter_inplace_info ha_alter_info,
dict_index_t index,
dict_table_t indexed_table,
const char **  col_names,
trx_t trx,
dict_foreign_t **  drop_fk,
ulint  n_drop_fk 
)
static
Parameters
ha_alter_infoin: Structure describing changes to be done by ALTER TABLE
indexin: index to check
indexed_tablein: table that owns the foreign keys
col_namesin: column names, or NULL for indexed_table->col_names
trxin/out: transaction
drop_fkin: Foreign key constraints to drop
n_drop_fkin: Number of foreign keys to drop

◆ innobase_check_gis_columns()

static dberr_t innobase_check_gis_columns ( Alter_inplace_info ha_alter_info,
dict_table_t table 
)
static

Check if we are creating spatial indexes on GIS columns, which are legacy columns from earlier MySQL, such as 5.6.

If so, we have to update the mtypes of the old GIS columns to DATA_GEOMETRY. In 5.6, we store GIS columns as DATA_BLOB in InnoDB layer, it will introduce confusion when we run latest server on older data. That's why we need to do the upgrade.

Parameters
[in]ha_alter_infoData used during in-place alter
[in]tableTable on which we want to add indexes
Returns
DB_SUCCESS if update successfully or no columns need to be updated, otherwise DB_ERROR, which means we can't update the mtype for some column, and creating spatial index on it should be dangerous

◆ innobase_check_index_keys()

static int innobase_check_index_keys ( const Alter_inplace_info info,
const dict_table_t innodb_table 
)
static

This function checks that index keys are sensible.

Returns
0 or error number
Parameters
infoin: indexes to be created or dropped
innodb_tablein: Existing indexes

◆ innobase_check_index_len()

static bool innobase_check_index_len ( const TABLE form,
ulint  max_len 
)
static

Check if a new table's index will exceed the index limit for the table row format.

Parameters
[in]formMySQL table that is being altered
[in]max_lenmax index length allowed
Returns
true if within limits false otherwise

◆ innobase_col_check_fk()

static bool innobase_col_check_fk ( const char *  col_name,
const dict_table_t table,
dict_s_col_list s_cols 
)
static

Check whether given column is a base of stored column.

Parameters
[in]col_namecolumn name
[in]tabletable
[in]s_colslist of stored columns
Returns
true if the given column is a base of stored column,else false.

◆ innobase_col_to_mysql()

static void innobase_col_to_mysql ( const dict_col_t col,
const uchar data,
ulint  len,
Field field 
)
static

Copies an InnoDB column to a MySQL field.

This function is adapted from row_sel_field_store_in_mysql_format().

Parameters
colin: InnoDB column
datain: InnoDB column data
lenin: length of data, in bytes
fieldin/out: MySQL field

◆ innobase_create_index_def()

template<typename Table >
static void innobase_create_index_def ( const TABLE altered_table,
const Table *  new_dd_tab,
const KEY keys,
ulint  key_number,
bool  new_clustered,
bool  key_clustered,
ddl::Index_defn index_def,
mem_heap_t heap 
)
static

Create index definition for key.

Parameters
[in]altered_tableMySQL table that is being altered
[in]new_dd_tabNew dd table
[in]keysKey definitions
[in]key_numberMySQL key number
[in]new_clusteredtrue if generating a new clustered index on the table
[in]key_clusteredtrue if this is the new clustered index
[out]index_defIndex definition
[in]heapheap where memory is allocated

◆ innobase_create_index_field_def()

static void innobase_create_index_field_def ( const TABLE altered_table,
const KEY_PART_INFO key_part,
ddl::Index_field index_field,
bool  new_clustered 
)
static

Create index field definition for key part.

Parameters
[in]altered_tableMySQL table that is being altered, or NULL if a new clustered index is not being created
[in]key_partMySQL key definition
[in,out]index_fieldindex field
[in]new_clusterednew cluster

◆ innobase_create_key_defs()

template<typename Table >
static ddl::Index_defn * innobase_create_key_defs ( mem_heap_t heap,
const Alter_inplace_info ha_alter_info,
const TABLE altered_table,
const Table *  new_dd_table,
ulint n_add,
ulint n_fts_add,
bool  got_default_clust,
ulint fts_doc_id_col,
bool &  add_fts_doc_id,
bool &  add_fts_doc_idx 
)
static

Create an index table where indexes are ordered as follows:

IF a new primary key is defined for the table THEN

    1) New primary key
    2) The remaining keys in key_info

ELSE

    1) All new indexes in the order they arrive from MySQL

ENDIF

Returns
key definitions
Parameters
heapin/out: memory heap where space for key definitions are allocated
ha_alter_infoin: alter operation
altered_tablein: MySQL table that is being altered
new_dd_tablein: new dd table
n_addin/out: number of indexes to be created
n_fts_addout: number of FTS indexes to be created
got_default_clustin: whether the table lacks a primary key
fts_doc_id_colin: The column number for Doc ID
add_fts_doc_idin: whether we need to add new DOC ID column for FTS index
add_fts_doc_idxin: whether we need to add new DOC ID index for FTS index

◆ innobase_discard_table()

void innobase_discard_table ( THD thd,
dict_table_t table 
)

Drop the statistics for a specified table, and mark it as discard after DDL.

Parameters
[in,out]thdTHD object
[in,out]tableInnoDB table object

◆ innobase_drop_fts_index_table()

static dberr_t innobase_drop_fts_index_table ( dict_table_t table,
trx_t trx 
)
static

Drop newly create FTS index related auxiliary table during FIC create index process, before fts_add_index is called.

Parameters
tabletable that was being rebuilt online
trxtransaction
Returns
DB_SUCCESS if successful, otherwise last error code

◆ innobase_dropping_foreign()

bool innobase_dropping_foreign ( const dict_foreign_t foreign,
dict_foreign_t **  drop_fk,
ulint  n_drop_fk 
)
inline

Determines if InnoDB is dropping a foreign key constraint.

Parameters
foreignthe constraint
drop_fkconstraints being dropped
n_drop_fknumber of constraints that are being dropped
Returns
whether the constraint is being dropped

◆ innobase_fields_to_mysql()

void innobase_fields_to_mysql ( struct TABLE table,
const dict_index_t index,
const dfield_t fields 
)

Copies an InnoDB index entry to table->record[0].

Parameters
[in,out]tableMysql table
[in]indexInnodb index
[in]fieldsInnodb index fields

◆ innobase_find_equiv_index()

static const KEY * innobase_find_equiv_index ( const char *const *  col_names,
uint  n_cols,
const KEY keys,
const uint *  add,
uint  n_add 
)
static

Check if a foreign key constraint can make use of an index that is being created.

Returns
usable index, or NULL if none found
Parameters
col_namesin: column names
n_colsin: number of columns
keysin: index information
addin: indexes being created
n_addin: number of indexes to create

◆ innobase_find_fk_index()

static dict_index_t * innobase_find_fk_index ( dict_table_t table,
const char **  col_names,
dict_index_t **  drop_index,
ulint  n_drop_index,
const char **  columns,
ulint  n_cols 
)
static

Find an index whose first fields are the columns in the array in the same order and is not marked for deletion.

Returns
matching index, NULL if not found
Parameters
tablein: table
col_namesin: column names, or NULL to use table->col_names
drop_indexin: indexes to be dropped
n_drop_indexin: size of drop_index[]
columnsin: array of column names
n_colsin: number of columns

◆ innobase_fts_check_doc_id_col()

bool innobase_fts_check_doc_id_col ( const dict_table_t table,
const TABLE altered_table,
ulint fts_doc_col_no,
ulint num_v 
)

Check whether the table has the FTS_DOC_ID column.

Returns
whether there exists an FTS_DOC_ID column
Parameters
tablein: InnoDB table with fulltext index
altered_tablein: MySQL table with fulltext index
fts_doc_col_noout: The column number for Doc ID, or ULINT_UNDEFINED if it is of wrong type
num_vout: number of virtual column

◆ innobase_fts_check_doc_id_index()

enum fts_doc_id_index_enum innobase_fts_check_doc_id_index ( const dict_table_t table,
const TABLE altered_table,
ulint fts_doc_col_no 
)

Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME on the Doc ID column.

Returns
the status of the FTS_DOC_ID index
Parameters
tablein: table definition
altered_tablein: MySQL table that is being altered
fts_doc_col_noout: The column number for Doc ID, or ULINT_UNDEFINED if it is being created in ha_alter_info

◆ innobase_fts_check_doc_id_index_in_def()

enum fts_doc_id_index_enum innobase_fts_check_doc_id_index_in_def ( ulint  n_key,
const KEY key_info 
)

Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME on the Doc ID column in MySQL create index definition.

Returns
FTS_EXIST_DOC_ID_INDEX if there exists the FTS_DOC_ID index, FTS_INCORRECT_DOC_ID_INDEX if the FTS_DOC_ID index is of wrong format
Parameters
n_keyin: Number of keys
key_infoin: Key definition

◆ innobase_fulltext_exist()

static bool innobase_fulltext_exist ( const TABLE table)
static

Determine if fulltext indexes exist in a given table.

Parameters
tableMySQL table
Returns
whether fulltext indexes exist on the table

◆ innobase_get_col_names()

static const char ** innobase_get_col_names ( Alter_inplace_info ha_alter_info,
const TABLE altered_table,
const TABLE table,
const dict_table_t user_table,
mem_heap_t heap 
)
static

Get the new non-virtual column names if any columns were renamed.

Parameters
ha_alter_infoData used during in-place alter
altered_tableMySQL table that is being altered
tableMySQL table as it is before the ALTER operation
user_tableInnoDB table as it is before the ALTER operation
heapMemory heap for the allocation
Returns
array of new column names in rebuilt_table, or NULL if not renamed

◆ innobase_get_foreign_key_info()

static bool innobase_get_foreign_key_info ( Alter_inplace_info ha_alter_info,
const TABLE_SHARE table_share,
dict_table_t table,
const char **  col_names,
dict_index_t **  drop_index,
ulint  n_drop_index,
dict_foreign_t **  add_fk,
ulint n_add_fk,
const trx_t trx,
dict_s_col_list s_cols 
)
static

Create InnoDB foreign key structure from MySQL alter_info.

Parameters
[in]ha_alter_infoalter table info
[in]table_shareTABLE_SHARE
[in]tabletable object
[in]col_namescolumn names, or NULL to use table->col_names
[in]drop_indexindexes to be dropped
[in]n_drop_indexsize of drop_index
[out]add_fkforeign constraint added
[out]n_add_fknumber of foreign constraints added
[in]trxuser transaction
[in]s_colslist of stored column information
Return values
trueif successful
falseon error (will call my_error())

◆ innobase_init_foreign()

static bool innobase_init_foreign ( dict_foreign_t foreign,
const char *  constraint_name,
dict_table_t table,
dict_index_t index,
const char **  column_names,
ulint  num_field,
const char *  referenced_table_name,
dict_table_t referenced_table,
dict_index_t referenced_index,
const char **  referenced_column_names,
ulint  referenced_num_field 
)
static

Initialize the dict_foreign_t structure with supplied info.

Returns
true if added, false if duplicate foreign->id
Parameters
foreignin/out: structure to initialize
constraint_namein/out: constraint name if exists
tablein: foreign table
indexin: foreign key index
column_namesin: foreign key column names
num_fieldin: number of columns
referenced_table_namein: referenced table name
referenced_tablein: referenced table
referenced_indexin: referenced index
referenced_column_namesin: referenced column names
referenced_num_fieldin: number of referenced columns

◆ innobase_need_rebuild()

static bool innobase_need_rebuild ( const Alter_inplace_info ha_alter_info)
static

Determine if ALTER TABLE needs to rebuild the table.

Parameters
[in]ha_alter_infoThe DDL operation
Returns
whether it is necessary to rebuild the table

◆ innobase_online_rebuild_log_free()

static void innobase_online_rebuild_log_free ( dict_table_t table)
static

Free the modification log for online table rebuild.

Parameters
tabletable that was being rebuilt online

◆ innobase_pk_col_is_existing()

static bool innobase_pk_col_is_existing ( const ulint  new_col_no,
const ulint col_map,
const ulint  col_map_size 
)
inlinestatic

Check whether the column is existing in old table.

Parameters
[in]new_col_nonew column no
[in]col_mapmapping of old column numbers to new ones
[in]col_map_sizethe column map size
Returns
true if the column is existing, otherwise false.

◆ innobase_pk_col_prefix_compare()

static lint innobase_pk_col_prefix_compare ( ulint  new_prefix_len,
ulint  old_prefix_len 
)
inlinestatic

Check whether the column prefix is increased, decreased, or unchanged.

Parameters
[in]new_prefix_lennew prefix length
[in]old_prefix_lennew prefix length
Return values
1prefix is increased
0prefix is unchanged
-1prefix is decreased

◆ innobase_pk_order_preserved()

static bool innobase_pk_order_preserved ( const ulint col_map,
const dict_index_t old_clust_index,
const dict_index_t new_clust_index 
)
static

Determine whether both the indexes have same set of primary key fields arranged in the same order.

Rules when we cannot skip sorting: (1) Removing existing PK columns somewhere else than at the end of the PK; (2) Adding existing columns to the PK, except at the end of the PK when no columns are removed from the PK; (3) Changing the order of existing PK columns; (4) Decreasing the prefix length just like removing existing PK columns follows rule(1), Increasing the prefix length just like adding existing PK columns follows rule(2); (5) Changing the ascending order of the existing PK columns.

Parameters
[in]col_mapmapping of old column numbers to new ones
[in]old_clust_indexindex to be compared
[in]new_clust_indexindex to be compared
Return values
trueif both indexes have same order.
false.

◆ innobase_rec_reset()

void innobase_rec_reset ( struct TABLE table)

Resets table->record[0].

in/out: MySQL table

Parameters
tablein/out: MySQL table

◆ innobase_rec_to_mysql()

void innobase_rec_to_mysql ( struct TABLE table,
const rec_t rec,
const dict_index_t index,
const ulint offsets 
)

Copies an InnoDB record to table->record[0].

Parameters
[in,out]tableMysql table
[in]recRecord
[in]indexIndex
[in]offsetsrec_get_offsets( rec, index, ...)

◆ innobase_rename_col_discard_foreign()

static void innobase_rename_col_discard_foreign ( Alter_inplace_info ha_alter_info,
const TABLE mysql_table,
dict_table_t old_table 
)
static

Discard the foreign key cache if anyone is affected by current column rename.

This is only used for rebuild case.

Parameters
[in]ha_alter_infodata used during in-place alter
[in]mysql_tableMySQL TABLE object
[in,out]old_tableInnoDB table object for old table

◆ innobase_rename_or_enlarge_columns_cache()

static void innobase_rename_or_enlarge_columns_cache ( Alter_inplace_info ha_alter_info,
const TABLE table,
dict_table_t user_table 
)
static

Rename or enlarge columns in the data dictionary cache as part of commit_cache_norebuild().

Parameters
ha_alter_infoData used during in-place alter.
tablethe TABLE
user_tableInnoDB table that was being altered

◆ innobase_rollback_sec_index()

static void innobase_rollback_sec_index ( dict_table_t user_table,
const TABLE table,
bool  locked,
trx_t trx 
)
static

Rollback a secondary index creation, drop the indexes with temporary index prefix.

Parameters
user_tableInnoDB table
tablethe TABLE
lockedtrue=table locked, false=may need to do a lazy drop
trxthe transaction

◆ innobase_row_to_mysql()

void innobase_row_to_mysql ( struct TABLE table,
const dict_table_t itab,
const dtuple_t row 
)

Copies an InnoDB row to table->record[0].

Parameters
[in,out]tableMysql table
[in]itabInnodb table
[in]rowInnodb row

◆ innobase_set_foreign_key_option()

static bool innobase_set_foreign_key_option ( dict_foreign_t foreign,
const Foreign_key_spec fk_key 
)
static

Set foreign key options.

Returns
true if successfully set
Parameters
foreignin:InnoDB Foreign key
fk_keyin: Foreign key info from MySQL

◆ innobase_spatial_exist()

static bool innobase_spatial_exist ( const TABLE table)
static

Determine if spatial indexes exist in a given table.

Parameters
tableMySQL table
Returns
whether spatial indexes exist on the table

◆ innobase_support_instant()

static Instant_Type innobase_support_instant ( const Alter_inplace_info ha_alter_info,
const dict_table_t table,
const TABLE old_table,
const TABLE altered_table 
)
inlinestatic

Determine if one ALTER TABLE can be done instantly on the table.

Parameters
[in]ha_alter_infoThe DDL operation
[in]tableInnoDB table
[in]old_tableold TABLE
[in]altered_tablenew TABLE
Returns
Instant_Type accordingly

< Only column RENAME

< Only virtual column ADD AND DROP

< Virtual column ADD/DROP with RENAME

< INSTANT ADD possibly with virtual column ADD and column RENAME

< INSTANT DROP possibly with virtual column ADD/DROP and column RENAME

◆ innobase_update_foreign_cache()

static dberr_t innobase_update_foreign_cache ( ha_innobase_inplace_ctx ctx,
THD user_thd,
dd::Table dd_table 
)
static

Update the foreign key constraint definitions in the data dictionary cache after the changes to data dictionary tables were committed.

Parameters
[in,out]ctxIn-place ALTER TABLE context
[in]user_thdMySQL connection
[in,out]dd_tabledd table instance
Returns
InnoDB error code (should always be DB_SUCCESS)

◆ innobase_update_foreign_try()

static bool innobase_update_foreign_try ( ha_innobase_inplace_ctx ctx,
trx_t trx,
const char *  table_name 
)
static

Add or drop foreign key constraints to the data dictionary tables, but do not touch the data dictionary cache.

Parameters
ctxIn-place ALTER TABLE context
trxData dictionary transaction
table_nameTable name in MySQL
Return values
trueFailure
falseSuccess

◆ innodb_v_adjust_idx_col()

static void innodb_v_adjust_idx_col ( const Alter_inplace_info ha_alter_info,
const TABLE old_table,
ulint  num_v_dropped,
ddl::Index_defn index_def 
)
static

Adjust the create index column number from "New table" to "old InnoDB table" while we are doing dropping virtual column.

Since we do not create separate new table for the dropping/adding virtual columns. To correctly find the indexed column, we will need to find its col_no in the "Old Table", not the "New table".

Parameters
[in]ha_alter_infoData used during in-place alter
[in]old_tableMySQL table as it is before the ALTER operation
[in]num_v_droppednumber of virtual column dropped
[in,out]index_defindex definition

◆ innopart_support_instant()

static Instant_Type innopart_support_instant ( const Alter_inplace_info ha_alter_info,
uint16_t  num_parts,
const Ha_innopart_share part_share,
const TABLE old_table,
const TABLE altered_table 
)
inlinestatic

Determine if one ALTER TABLE can be done instantly on the partitioned table.

Parameters
[in]ha_alter_infothe DDL operation
[in]num_partsnumber of partitions
[in]part_sharethe partitioned tables
[in]old_tableold TABLE
[in]altered_tablenew TABLE
Returns
Instant_Type accordingly

◆ instant_type_to_int()

uint16_t instant_type_to_int ( Instant_Type  type)
inline

Function to convert the Instant_Type to a comparable int.

◆ is_common_state()

static bool is_common_state ( partition_state  s)
inlinestatic

Check if the specified partition_state is of common state.

Parameters
[in]sThe state to be checked
Return values
trueif this is of a common state
falseif not

◆ is_drop_state()

static bool is_drop_state ( partition_state  s)
inlinestatic

Check if the specified partition_state is of drop state.

Parameters
[in]sThe state to be checked
Return values
trueif this is of a drop state
falseif not

◆ is_instant()

static bool is_instant ( const Alter_inplace_info ha_alter_info)
inlinestatic

Determine if this is an instant ALTER TABLE.

This can be checked in *inplace_alter_table() functions, which are called after check_if_supported_inplace_alter()

Parameters
[in]ha_alter_infoThe DDL operation
Returns
whether it's an instant ALTER TABLE

◆ my_error_innodb()

static UNIV_COLD void my_error_innodb ( dberr_t  error,
const char *  table,
uint32_t  flags 
)
static
Parameters
errorin: InnoDB error code
tablein: table name
flagsin: table flags

◆ ok_to_rename_column()

static bool ok_to_rename_column ( const Alter_inplace_info ha_alter_info,
const TABLE old_table,
const TABLE altered_table,
const dict_table_t dict_table,
bool  instant,
bool  report_error 
)
static

◆ online_retry_drop_dict_indexes()

static void online_retry_drop_dict_indexes ( dict_table_t table,
bool  locked 
)
static

Drop in-memory metadata for index (dict_index_t) left from previous online ALTER operation.

Parameters
[in]tabletable to check
[in]lockedif it is dict_sys mutex locked

◆ prepare_inplace_add_virtual()

static bool prepare_inplace_add_virtual ( Alter_inplace_info ha_alter_info,
const TABLE altered_table,
const TABLE table 
)
static

Collect virtual column info for its addition.

Parameters
[in]ha_alter_infoData used during in-place alter
[in]altered_tableMySQL table that is being altered to
[in]tableMySQL table as it is before the ALTER operation
Return values
trueFailure
falseSuccess

◆ prepare_inplace_alter_table_dict()

template<typename Table >
static bool prepare_inplace_alter_table_dict ( Alter_inplace_info ha_alter_info,
const TABLE altered_table,
const TABLE old_table,
const Table *  old_dd_tab,
Table *  new_dd_tab,
const char *  table_name,
uint32_t  flags,
uint32_t  flags2,
ulint  fts_doc_id_col,
bool  add_fts_doc_id,
bool  add_fts_doc_id_idx 
)
static

Update internal structures with concurrent writes blocked, while preparing ALTER TABLE.

Parameters
ha_alter_infoData used during in-place alter
altered_tableMySQL table that is being altered
old_tableMySQL table as it is before the ALTER operation
old_dd_tabold dd table
new_dd_tabnew dd table
table_nameTable name in MySQL
flagsTable and tablespace flags
flags2Additional table flags
fts_doc_id_colThe column number of FTS_DOC_ID
add_fts_doc_idFlag: add column FTS_DOC_ID?
add_fts_doc_id_idxFlag: add index FTS_DOC_ID_INDEX (FTS_DOC_ID)?
Return values
trueFailure
falseSuccess

◆ prepare_inplace_change_implicit_tablespace_option()

static bool prepare_inplace_change_implicit_tablespace_option ( THD thd,
Alter_inplace_info ha_alter_info,
const dict_table_t table 
)
static

Update the attributes for the implicit tablespaces.

Parameters
[in]thdTHD object
[in]ha_alter_infoData used during in-place alter
[in]tableMySQL table that is being modified
Returns
true Failure
false Success

◆ prepare_inplace_drop_virtual()

static bool prepare_inplace_drop_virtual ( Alter_inplace_info ha_alter_info,
const TABLE table 
)
static

Collect virtual column info for its addition.

Parameters
[in]ha_alter_infoData used during in-place alter
[in]tableMySQL table as it is before the ALTER operation
Return values
trueFailure
falseSuccess

◆ rename_index_in_cache()

static void rename_index_in_cache ( dict_index_t index,
const char *  new_name 
)
static

Rename a given index in the InnoDB data dictionary cache.

Parameters
[in,out]indexindex to rename
new_namenew index name

◆ rename_indexes_in_cache()

static void rename_indexes_in_cache ( const ha_innobase_inplace_ctx ctx,
const Alter_inplace_info ha_alter_info 
)
static

Rename all indexes in data dictionary cache of a given table that are specified in ha_alter_info.

Parameters
ctxalter context, used to fetch the list of indexes to rename
ha_alter_infofetch the new names from here

◆ replace_table_name()

static void replace_table_name ( const char *  filename,
char *  new_filename,
const char *  table_name 
)
static

Replace the table name in filename with the specified one.

Parameters
[in]filenameoriginal file name
[out]new_filenamenew file name
[in]table_nameto replace with this table name, in the format of db/name

◆ reset_column_ord_part()

static void reset_column_ord_part ( dict_table_t table)
inlinestatic

Reset dict_col_t::ord_part for those columns that fail to be indexed, Check every existing column to see if any current index references them.

This should be checked after an index is dropped during ALTER TABLE.

Parameters
[in,out]tableInnoDB table to check

◆ rollback_inplace_alter_table()

bool rollback_inplace_alter_table ( const Alter_inplace_info ha_alter_info,
const TABLE table,
row_prebuilt_t prebuilt 
)
inline

Roll back the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the storage engine.

Note that the allowed level of concurrency during this operation will be the same as for inplace_alter_table() and thus might be higher than during prepare_inplace_alter_table(). (E.g concurrent writes were blocked during prepare, but might not be during commit).

Parameters
[in]ha_alter_infoData used during in-place alter.
[in]tablethe TABLE
[in,out]prebuiltthe prebuilt struct
Return values
trueFailure
falseSuccess

Variable Documentation

◆ INNOBASE_ALTER_DATA

const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_DATA
static
Initial value:
=
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD
Operations for rebuilding a table in place.
Definition: handler0alter.cc:126
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ONLINE_CREATE
Operations for creating secondary indexes (no rebuild needed)
Definition: handler0alter.cc:121

Operations that require changes to data.

◆ INNOBASE_ALTER_NOREBUILD

const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_NOREBUILD
static
Initial value:
=
static const HA_ALTER_FLAGS ADD_VIRTUAL_COLUMN
Definition: handler.h:3368
static const HA_ALTER_FLAGS ALTER_COLUMN_INDEX_LENGTH
Change in index length such that it does not require index rebuild.
Definition: handler.h:3497
static const HA_ALTER_FLAGS ALTER_COLUMN_NAME
Definition: handler.h:3384
static const HA_ALTER_FLAGS ALTER_INDEX_COMMENT
Definition: handler.h:3477
static const HA_ALTER_FLAGS ALTER_COLUMN_EQUAL_PACK_LENGTH
Change column datatype in such way that new type has compatible packed representation with old type,...
Definition: handler.h:3396
static const HA_ALTER_FLAGS DROP_INDEX
Definition: handler.h:3351
static const HA_ALTER_FLAGS DROP_UNIQUE_INDEX
Definition: handler.h:3357
static const HA_ALTER_FLAGS ALTER_VIRTUAL_COLUMN_ORDER
A virtual column has changed its position.
Definition: handler.h:3399
static const HA_ALTER_FLAGS RENAME_INDEX
Rename index.
Definition: handler.h:3465
static const HA_ALTER_FLAGS DROP_VIRTUAL_COLUMN
Definition: handler.h:3378
static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_FOREIGN_OPERATIONS
Operations on foreign key definitions (changing the schema only)
Definition: handler0alter.cc:164

Operations that InnoDB cares about and can perform without rebuild.

◆ INNOBASE_ALTER_REBUILD

const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD
static
Initial value:
=
static const HA_ALTER_FLAGS RECREATE_TABLE
Recreate the table for ALTER TABLE FORCE, ALTER TABLE ENGINE and OPTIMIZE TABLE operations.
Definition: handler.h:3471
static const HA_ALTER_FLAGS ADD_STORED_BASE_COLUMN
Definition: handler.h:3370
static const HA_ALTER_FLAGS ADD_PK_INDEX
Definition: handler.h:3360
static const HA_ALTER_FLAGS ALTER_COLUMN_NOT_NULLABLE
Definition: handler.h:3408
static const HA_ALTER_FLAGS ALTER_COLUMN_NULLABLE
Definition: handler.h:3405
static const HA_ALTER_FLAGS DROP_PK_INDEX
Definition: handler.h:3363
static const HA_ALTER_FLAGS ALTER_STORED_COLUMN_ORDER
A stored column has changed its position (disregarding virtual columns)
Definition: handler.h:3402
static const HA_ALTER_FLAGS CHANGE_CREATE_OPTION
Definition: handler.h:3424
static const HA_ALTER_FLAGS DROP_STORED_COLUMN
Definition: handler.h:3379

Operations for rebuilding a table in place.

◆ INNOBASE_FOREIGN_OPERATIONS

const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_FOREIGN_OPERATIONS
static
Initial value:
=
static const HA_ALTER_FLAGS ADD_FOREIGN_KEY
Definition: handler.h:3418
static const HA_ALTER_FLAGS DROP_FOREIGN_KEY
Definition: handler.h:3421

Operations on foreign key definitions (changing the schema only)

◆ INNOBASE_INPLACE_IGNORE

const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_INPLACE_IGNORE
static
Initial value:
=
static const HA_ALTER_FLAGS CHANGE_INDEX_OPTION
Change index option in a way which is likely not to require index recreation.
Definition: handler.h:3487
static const HA_ALTER_FLAGS DROP_CHECK_CONSTRAINT
Definition: handler.h:3515
static const HA_ALTER_FLAGS ALTER_COLUMN_STORAGE_TYPE
Definition: handler.h:3430
static const HA_ALTER_FLAGS ALTER_COLUMN_COLUMN_FORMAT
Definition: handler.h:3433
static const HA_ALTER_FLAGS ADD_CHECK_CONSTRAINT
Definition: handler.h:3512
static const HA_ALTER_FLAGS ALTER_RENAME
Definition: handler.h:3427
static const HA_ALTER_FLAGS SUSPEND_CHECK_CONSTRAINT
Definition: handler.h:3518
static const HA_ALTER_FLAGS ALTER_COLUMN_VISIBILITY
Definition: handler.h:3521
static const HA_ALTER_FLAGS ALTER_COLUMN_DEFAULT
Definition: handler.h:3411

Operations for altering a table that InnoDB does not care about.

◆ INNOBASE_INSTANT_ALLOWED

◆ INNOBASE_ONLINE_CREATE

const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ONLINE_CREATE
static
Initial value:
=
static const HA_ALTER_FLAGS ADD_SPATIAL_INDEX
Definition: handler.h:3474
static const HA_ALTER_FLAGS ADD_INDEX
Definition: handler.h:3348
static const HA_ALTER_FLAGS ADD_UNIQUE_INDEX
Definition: handler.h:3354

Operations for creating secondary indexes (no rebuild needed)