summaryrefslogtreecommitdiff
path: root/sql/sql_alter.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_alter.h')
-rw-r--r--sql/sql_alter.h244
1 files changed, 124 insertions, 120 deletions
diff --git a/sql/sql_alter.h b/sql/sql_alter.h
index c6558c3bc8c..d9749592a4f 100644
--- a/sql/sql_alter.h
+++ b/sql/sql_alter.h
@@ -1,5 +1,5 @@
/* Copyright (c) 2010, 2014, Oracle and/or its affiliates.
- Copyright (c) 2013, 2014, Monty Program Ab.
+ Copyright (c) 2013, 2020, MariaDB Corporation.
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
@@ -29,118 +29,38 @@ class Key;
class Alter_info
{
public:
- /*
- These flags are set by the parser and describes the type of
- operation(s) specified by the ALTER TABLE statement.
-
- They do *not* describe the type operation(s) to be executed
- by the storage engine. For example, we don't yet know the
- type of index to be added/dropped.
- */
-
- // Set for ADD [COLUMN]
- static const uint ALTER_ADD_COLUMN = 1L << 0;
-
- // Set for DROP [COLUMN]
- static const uint ALTER_DROP_COLUMN = 1L << 1;
-
- // Set for CHANGE [COLUMN] | MODIFY [CHANGE]
- // Set by mysql_recreate_table()
- static const uint ALTER_CHANGE_COLUMN = 1L << 2;
-
- // Set for ADD INDEX | ADD KEY | ADD PRIMARY KEY | ADD UNIQUE KEY |
- // ADD UNIQUE INDEX | ALTER ADD [COLUMN]
- static const uint ALTER_ADD_INDEX = 1L << 3;
-
- // Set for DROP PRIMARY KEY | DROP FOREIGN KEY | DROP KEY | DROP INDEX
- static const uint ALTER_DROP_INDEX = 1L << 4;
-
- // Set for RENAME [TO]
- static const uint ALTER_RENAME = 1L << 5;
-
- // Set for ORDER BY
- static const uint ALTER_ORDER = 1L << 6;
-
- // Set for table_options
- static const uint ALTER_OPTIONS = 1L << 7;
-
- // Set for ALTER [COLUMN] ... SET DEFAULT ... | DROP DEFAULT
- static const uint ALTER_CHANGE_COLUMN_DEFAULT = 1L << 8;
-
- // Set for DISABLE KEYS | ENABLE KEYS
- static const uint ALTER_KEYS_ONOFF = 1L << 9;
-
- // Set for FORCE
- // Set for ENGINE(same engine)
- // Set by mysql_recreate_table()
- static const uint ALTER_RECREATE = 1L << 10;
-
- // Set for ADD PARTITION
- static const uint ALTER_ADD_PARTITION = 1L << 11;
-
- // Set for DROP PARTITION
- static const uint ALTER_DROP_PARTITION = 1L << 12;
-
- // Set for COALESCE PARTITION
- static const uint ALTER_COALESCE_PARTITION = 1L << 13;
-
- // Set for REORGANIZE PARTITION ... INTO
- static const uint ALTER_REORGANIZE_PARTITION = 1L << 14;
-
- // Set for partition_options
- static const uint ALTER_PARTITION = 1L << 15;
-
- // Set for LOAD INDEX INTO CACHE ... PARTITION
- // Set for CACHE INDEX ... PARTITION
- static const uint ALTER_ADMIN_PARTITION = 1L << 16;
-
- // Set for REORGANIZE PARTITION
- static const uint ALTER_TABLE_REORG = 1L << 17;
-
- // Set for REBUILD PARTITION
- static const uint ALTER_REBUILD_PARTITION = 1L << 18;
-
- // Set for partitioning operations specifying ALL keyword
- static const uint ALTER_ALL_PARTITION = 1L << 19;
-
- // Set for REMOVE PARTITIONING
- static const uint ALTER_REMOVE_PARTITIONING = 1L << 20;
-
- // Set for ADD FOREIGN KEY
- static const uint ADD_FOREIGN_KEY = 1L << 21;
-
- // Set for DROP FOREIGN KEY
- static const uint DROP_FOREIGN_KEY = 1L << 22;
-
- // Set for EXCHANGE PARITION
- static const uint ALTER_EXCHANGE_PARTITION = 1L << 23;
-
- // Set by Sql_cmd_alter_table_truncate_partition::execute()
- static const uint ALTER_TRUNCATE_PARTITION = 1L << 24;
-
- // Set for ADD [COLUMN] FIRST | AFTER
- static const uint ALTER_COLUMN_ORDER = 1L << 25;
-
- static const uint ALTER_ADD_CHECK_CONSTRAINT = 1L << 27;
- static const uint ALTER_DROP_CHECK_CONSTRAINT = 1L << 28;
- static const uint ALTER_RENAME_COLUMN = 1L << 29;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
+ bool vers_prohibited(THD *thd) const;
+
/**
The different values of the ALGORITHM clause.
Describes which algorithm to use when altering the table.
*/
enum enum_alter_table_algorithm
{
- // In-place if supported, copy otherwise.
+/*
+ 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)
+*/
ALTER_TABLE_ALGORITHM_DEFAULT,
+ // Copy if supported, error otherwise.
+ ALTER_TABLE_ALGORITHM_COPY,
+
// In-place if supported, error otherwise.
ALTER_TABLE_ALGORITHM_INPLACE,
- // Copy if supported, error otherwise.
- ALTER_TABLE_ALGORITHM_COPY
+ // No Copy will refuse any operation which does rebuild.
+ ALTER_TABLE_ALGORITHM_NOCOPY,
+
+ // Instant should allow any operation that changes metadata only.
+ ALTER_TABLE_ALGORITHM_INSTANT,
+
+ // When there is no specification of algorithm during alter table.
+ ALTER_TABLE_ALGORITHM_NONE
};
@@ -153,7 +73,7 @@ public:
// Maximum supported level of concurency for the given operation.
ALTER_TABLE_LOCK_DEFAULT,
- // Allow concurrent reads & writes. If not supported, give erorr.
+ // Allow concurrent reads & writes. If not supported, give error.
ALTER_TABLE_LOCK_NONE,
// Allow concurrent reads only. If not supported, give error.
@@ -173,27 +93,34 @@ public:
// List of columns, used by both CREATE and ALTER TABLE.
List<Create_field> create_list;
- static const uint CHECK_CONSTRAINT_IF_NOT_EXISTS= 1;
+ enum flags_bits
+ {
+ CHECK_CONSTRAINT_IF_NOT_EXISTS= 1
+ };
List<Virtual_column_info> check_constraint_list;
// Type of ALTER TABLE operation.
- uint flags;
+ alter_table_operations flags;
+ ulong partition_flags;
// Enable or disable keys.
enum_enable_or_disable keys_onoff;
// List of partitions.
- List<char> partition_names;
+ List<const char> partition_names;
// Number of partitions.
uint num_parts;
+private:
// Type of ALTER TABLE algorithm.
enum_alter_table_algorithm requested_algorithm;
+
+public:
// Type of ALTER TABLE lock.
enum_alter_table_lock requested_lock;
Alter_info() :
- flags(0),
+ flags(0), partition_flags(0),
keys_onoff(LEAVE_AS_IS),
num_parts(0),
- requested_algorithm(ALTER_TABLE_ALGORITHM_DEFAULT),
+ requested_algorithm(ALTER_TABLE_ALGORITHM_NONE),
requested_lock(ALTER_TABLE_LOCK_DEFAULT)
{}
@@ -205,10 +132,11 @@ public:
create_list.empty();
check_constraint_list.empty();
flags= 0;
+ partition_flags= 0;
keys_onoff= LEAVE_AS_IS;
num_parts= 0;
partition_names.empty();
- requested_algorithm= ALTER_TABLE_ALGORITHM_DEFAULT;
+ requested_algorithm= ALTER_TABLE_ALGORITHM_NONE;
requested_lock= ALTER_TABLE_LOCK_DEFAULT;
}
@@ -240,7 +168,7 @@ public:
@retval false Supported value found, state updated
@retval true Not supported value, no changes made
*/
- bool set_requested_algorithm(const LEX_STRING *str);
+ bool set_requested_algorithm(const LEX_CSTRING *str);
/**
@@ -253,7 +181,55 @@ public:
@retval true Not supported value, no changes made
*/
- bool set_requested_lock(const LEX_STRING *str);
+ bool set_requested_lock(const LEX_CSTRING *str);
+
+ /**
+ 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);
+
+ /**
+ Returns the algorithm value in the format "algorithm=value"
+ */
+ const char* algorithm_clause(THD *thd) const;
+
+ /**
+ 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
+ */
+ bool supports_algorithm(THD *thd,
+ 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
+ */
+ bool supports_lock(THD *thd, const Alter_inplace_info *ha_alter_info);
+
+ /**
+ 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;
private:
Alter_info &operator=(const Alter_info &rhs); // not implemented
@@ -268,19 +244,19 @@ public:
Alter_table_ctx();
Alter_table_ctx(THD *thd, TABLE_LIST *table_list, uint tables_opened_arg,
- char *new_db_arg, char *new_name_arg);
+ const LEX_CSTRING *new_db_arg, const LEX_CSTRING *new_name_arg);
/**
@return true if the table is moved to another database, false otherwise.
*/
bool is_database_changed() const
- { return (new_db != db); };
+ { return (new_db.str != db.str); };
/**
@return true if the table is renamed, false otherwise.
*/
bool is_table_renamed() const
- { return (is_database_changed() || new_name != table_name); };
+ { return (is_database_changed() || new_name.str != table_name.str); };
/**
@return filename (including .frm) for the new table.
@@ -330,13 +306,14 @@ public:
Create_field *datetime_field;
bool error_if_not_empty;
uint tables_opened;
- char *db;
- char *table_name;
- char *alias;
- char *new_db;
- char *new_name;
- char *new_alias;
- char tmp_name[80];
+ LEX_CSTRING db;
+ LEX_CSTRING table_name;
+ LEX_CSTRING alias;
+ LEX_CSTRING new_db;
+ LEX_CSTRING new_name;
+ LEX_CSTRING new_alias;
+ LEX_CSTRING tmp_name;
+ char tmp_buff[80];
/**
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
@@ -347,15 +324,17 @@ public:
const char *fk_error_id;
/** Name of table for the above error. */
const char *fk_error_table;
+ bool modified_primary_key;
private:
char new_filename[FN_REFLEN + 1];
- char new_alias_buff[FN_REFLEN + 1];
+ char new_alias_buff[NAME_LEN + 1];
+ char tmp_name_buff[NAME_LEN + 1];
char path[FN_REFLEN + 1];
char new_path[FN_REFLEN + 1];
char tmp_path[FN_REFLEN + 1];
-#ifndef DBUG_OFF
+#ifdef DBUG_ASSERT_EXISTS
/** Indicates that we are altering temporary table. Used only in asserts. */
bool tmp_table;
#endif
@@ -412,6 +391,31 @@ public:
/**
+ Sql_cmd_alter_sequence represents the ALTER SEQUENCE statement.
+*/
+class Sql_cmd_alter_sequence : public Sql_cmd,
+ public DDL_options
+{
+public:
+ /**
+ Constructor, used to represent a ALTER TABLE statement.
+ */
+ Sql_cmd_alter_sequence(const DDL_options &options)
+ :DDL_options(options)
+ {}
+
+ ~Sql_cmd_alter_sequence()
+ {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return SQLCOM_ALTER_SEQUENCE;
+ }
+ bool execute(THD *thd);
+};
+
+
+/**
Sql_cmd_alter_table_tablespace represents ALTER TABLE
IMPORT/DISCARD TABLESPACE statements.
*/