2014-05-07 22:36:25 +02:00
|
|
|
/* Copyright (c) 2010, 2014, Oracle and/or its affiliates.
|
2021-11-09 08:11:50 +01:00
|
|
|
Copyright (c) 2013, 2021, MariaDB Corporation.
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
#ifndef SQL_ALTER_TABLE_H
|
|
|
|
#define SQL_ALTER_TABLE_H
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
class Alter_drop;
|
|
|
|
class Alter_column;
|
2020-03-03 11:50:33 +01:00
|
|
|
class Alter_rename_key;
|
2021-02-25 15:29:51 +01:00
|
|
|
class Alter_index_ignorability;
|
2013-03-25 23:03:13 +01:00
|
|
|
class Key;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Data describing the table being created by CREATE TABLE or
|
|
|
|
altered by ALTER TABLE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Alter_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
|
|
|
|
|
2018-05-08 13:14:36 +02:00
|
|
|
bool vers_prohibited(THD *thd) const;
|
2017-11-24 17:15:10 +01:00
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
/**
|
|
|
|
The different values of the ALGORITHM clause.
|
|
|
|
Describes which algorithm to use when altering the table.
|
|
|
|
*/
|
|
|
|
enum enum_alter_table_algorithm
|
|
|
|
{
|
2018-05-07 11:24:58 +02:00
|
|
|
/*
|
|
|
|
Use thd->variables.alter_algorithm for alter method. If this is also
|
|
|
|
default then use the fastest possible ALTER TABLE method
|
|
|
|
(INSTANT, NOCOPY, INPLACE, COPY)
|
|
|
|
*/
|
2013-03-25 23:03:13 +01:00
|
|
|
ALTER_TABLE_ALGORITHM_DEFAULT,
|
|
|
|
|
2018-05-07 11:24:58 +02:00
|
|
|
// Copy if supported, error otherwise.
|
|
|
|
ALTER_TABLE_ALGORITHM_COPY,
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
// In-place if supported, error otherwise.
|
|
|
|
ALTER_TABLE_ALGORITHM_INPLACE,
|
|
|
|
|
2018-05-07 11:24:58 +02:00
|
|
|
// No Copy will refuse any operation which does rebuild.
|
|
|
|
ALTER_TABLE_ALGORITHM_NOCOPY,
|
|
|
|
|
|
|
|
// Instant should allow any operation that changes metadata only.
|
2020-04-25 10:57:00 +02:00
|
|
|
ALTER_TABLE_ALGORITHM_INSTANT,
|
|
|
|
|
|
|
|
// When there is no specification of algorithm during alter table.
|
|
|
|
ALTER_TABLE_ALGORITHM_NONE
|
2013-03-25 23:03:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
The different values of the LOCK clause.
|
|
|
|
Describes the level of concurrency during ALTER TABLE.
|
|
|
|
*/
|
|
|
|
enum enum_alter_table_lock
|
|
|
|
{
|
|
|
|
// Maximum supported level of concurency for the given operation.
|
|
|
|
ALTER_TABLE_LOCK_DEFAULT,
|
|
|
|
|
2018-05-07 11:24:58 +02:00
|
|
|
// Allow concurrent reads & writes. If not supported, give error.
|
2013-03-25 23:03:13 +01:00
|
|
|
ALTER_TABLE_LOCK_NONE,
|
|
|
|
|
|
|
|
// Allow concurrent reads only. If not supported, give error.
|
|
|
|
ALTER_TABLE_LOCK_SHARED,
|
|
|
|
|
|
|
|
// Block reads and writes.
|
|
|
|
ALTER_TABLE_LOCK_EXCLUSIVE
|
|
|
|
};
|
|
|
|
|
2023-06-29 16:24:50 +02:00
|
|
|
Lex_table_name db, table_name;
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
// Columns and keys to be dropped.
|
|
|
|
List<Alter_drop> drop_list;
|
2018-10-01 13:33:48 +02:00
|
|
|
// Columns for ALTER_CHANGE_COLUMN_DEFAULT.
|
2013-03-25 23:03:13 +01:00
|
|
|
List<Alter_column> alter_list;
|
|
|
|
// List of keys, used by both CREATE and ALTER TABLE.
|
|
|
|
List<Key> key_list;
|
2020-03-03 11:50:33 +01:00
|
|
|
// List of keys to be renamed.
|
|
|
|
List<Alter_rename_key> alter_rename_key_list;
|
2013-03-25 23:03:13 +01:00
|
|
|
// List of columns, used by both CREATE and ALTER TABLE.
|
|
|
|
List<Create_field> create_list;
|
2021-02-25 15:29:51 +01:00
|
|
|
// Indexes whose ignorability needs to be changed.
|
|
|
|
List<Alter_index_ignorability> alter_index_ignorability_list;
|
2016-06-29 21:27:34 +02:00
|
|
|
List<Virtual_column_info> check_constraint_list;
|
2013-03-25 23:03:13 +01:00
|
|
|
// Type of ALTER TABLE operation.
|
2018-02-16 09:56:03 +01:00
|
|
|
alter_table_operations flags;
|
2018-02-19 10:23:20 +01:00
|
|
|
ulong partition_flags;
|
2013-03-25 23:03:13 +01:00
|
|
|
// Enable or disable keys.
|
|
|
|
enum_enable_or_disable keys_onoff;
|
2023-08-18 17:35:02 +02:00
|
|
|
// Used only in add_stat_drop_index()
|
|
|
|
TABLE *original_table;
|
2013-03-25 23:03:13 +01:00
|
|
|
// List of partitions.
|
2017-04-23 18:39:57 +02:00
|
|
|
List<const char> partition_names;
|
2013-03-25 23:03:13 +01:00
|
|
|
// Number of partitions.
|
|
|
|
uint num_parts;
|
2023-08-18 17:35:02 +02:00
|
|
|
|
|
|
|
/* List of fields that we should delete statistics from */
|
|
|
|
List<Field> drop_stat_fields;
|
|
|
|
|
|
|
|
struct DROP_INDEX_STAT_PARAMS
|
|
|
|
{
|
|
|
|
KEY *key;
|
|
|
|
bool ext_prefixes_only;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RENAME_COLUMN_STAT_PARAMS
|
|
|
|
{
|
|
|
|
Field *field;
|
|
|
|
LEX_CSTRING *name;
|
|
|
|
uint duplicate_counter; // For temporary names
|
|
|
|
};
|
|
|
|
struct RENAME_INDEX_STAT_PARAMS
|
|
|
|
{
|
|
|
|
const KEY *key;
|
|
|
|
const LEX_CSTRING *name;
|
|
|
|
uint duplicate_counter; // For temporary names
|
|
|
|
uint usage_count; // How many rename entries
|
|
|
|
};
|
|
|
|
|
|
|
|
/* List of index that we should delete statistics from */
|
|
|
|
List<DROP_INDEX_STAT_PARAMS> drop_stat_indexes;
|
|
|
|
|
|
|
|
List<RENAME_COLUMN_STAT_PARAMS> rename_stat_fields;
|
|
|
|
|
|
|
|
List<RENAME_INDEX_STAT_PARAMS> rename_stat_indexes;
|
|
|
|
|
|
|
|
bool add_stat_drop_index(KEY *key, bool ext_prefixes_only,
|
|
|
|
MEM_ROOT *mem_root)
|
|
|
|
{
|
|
|
|
DROP_INDEX_STAT_PARAMS *param;
|
|
|
|
if (!(param= (DROP_INDEX_STAT_PARAMS*)
|
|
|
|
alloc_root(mem_root, sizeof(*param))))
|
|
|
|
return true;
|
|
|
|
param->key= key;
|
|
|
|
param->ext_prefixes_only= ext_prefixes_only;
|
|
|
|
return drop_stat_indexes.push_back(param, mem_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool add_stat_drop_index(THD *thd, const LEX_CSTRING *key_name);
|
|
|
|
|
|
|
|
bool add_stat_rename_index(const KEY *key, const LEX_CSTRING *name,
|
|
|
|
MEM_ROOT *mem_root)
|
|
|
|
{
|
|
|
|
RENAME_INDEX_STAT_PARAMS *param;
|
|
|
|
if (!(param= (RENAME_INDEX_STAT_PARAMS*)
|
|
|
|
alloc_root(mem_root, sizeof(*param))))
|
|
|
|
return true;
|
|
|
|
param->key= key;
|
|
|
|
param->name= name;
|
|
|
|
param->usage_count= 0;
|
|
|
|
return rename_stat_indexes.push_back(param, mem_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool add_stat_rename_field(Field *field, LEX_CSTRING *name,
|
|
|
|
MEM_ROOT *mem_root)
|
|
|
|
{
|
|
|
|
RENAME_COLUMN_STAT_PARAMS *param;
|
|
|
|
if (!(param= (RENAME_COLUMN_STAT_PARAMS*)
|
|
|
|
alloc_root(mem_root, sizeof(*param))))
|
|
|
|
return true;
|
|
|
|
param->field= field;
|
|
|
|
param->name= name;
|
|
|
|
param->duplicate_counter= 0;
|
|
|
|
return rename_stat_fields.push_back(param, mem_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool collect_renamed_fields(THD *thd);
|
|
|
|
|
|
|
|
/* Delete/update statistics in EITS tables */
|
|
|
|
void apply_statistics_deletes_renames(THD *thd, TABLE *table);
|
|
|
|
|
2020-04-25 10:57:00 +02:00
|
|
|
private:
|
2013-03-25 23:03:13 +01:00
|
|
|
// Type of ALTER TABLE algorithm.
|
|
|
|
enum_alter_table_algorithm requested_algorithm;
|
2020-04-25 10:57:00 +02:00
|
|
|
|
|
|
|
public:
|
2013-03-25 23:03:13 +01:00
|
|
|
// Type of ALTER TABLE lock.
|
|
|
|
enum_alter_table_lock requested_lock;
|
|
|
|
|
|
|
|
|
|
|
|
Alter_info() :
|
2018-02-19 10:23:20 +01:00
|
|
|
flags(0), partition_flags(0),
|
2013-03-25 23:03:13 +01:00
|
|
|
keys_onoff(LEAVE_AS_IS),
|
2023-10-14 14:46:29 +02:00
|
|
|
original_table(0),
|
2013-03-25 23:03:13 +01:00
|
|
|
num_parts(0),
|
2020-04-25 10:57:00 +02:00
|
|
|
requested_algorithm(ALTER_TABLE_ALGORITHM_NONE),
|
2013-03-25 23:03:13 +01:00
|
|
|
requested_lock(ALTER_TABLE_LOCK_DEFAULT)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
drop_list.empty();
|
|
|
|
alter_list.empty();
|
|
|
|
key_list.empty();
|
2020-03-03 11:50:33 +01:00
|
|
|
alter_rename_key_list.empty();
|
2013-03-25 23:03:13 +01:00
|
|
|
create_list.empty();
|
2021-02-25 15:29:51 +01:00
|
|
|
alter_index_ignorability_list.empty();
|
2016-06-29 21:27:34 +02:00
|
|
|
check_constraint_list.empty();
|
2023-08-18 17:35:02 +02:00
|
|
|
drop_stat_fields.empty();
|
|
|
|
drop_stat_indexes.empty();
|
|
|
|
rename_stat_fields.empty();
|
|
|
|
rename_stat_indexes.empty();
|
2013-03-25 23:03:13 +01:00
|
|
|
flags= 0;
|
2018-02-19 10:23:20 +01:00
|
|
|
partition_flags= 0;
|
2013-03-25 23:03:13 +01:00
|
|
|
keys_onoff= LEAVE_AS_IS;
|
|
|
|
num_parts= 0;
|
|
|
|
partition_names.empty();
|
2020-04-25 10:57:00 +02:00
|
|
|
requested_algorithm= ALTER_TABLE_ALGORITHM_NONE;
|
2013-03-25 23:03:13 +01:00
|
|
|
requested_lock= ALTER_TABLE_LOCK_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Construct a copy of this object to be used for mysql_alter_table
|
|
|
|
and mysql_create_table.
|
|
|
|
|
|
|
|
Historically, these two functions modify their Alter_info
|
|
|
|
arguments. This behaviour breaks re-execution of prepared
|
|
|
|
statements and stored procedures and is compensated by always
|
|
|
|
supplying a copy of Alter_info to these functions.
|
|
|
|
|
|
|
|
@param rhs Alter_info to make copy of
|
|
|
|
@param mem_root Mem_root for new Alter_info
|
|
|
|
|
|
|
|
@note You need to use check the error in THD for out
|
|
|
|
of memory condition after calling this function.
|
|
|
|
*/
|
|
|
|
Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Parses the given string and sets requested_algorithm
|
|
|
|
if the string value matches a supported value.
|
|
|
|
Supported values: INPLACE, COPY, DEFAULT
|
|
|
|
|
|
|
|
@param str String containing the supplied value
|
|
|
|
@retval false Supported value found, state updated
|
|
|
|
@retval true Not supported value, no changes made
|
|
|
|
*/
|
2017-04-23 18:39:57 +02:00
|
|
|
bool set_requested_algorithm(const LEX_CSTRING *str);
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Parses the given string and sets requested_lock
|
|
|
|
if the string value matches a supported value.
|
|
|
|
Supported values: NONE, SHARED, EXCLUSIVE, DEFAULT
|
|
|
|
|
|
|
|
@param str String containing the supplied value
|
|
|
|
@retval false Supported value found, state updated
|
|
|
|
@retval true Not supported value, no changes made
|
|
|
|
*/
|
|
|
|
|
2017-04-23 18:39:57 +02:00
|
|
|
bool set_requested_lock(const LEX_CSTRING *str);
|
2013-03-25 23:03:13 +01:00
|
|
|
|
2020-04-25 10:57:00 +02:00
|
|
|
/**
|
|
|
|
Set the requested algorithm to the given algorithm value
|
|
|
|
@param algo_value algorithm to be set
|
|
|
|
*/
|
|
|
|
void set_requested_algorithm(enum_alter_table_algorithm algo_value);
|
|
|
|
|
2018-05-07 11:24:58 +02:00
|
|
|
/**
|
|
|
|
Returns the algorithm value in the format "algorithm=value"
|
|
|
|
*/
|
2020-04-25 10:57:00 +02:00
|
|
|
const char* algorithm_clause(THD *thd) const;
|
2018-05-07 11:24:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the lock value in the format "lock=value"
|
|
|
|
*/
|
|
|
|
const char* lock() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check whether the given result can be supported
|
|
|
|
with the specified user alter algorithm.
|
|
|
|
|
|
|
|
@param thd Thread handle
|
|
|
|
@param ha_alter_info Structure describing changes to be done
|
|
|
|
by ALTER TABLE and holding data during
|
|
|
|
in-place alter
|
|
|
|
@retval false Supported operation
|
|
|
|
@retval true Not supported value
|
|
|
|
*/
|
2020-07-27 14:04:04 +02:00
|
|
|
bool supports_algorithm(THD *thd,
|
2018-05-07 11:24:58 +02:00
|
|
|
const Alter_inplace_info *ha_alter_info);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check whether the given result can be supported
|
|
|
|
with the specified user lock type.
|
|
|
|
|
|
|
|
@param ha_alter_info Structure describing changes to be done
|
|
|
|
by ALTER TABLE and holding data during
|
|
|
|
in-place alter
|
|
|
|
@retval false Supported lock type
|
|
|
|
@retval true Not supported value
|
|
|
|
*/
|
2020-07-27 14:04:04 +02:00
|
|
|
bool supports_lock(THD *thd, const Alter_inplace_info *ha_alter_info);
|
2018-05-07 11:24:58 +02:00
|
|
|
|
2020-04-25 10:57:00 +02:00
|
|
|
/**
|
|
|
|
Return user requested algorithm. If user does not specify
|
|
|
|
algorithm then return alter_algorithm variable value.
|
|
|
|
*/
|
|
|
|
enum_alter_table_algorithm algorithm(const THD *thd) const;
|
|
|
|
|
2023-06-29 18:03:54 +02:00
|
|
|
uint check_vcol_field(Item_field *f) const;
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
private:
|
|
|
|
Alter_info &operator=(const Alter_info &rhs); // not implemented
|
|
|
|
Alter_info(const Alter_info &rhs); // not implemented
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Runtime context for ALTER TABLE. */
|
|
|
|
class Alter_table_ctx
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Alter_table_ctx();
|
|
|
|
|
|
|
|
Alter_table_ctx(THD *thd, TABLE_LIST *table_list, uint tables_opened_arg,
|
2018-01-07 17:03:44 +01:00
|
|
|
const LEX_CSTRING *new_db_arg, const LEX_CSTRING *new_name_arg);
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@return true if the table is moved to another database, false otherwise.
|
|
|
|
*/
|
|
|
|
bool is_database_changed() const
|
2018-01-07 17:03:44 +01:00
|
|
|
{ return (new_db.str != db.str); };
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@return true if the table is renamed, false otherwise.
|
|
|
|
*/
|
|
|
|
bool is_table_renamed() const
|
2018-01-07 17:03:44 +01:00
|
|
|
{ return (is_database_changed() || new_name.str != table_name.str); };
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@return filename (including .frm) for the new table.
|
|
|
|
*/
|
|
|
|
const char *get_new_filename() const
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(!tmp_table);
|
|
|
|
return new_filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return path to the original table.
|
|
|
|
*/
|
|
|
|
const char *get_path() const
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(!tmp_table);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return path to the new table.
|
|
|
|
*/
|
|
|
|
const char *get_new_path() const
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(!tmp_table);
|
|
|
|
return new_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return path to the temporary table created during ALTER TABLE.
|
|
|
|
*/
|
|
|
|
const char *get_tmp_path() const
|
|
|
|
{ return tmp_path; }
|
|
|
|
|
2021-01-17 15:06:43 +01:00
|
|
|
const LEX_CSTRING get_tmp_cstring_path() const
|
|
|
|
{
|
|
|
|
LEX_CSTRING tmp= { tmp_path, strlen(tmp_path) };
|
|
|
|
return tmp;
|
|
|
|
};
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
/**
|
|
|
|
Mark ALTER TABLE as needing to produce foreign key error if
|
|
|
|
it deletes a row from the table being changed.
|
|
|
|
*/
|
|
|
|
void set_fk_error_if_delete_row(FOREIGN_KEY_INFO *fk)
|
|
|
|
{
|
|
|
|
fk_error_if_delete_row= true;
|
|
|
|
fk_error_id= fk->foreign_id->str;
|
|
|
|
fk_error_table= fk->foreign_table->str;
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:50:11 +02:00
|
|
|
void report_implicit_default_value_error(THD *thd, const TABLE_SHARE *) const;
|
2013-03-25 23:03:13 +01:00
|
|
|
public:
|
2021-11-09 08:11:50 +01:00
|
|
|
Create_field *implicit_default_value_error_field= nullptr;
|
|
|
|
bool error_if_not_empty= false;
|
|
|
|
uint tables_opened= 0;
|
2018-01-07 17:03:44 +01:00
|
|
|
LEX_CSTRING db;
|
|
|
|
LEX_CSTRING table_name;
|
2021-03-30 16:06:55 +02:00
|
|
|
LEX_CSTRING storage_engine_name;
|
2018-01-07 17:03:44 +01:00
|
|
|
LEX_CSTRING alias;
|
|
|
|
LEX_CSTRING new_db;
|
|
|
|
LEX_CSTRING new_name;
|
|
|
|
LEX_CSTRING new_alias;
|
|
|
|
LEX_CSTRING tmp_name;
|
2021-03-30 16:06:55 +02:00
|
|
|
LEX_CSTRING tmp_storage_engine_name;
|
|
|
|
LEX_CUSTRING tmp_id, id;
|
2018-01-07 17:03:44 +01:00
|
|
|
char tmp_buff[80];
|
2021-03-30 16:06:55 +02:00
|
|
|
uchar id_buff[MY_UUID_SIZE];
|
|
|
|
char storage_engine_buff[NAME_LEN], tmp_storage_engine_buff[NAME_LEN];
|
|
|
|
bool storage_engine_partitioned;
|
|
|
|
bool tmp_storage_engine_name_partitioned;
|
MDEV-25180 Atomic ALTER TABLE
MDEV-25604 Atomic DDL: Binlog event written upon recovery does not
have default database
The purpose of this task is to ensure that ALTER TABLE is atomic even if
the MariaDB server would be killed at any point of the alter table.
This means that either the ALTER TABLE succeeds (including that triggers,
the status tables and the binary log are updated) or things should be
reverted to their original state.
If the server crashes before the new version is fully up to date and
commited, it will revert to the original table and remove all
temporary files and tables.
If the new version is commited, crash recovery will use the new version,
and update triggers, the status tables and the binary log.
The one execption is ALTER TABLE .. RENAME .. where no changes are done
to table definition. This one will work as RENAME and roll back unless
the whole statement completed, including updating the binary log (if
enabled).
Other changes:
- Added handlerton->check_version() function to allow the ddl recovery
code to check, in case of inplace alter table, if the table in the
storage engine is of the new or old version.
- Added handler->table_version() so that an engine can report the current
version of the table. This should be changed each time the table
definition changes.
- Added ha_signal_ddl_recovery_done() and
handlerton::signal_ddl_recovery_done() to inform all handlers when
ddl recovery has been done. (Needed by InnoDB).
- Added handlerton call inplace_alter_table_committed, to signal engine
that ddl_log has been closed for the alter table query.
- Added new handerton flag
HTON_REQUIRES_NOTIFY_TABLEDEF_CHANGED_AFTER_COMMIT to signal when we
should call hton->notify_tabledef_changed() during
mysql_inplace_alter_table. This was required as MyRocks and InnoDB
needed the call at different times.
- Added function server_uuid_value() to be able to generate a temporary
xid when ddl recovery writes the query to the binary log. This is
needed to be able to handle crashes during ddl log recovery.
- Moved freeing of the frm definition to end of mysql_alter_table() to
remove duplicate code and have a common exit strategy.
-------
InnoDB part of atomic ALTER TABLE
(Implemented by Marko Mäkelä)
innodb_check_version(): Compare the saved dict_table_t::def_trx_id
to determine whether an ALTER TABLE operation was committed.
We must correctly recover dict_table_t::def_trx_id for this to work.
Before purge removes any trace of DB_TRX_ID from system tables, it
will make an effort to load the user table into the cache, so that
the dict_table_t::def_trx_id can be recovered.
ha_innobase::table_version(): return garbage, or the trx_id that would
be used for committing an ALTER TABLE operation.
In InnoDB, table names starting with #sql-ib will remain special:
they will be dropped on startup. This may be revisited later in
MDEV-18518 when we implement proper undo logging and rollback
for creating or dropping multiple tables in a transaction.
Table names starting with #sql will retain some special meaning:
dict_table_t::parse_name() will not consider such names for
MDL acquisition, and dict_table_rename_in_cache() will treat such
names specially when handling FOREIGN KEY constraints.
Simplify InnoDB DROP INDEX.
Prevent purge wakeup
To ensure that dict_table_t::def_trx_id will be recovered correctly
in case the server is killed before ddl_log_complete(), we will block
the purge of any history in SYS_TABLES, SYS_INDEXES, SYS_COLUMNS
between ha_innobase::commit_inplace_alter_table(commit=true)
(purge_sys.stop_SYS()) and purge_sys.resume_SYS().
The completion callback purge_sys.resume_SYS() must be between
ddl_log_complete() and MDL release.
--------
MyRocks support for atomic ALTER TABLE
(Implemented by Sergui Petrunia)
Implement these SE API functions:
- ha_rocksdb::table_version()
- hton->check_version = rocksdb_check_versionMyRocks data dictionary
now stores table version for each table.
(Absence of table version record is interpreted as table_version=0,
that is, which means no upgrade changes are needed)
- For inplace alter table of a partitioned table, call the underlying
handlerton when checking if the table is ok. This assumes that the
partition engine commits all changes at once.
2021-03-18 11:41:08 +01:00
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
/**
|
|
|
|
Indicates that if a row is deleted during copying of data from old version
|
|
|
|
of table to the new version ER_FK_CANNOT_DELETE_PARENT error should be
|
|
|
|
emitted.
|
|
|
|
*/
|
2021-11-09 08:11:50 +01:00
|
|
|
bool fk_error_if_delete_row= false;
|
2013-03-25 23:03:13 +01:00
|
|
|
/** Name of foreign key for the above error. */
|
2021-11-09 08:11:50 +01:00
|
|
|
const char *fk_error_id= nullptr;
|
2013-03-25 23:03:13 +01:00
|
|
|
/** Name of table for the above error. */
|
2021-11-09 08:11:50 +01:00
|
|
|
const char *fk_error_table= nullptr;
|
|
|
|
bool modified_primary_key= false;
|
2021-03-30 16:06:55 +02:00
|
|
|
/** Indicates that we are altering temporary table */
|
2021-11-09 08:11:50 +01:00
|
|
|
bool tmp_table= false;
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
char new_filename[FN_REFLEN + 1];
|
2018-01-07 17:03:44 +01:00
|
|
|
char new_alias_buff[NAME_LEN + 1];
|
|
|
|
char tmp_name_buff[NAME_LEN + 1];
|
2013-03-25 23:03:13 +01:00
|
|
|
char path[FN_REFLEN + 1];
|
|
|
|
char new_path[FN_REFLEN + 1];
|
|
|
|
char tmp_path[FN_REFLEN + 1];
|
|
|
|
|
|
|
|
Alter_table_ctx &operator=(const Alter_table_ctx &rhs); // not implemented
|
|
|
|
Alter_table_ctx(const Alter_table_ctx &rhs); // not implemented
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-16 14:53:30 +02:00
|
|
|
/**
|
2013-03-25 23:03:13 +01:00
|
|
|
Sql_cmd_common_alter_table represents the common properties of the ALTER TABLE
|
2010-08-16 14:53:30 +02:00
|
|
|
statements.
|
|
|
|
@todo move Alter_info and other ALTER generic structures from Lex here.
|
|
|
|
*/
|
2019-03-11 16:45:38 +01:00
|
|
|
class Sql_cmd_common_alter_table : public Sql_cmd
|
2010-08-16 14:53:30 +02:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
2023-02-07 12:57:20 +01:00
|
|
|
Sql_cmd_common_alter_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
virtual ~Sql_cmd_common_alter_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2024-06-12 15:46:26 +02:00
|
|
|
enum_sql_command sql_command_code() const override
|
2013-03-25 23:03:13 +01:00
|
|
|
{
|
|
|
|
return SQLCOM_ALTER_TABLE;
|
|
|
|
}
|
2010-08-16 14:53:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-03-25 23:03:13 +01:00
|
|
|
Sql_cmd_alter_table represents the generic ALTER TABLE statement.
|
2010-08-16 14:53:30 +02:00
|
|
|
@todo move Alter_info and other ALTER specific structures from Lex here.
|
|
|
|
*/
|
2019-05-31 13:24:40 +02:00
|
|
|
class Sql_cmd_alter_table : public Sql_cmd_common_alter_table,
|
|
|
|
public Storage_engine_name
|
2010-08-16 14:53:30 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, used to represent a ALTER TABLE statement.
|
|
|
|
*/
|
2023-02-07 12:57:20 +01:00
|
|
|
Sql_cmd_alter_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
~Sql_cmd_alter_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2024-06-12 15:46:26 +02:00
|
|
|
Storage_engine_name *option_storage_engine_name() override { return this; }
|
2019-05-31 13:24:40 +02:00
|
|
|
|
2024-06-12 15:46:26 +02:00
|
|
|
bool execute(THD *thd) override;
|
2010-08-16 14:53:30 +02:00
|
|
|
};
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
|
2017-05-08 01:44:55 +02:00
|
|
|
/**
|
|
|
|
Sql_cmd_alter_sequence represents the ALTER SEQUENCE statement.
|
|
|
|
*/
|
2017-11-15 16:18:28 +01:00
|
|
|
class Sql_cmd_alter_sequence : public Sql_cmd,
|
|
|
|
public DDL_options
|
2017-05-08 01:44:55 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, used to represent a ALTER TABLE statement.
|
|
|
|
*/
|
2017-11-15 16:18:28 +01:00
|
|
|
Sql_cmd_alter_sequence(const DDL_options &options)
|
|
|
|
:DDL_options(options)
|
2017-05-08 01:44:55 +02:00
|
|
|
{}
|
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
~Sql_cmd_alter_sequence() = default;
|
2017-05-08 01:44:55 +02:00
|
|
|
|
2024-06-12 15:46:26 +02:00
|
|
|
enum_sql_command sql_command_code() const override
|
2017-05-08 01:44:55 +02:00
|
|
|
{
|
|
|
|
return SQLCOM_ALTER_SEQUENCE;
|
|
|
|
}
|
2024-06-12 15:46:26 +02:00
|
|
|
bool execute(THD *thd) override;
|
2017-05-08 01:44:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
/**
|
|
|
|
Sql_cmd_alter_table_tablespace represents ALTER TABLE
|
|
|
|
IMPORT/DISCARD TABLESPACE statements.
|
|
|
|
*/
|
|
|
|
class Sql_cmd_discard_import_tablespace : public Sql_cmd_common_alter_table
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum enum_tablespace_op_type
|
|
|
|
{
|
|
|
|
DISCARD_TABLESPACE, IMPORT_TABLESPACE
|
|
|
|
};
|
|
|
|
|
|
|
|
Sql_cmd_discard_import_tablespace(enum_tablespace_op_type tablespace_op_arg)
|
|
|
|
: m_tablespace_op(tablespace_op_arg)
|
|
|
|
{}
|
|
|
|
|
2024-06-12 15:46:26 +02:00
|
|
|
bool execute(THD *thd) override;
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const enum_tablespace_op_type m_tablespace_op;
|
|
|
|
};
|
|
|
|
|
2010-08-16 14:53:30 +02:00
|
|
|
#endif
|