MySQL 9.1.0
Source Code Documentation
|
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::Column * | get_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 KEY * | innobase_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_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) |
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::Index * | get_dd_index (const Index *index) |
template<> | |
const dd::Index * | get_dd_index< dd::Index > (const dd::Index *dd_index) |
template<> | |
const dd::Index * | get_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_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) |
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 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) |
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_part_len) |
Check if the key parts of the indexes of new table will exceed the index limit based on 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... | |
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... | |
Smart ALTER TABLE.
typedef std::vector<alter_part *, ut::allocator<alter_part *> > alter_part_array |
typedef std::set<ulint, std::less<ulint>, ut::allocator<ulint> > col_set |
Set of column numbers.
|
static |
|
static |
Fill the stored column information in s_cols list.
[in] | altered_table | mysql table object |
[in] | table | innodb table object |
[out] | s_cols | list of stored column |
[out] | s_heap | heap for storing stored column information. |
|
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.
ha_alter_info | Data used during in-place alter |
ctx | In-place ALTER TABLE context |
table_name | Table name in MySQL |
thd | MySQL connection |
void alter_stats_rebuild | ( | dict_table_t * | table, |
const char * | table_name, | ||
THD * | thd | ||
) |
Adjust the persistent statistics after rebuilding ALTER TABLE.
Remove statistics for dropped indexes, add statistics for created indexes and rename statistics for renamed indexes.
table | InnoDB table that was rebuilt by ALTER TABLE |
table_name | Table name in MySQL |
thd | MySQL connection |
|
static |
|
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.
[in] | table | table object |
[in] | col_no | column number of the column which is to be checked |
[in] | is_v | if this is a virtual column |
true | the column exists or it is a system column |
false | column does not exist |
|
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
[in] | table | old TABLE |
[in] | altered_table | new TABLE |
[in] | ha_alter_info | Structure describing changes to be done by ALTER TABLE and holding data used during in-place alter. |
|
inline |
Commit the changes to the data dictionary cache after a successful commit_try_norebuild() call.
ctx | In-place ALTER TABLE context |
trx | Data dictionary transaction object (will be started and committed) |
|
inline |
Apply the changes made during commit_try_rebuild(), to the data dictionary cache and the file system.
ctx | In-place ALTER TABLE context |
|
static |
Get the auto-increment value of the table on commit.
[in] | ha_alter_info | Data used during in-place alter |
[in,out] | ctx | In-place ALTER TABLE context return autoinc value in ctx->max_autoinc |
[in] | altered_table | MySQL table that is being altered |
[in] | old_table | MySQL table as it is before the ALTER operation |
true | Failure |
false | Success |
|
inline |
Commit the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the data dictionary tables, when not rebuilding the table.
[in] | ha_alter_info | Data used during in-place alter |
[in] | ctx | In-place ALTER TABLE context |
[in] | trx | Data dictionary transaction |
[in] | table_name | Table name in MySQL |
true | Failure |
false | Success |
|
inline |
Commit the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the data dictionary tables, when rebuilding the table.
ha_alter_info | Data used during in-place alter |
ctx | In-place ALTER TABLE context |
altered_table | MySQL table that is being altered |
old_table | MySQL table as it is before the ALTER operation |
trx | Data dictionary transaction |
table_name | Table name in MySQL |
true | Failure |
false | Success |
|
static |
Update metadata in commit phase.
Note this function should only update the metadata which would not result in failure
[in] | old_info | Some table information for the old table |
[in,out] | new_table | New InnoDB table object |
[in] | old_dd_tab | Old dd::Table or dd::Partition |
[in,out] | new_dd_tab | New dd::Table or dd::Partition |
|
static |
Update metadata in commit phase when the alter table does no change to the table.
[in] | ha_alter_info | the DDL operation |
[in] | old_dd_tab | Old dd::Table or dd::Partition |
[in] | new_dd_tab | New dd::Table or dd::Partition |
[in] | ignore_fts | ignore FTS update if true |
|
static |
Update table level instant metadata in commit phase.
Update table level instant metadata in commit phase of INPLACE ALTER.
[in] | table | InnoDB table object |
[in] | old_dd_tab | old dd::Table |
[in] | new_dd_tab | new dd::Table |
|
static |
Update instant metadata in commit phase for partitioned table.
[in] | part_share | partition share object to get each partitioned table |
[in] | n_parts | number of partitions |
[in] | old_dd_tab | old dd::Table |
[in] | new_dd_tab | new dd::Table |
|
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.
[in] | ha_alter_info | inplace alter info |
[in] | old_dd_tab | old table definition |
[in,out] | new_dd_tab | new table definition |
|
static |
Check if the DATA DIRECTORY is specified (implicitly or explicitly)
[in] | dd_part | The dd::Partition to be checked |
true | the DATA DIRECTORY is specified (implicitly or explicitly) |
false | otherwise |
|
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
[in,out] | thd | MySQL connection |
[in] | old_table | Old InnoDB table object |
[in,out] | new_table | New InnoDB table object |
[in] | old_dd_tab | Old dd::Table or dd::Partition |
true | On failure |
|
static |
Check that the column is part of a virtual index(index contains virtual column) in the table.
[in] | table | Table containing column |
[in] | col | column to be checked |
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.
[in] | table_p | partition table |
[in] | table_s | swap table |
|
static |
Store the column number of the columns in a list belonging to indexes which are not being dropped.
[in] | ctx | In-place ALTER TABLE context |
[in,out] | drop_col_list | list which will be set, containing columns which is part of index being dropped |
[in,out] | drop_v_col_list | list which will be set, containing virtual columns which is part of index being dropped |
const dd::Index * get_dd_index | ( | const Index * | index | ) |
const dd::Index * get_dd_index< dd::Index > | ( | const dd::Index * | dd_index | ) |
const dd::Index * get_dd_index< dd::Partition_index > | ( | const dd::Partition_index * | dd_index | ) |
|
static |
Get the name of an erroneous key.
[in] | error_key_num | InnoDB number of the erroneous key |
[in] | ha_alter_info | changes that were being performed |
[in] | table | InnoDB table |
|
static |
Get the number of columns being added using ALTER TABLE.
[in] | ha_alter_info | inplace alter info |
|
static |
Get col in new table def of renamed column.
[in] | ha_alter_info | inplace alter info |
[in] | old_dd_column | column in old table |
[in] | new_dd_tab | new table definition |
|
static |
Construct the translation table for reordering, dropping or adding columns.
ha_alter_info | Data used during in-place alter |
altered_table | MySQL table that is being altered |
table | MySQL table as it is before the ALTER operation |
new_table | InnoDB table corresponding to MySQL altered_table |
old_table | InnoDB table corresponding to MYSQL table |
add_cols | Default values for ADD COLUMN, or NULL if no ADD COLUMN |
heap | Memory heap where allocated |
|
static |
Convert a default value for ADD COLUMN.
heap | Memory heap where allocated |
dfield | InnoDB data field to copy to |
field | MySQL value for the column |
comp | nonzero if in compact format |
Check each index column size, make sure they do not exceed the max limit.
max_col_len | in: maximum column length |
key_info | in: Indexes to be created |
|
static |
Check whether the foreign key options is legit.
foreign | in: foreign key |
|
static |
Check whether the foreign key constraint is on base of any stored columns.
[in] | foreign | Foreign key constraint information |
[in] | table | table to which the foreign key objects to be added |
[in] | s_cols | list of stored column information in the table. |
|
static |
ha_alter_info | in: Structure describing changes to be done by ALTER TABLE |
index | in: index to check |
indexed_table | in: table that owns the foreign keys |
col_names | in: column names, or NULL for indexed_table->col_names |
trx | in/out: transaction |
drop_fk | in: Foreign key constraints to drop |
n_drop_fk | in: Number of foreign keys to drop |
|
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.
[in] | ha_alter_info | Data used during in-place alter |
[in] | table | Table on which we want to add indexes |
|
static |
This function checks that index keys are sensible.
info | in: indexes to be created or dropped |
innodb_table | in: Existing indexes |
Check if the key parts of the indexes of new table will exceed the index limit based on the table row format.
[in] | form | MySQL table that is being altered |
[in] | max_part_len | max index part length allowed |
|
static |
Check whether given column is a base of stored column.
[in] | col_name | column name |
[in] | table | table |
[in] | s_cols | list of stored columns |
|
static |
Copies an InnoDB column to a MySQL field.
This function is adapted from row_sel_field_store_in_mysql_format().
col | in: InnoDB column |
data | in: InnoDB column data |
len | in: length of data, in bytes |
field | in/out: MySQL field |
|
static |
Create index definition for key.
[in] | altered_table | MySQL table that is being altered |
[in] | new_dd_tab | New dd table |
[in] | keys | Key definitions |
[in] | key_number | MySQL key number |
[in] | new_clustered | true if generating a new clustered index on the table |
[in] | key_clustered | true if this is the new clustered index |
[out] | index_def | Index definition |
[in] | heap | heap where memory is allocated |
|
static |
Create index field definition for key part.
[in] | altered_table | MySQL table that is being altered, or NULL if a new clustered index is not being created |
[in] | key_part | MySQL key definition |
[in,out] | index_field | index field |
[in] | new_clustered | new cluster |
|
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
heap | in/out: memory heap where space for key definitions are allocated |
ha_alter_info | in: alter operation |
altered_table | in: MySQL table that is being altered |
new_dd_table | in: new dd table |
n_add | in/out: number of indexes to be created |
n_fts_add | out: number of FTS indexes to be created |
got_default_clust | in: whether the table lacks a primary key |
fts_doc_id_col | in: The column number for Doc ID |
add_fts_doc_id | in: whether we need to add new DOC ID column for FTS index |
add_fts_doc_idx | in: whether we need to add new DOC ID index for FTS index |
void innobase_discard_table | ( | THD * | thd, |
dict_table_t * | table | ||
) |
Drop the statistics for a specified table, and mark it as discard after DDL.
[in,out] | thd | THD object |
[in,out] | table | InnoDB table object |
|
static |
Drop newly create FTS index related auxiliary table during FIC create index process, before fts_add_index is called.
table | table that was being rebuilt online |
trx | transaction |
|
inline |
Determines if InnoDB is dropping a foreign key constraint.
foreign | the constraint |
drop_fk | constraints being dropped |
n_drop_fk | number of constraints that are being dropped |
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].
[in,out] | table | Mysql table |
[in] | index | Innodb index |
[in] | fields | Innodb index fields |
|
static |
Check if a foreign key constraint can make use of an index that is being created.
col_names | in: column names |
n_cols | in: number of columns |
keys | in: index information |
add | in: indexes being created |
n_add | in: number of indexes to create |
|
static |
Find an index whose first fields are the columns in the array in the same order and is not marked for deletion.
table | in: table |
col_names | in: column names, or NULL to use table->col_names |
drop_index | in: indexes to be dropped |
n_drop_index | in: size of drop_index[] |
columns | in: array of column names |
n_cols | in: number of columns |
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.
table | in: InnoDB table with fulltext index |
altered_table | in: MySQL table with fulltext index |
fts_doc_col_no | out: The column number for Doc ID, or ULINT_UNDEFINED if it is of wrong type |
num_v | out: number of virtual column |
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.
table | in: table definition |
altered_table | in: MySQL table that is being altered |
fts_doc_col_no | out: The column number for Doc ID, or ULINT_UNDEFINED if it is being created in ha_alter_info |
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.
n_key | in: Number of keys |
key_info | in: Key definition |
|
static |
Determine if fulltext indexes exist in a given table.
table | MySQL table |
|
static |
Get the new non-virtual column names if any columns were renamed.
ha_alter_info | Data used during in-place alter |
altered_table | MySQL table that is being altered |
table | MySQL table as it is before the ALTER operation |
user_table | InnoDB table as it is before the ALTER operation |
heap | Memory heap for the allocation |
|
static |
Create InnoDB foreign key structure from MySQL alter_info.
[in] | ha_alter_info | alter table info |
[in] | table_share | TABLE_SHARE |
[in] | table | table object |
[in] | col_names | column names, or NULL to use table->col_names |
[in] | drop_index | indexes to be dropped |
[in] | n_drop_index | size of drop_index |
[out] | add_fk | foreign constraint added |
[out] | n_add_fk | number of foreign constraints added |
[in] | trx | user transaction |
[in] | s_cols | list of stored column information |
true | if successful |
false | on error (will call my_error()) |
|
static |
Initialize the dict_foreign_t structure with supplied info.
foreign | in/out: structure to initialize |
constraint_name | in/out: constraint name if exists |
table | in: foreign table |
index | in: foreign key index |
column_names | in: foreign key column names |
num_field | in: number of columns |
referenced_table_name | in: referenced table name |
referenced_table | in: referenced table |
referenced_index | in: referenced index |
referenced_column_names | in: referenced column names |
referenced_num_field | in: number of referenced columns |
|
static |
Determine if ALTER TABLE needs to rebuild the table.
[in] | ha_alter_info | The DDL operation |
|
static |
Free the modification log for online table rebuild.
table | table that was being rebuilt online |
|
inlinestatic |
Check whether the column is existing in old table.
[in] | new_col_no | new column no |
[in] | col_map | mapping of old column numbers to new ones |
[in] | col_map_size | the column map size |
|
inlinestatic |
Check whether the column prefix is increased, decreased, or unchanged.
[in] | new_prefix_len | new prefix length |
[in] | old_prefix_len | new prefix length |
1 | prefix is increased |
0 | prefix is unchanged |
-1 | prefix is decreased |
|
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.
[in] | col_map | mapping of old column numbers to new ones |
[in] | old_clust_index | index to be compared |
[in] | new_clust_index | index to be compared |
true | if both indexes have same order. |
false | . |
void innobase_rec_reset | ( | struct TABLE * | table | ) |
Resets table->record[0].
in/out: MySQL table
table | in/out: MySQL table |
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].
[in,out] | table | Mysql table |
[in] | rec | Record |
[in] | index | Index |
[in] | offsets | rec_get_offsets( rec, index, ...) |
|
static |
Discard the foreign key cache if anyone is affected by current column rename.
This is only used for rebuild case.
[in] | ha_alter_info | data used during in-place alter |
[in] | mysql_table | MySQL TABLE object |
[in,out] | old_table | InnoDB table object for old table |
|
static |
Rename or enlarge columns in the data dictionary cache as part of commit_cache_norebuild().
ha_alter_info | Data used during in-place alter. |
table | the TABLE |
user_table | InnoDB table that was being altered |
|
static |
Rollback a secondary index creation, drop the indexes with temporary index prefix.
user_table | InnoDB table |
table | the TABLE |
locked | true=table locked, false=may need to do a lazy drop |
trx | the transaction |
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].
[in,out] | table | Mysql table |
[in] | itab | Innodb table |
[in] | row | Innodb row |
|
static |
Set foreign key options.
foreign | in:InnoDB Foreign key |
fk_key | in: Foreign key info from MySQL |
|
static |
Determine if spatial indexes exist in a given table.
table | MySQL table |
|
inlinestatic |
Determine if one ALTER TABLE can be done instantly on the table.
[in] | ha_alter_info | The DDL operation |
[in] | table | InnoDB table |
[in] | old_table | old TABLE |
[in] | altered_table | new TABLE |
< 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
|
static |
Update the foreign key constraint definitions in the data dictionary cache after the changes to data dictionary tables were committed.
[in,out] | ctx | In-place ALTER TABLE context |
[in] | user_thd | MySQL connection |
[in,out] | dd_table | dd table instance |
|
static |
Add or drop foreign key constraints to the data dictionary tables, but do not touch the data dictionary cache.
ctx | In-place ALTER TABLE context |
trx | Data dictionary transaction |
table_name | Table name in MySQL |
true | Failure |
false | Success |
|
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".
[in] | ha_alter_info | Data used during in-place alter |
[in] | old_table | MySQL table as it is before the ALTER operation |
[in] | num_v_dropped | number of virtual column dropped |
[in,out] | index_def | index definition |
|
inlinestatic |
Determine if one ALTER TABLE can be done instantly on the partitioned table.
[in] | ha_alter_info | the DDL operation |
[in] | num_parts | number of partitions |
[in] | part_share | the partitioned tables |
[in] | old_table | old TABLE |
[in] | altered_table | new TABLE |
|
inline |
Function to convert the Instant_Type to a comparable int.
|
inlinestatic |
Check if the specified partition_state is of common state.
[in] | s | The state to be checked |
true | if this is of a common state |
false | if not |
|
inlinestatic |
Check if the specified partition_state is of drop state.
[in] | s | The state to be checked |
true | if this is of a drop state |
false | if not |
|
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()
[in] | ha_alter_info | The DDL operation |
error | in: InnoDB error code |
table | in: table name |
flags | in: table flags |
|
static |
|
static |
Drop in-memory metadata for index (dict_index_t) left from previous online ALTER operation.
[in] | table | table to check |
[in] | locked | if it is dict_sys mutex locked |
|
static |
Collect virtual column info for its addition.
[in] | ha_alter_info | Data used during in-place alter |
[in] | altered_table | MySQL table that is being altered to |
[in] | table | MySQL table as it is before the ALTER operation |
true | Failure |
false | Success |
|
static |
Update internal structures with concurrent writes blocked, while preparing ALTER TABLE.
ha_alter_info | Data used during in-place alter |
altered_table | MySQL table that is being altered |
old_table | MySQL table as it is before the ALTER operation |
old_dd_tab | old dd table |
new_dd_tab | new dd table |
table_name | Table name in MySQL |
flags | Table and tablespace flags |
flags2 | Additional table flags |
fts_doc_id_col | The column number of FTS_DOC_ID |
add_fts_doc_id | Flag: add column FTS_DOC_ID? |
add_fts_doc_id_idx | Flag: add index FTS_DOC_ID_INDEX (FTS_DOC_ID)? |
true | Failure |
false | Success |
|
static |
Update the attributes for the implicit tablespaces.
[in] | thd | THD object |
[in] | ha_alter_info | Data used during in-place alter |
[in] | table | MySQL table that is being modified |
|
static |
Collect virtual column info for its addition.
[in] | ha_alter_info | Data used during in-place alter |
[in] | table | MySQL table as it is before the ALTER operation |
true | Failure |
false | Success |
|
static |
Rename a given index in the InnoDB data dictionary cache.
[in,out] | index | index to rename |
new_name | new index name |
|
static |
Rename all indexes in data dictionary cache of a given table that are specified in ha_alter_info.
ctx | alter context, used to fetch the list of indexes to rename |
ha_alter_info | fetch the new names from here |
|
static |
Replace the table name in filename with the specified one.
[in] | filename | original file name |
[out] | new_filename | new file name |
[in] | table_name | to replace with this table name, in the format of db/name |
|
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.
[in,out] | table | InnoDB table to check |
|
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).
[in] | ha_alter_info | Data used during in-place alter. |
[in] | table | the TABLE |
[in,out] | prebuilt | the prebuilt struct |
true | Failure |
false | Success |
|
static |
Operations that require changes to data.
|
static |
Operations that InnoDB cares about and can perform without rebuild.
|
static |
Operations for rebuilding a table in place.
|
static |
Operations on foreign key definitions (changing the schema only)
|
static |
Operations for altering a table that InnoDB does not care about.
|
static |
Operation allowed with ALGORITHM=INSTANT.
|
static |
Operations for creating secondary indexes (no rebuild needed)