summaryrefslogtreecommitdiff
path: root/sql/sql_alter.cc
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2020-04-25 14:27:00 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2020-05-04 09:35:38 +0530
commitec9908b2577758ffb3cb0d1b06400f12ff47b81c (patch)
treea18426dce230626e84f752cf5d966d8e205f530b /sql/sql_alter.cc
parentf98017bb6df0110aa0a359ab4378cc97f6a95473 (diff)
downloadmariadb-git-ec9908b2577758ffb3cb0d1b06400f12ff47b81c.tar.gz
MDEV-16288 ALTER TABLE…ALGORITHM=DEFAULT does not override alter_algorithm
- ALTER_ALGORITHM should be substituted when there is no mention of algorithm in alter statement. - Introduced algorithm(thd) in Alter_info. It returns the user requested algorithm. If user doesn't specify algorithm explicitly then it returns alter_algorithm variable. - changed algorithm() to get_algorithm(thd) to return algorithm name for displaying the error. - set_requested_algorithm(algo_value) to avoid direct assignment on requested_algorithm variable. - Avoid direct access of requested_algorithm to encapsulate requested_algorithm variable
Diffstat (limited to 'sql/sql_alter.cc')
-rw-r--r--sql/sql_alter.cc34
1 files changed, 23 insertions, 11 deletions
diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc
index b3a036eda9e..a68dcb31a4c 100644
--- a/sql/sql_alter.cc
+++ b/sql/sql_alter.cc
@@ -69,6 +69,10 @@ bool Alter_info::set_requested_algorithm(const LEX_CSTRING *str)
return false;
}
+void Alter_info::set_requested_algorithm(enum_alter_table_algorithm algo_val)
+{
+ requested_algorithm= algo_val;
+}
bool Alter_info::set_requested_lock(const LEX_CSTRING *str)
{
@@ -86,13 +90,16 @@ bool Alter_info::set_requested_lock(const LEX_CSTRING *str)
return false;
}
-const char* Alter_info::algorithm() const
+const char* Alter_info::algorithm_clause(THD *thd) const
{
- switch (requested_algorithm) {
+ switch (algorithm(thd)) {
case ALTER_TABLE_ALGORITHM_INPLACE:
return "ALGORITHM=INPLACE";
case ALTER_TABLE_ALGORITHM_COPY:
return "ALGORITHM=COPY";
+ case ALTER_TABLE_ALGORITHM_NONE:
+ DBUG_ASSERT(0);
+ /* Fall through */
case ALTER_TABLE_ALGORITHM_DEFAULT:
return "ALGORITHM=DEFAULT";
case ALTER_TABLE_ALGORITHM_NOCOPY:
@@ -123,9 +130,6 @@ const char* Alter_info::lock() const
bool Alter_info::supports_algorithm(THD *thd, enum_alter_inplace_result result,
const Alter_inplace_info *ha_alter_info)
{
- if (requested_algorithm == Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT)
- requested_algorithm = (Alter_info::enum_alter_table_algorithm) thd->variables.alter_algorithm;
-
switch (result) {
case HA_ALTER_INPLACE_EXCLUSIVE_LOCK:
case HA_ALTER_INPLACE_SHARED_LOCK:
@@ -134,16 +138,16 @@ bool Alter_info::supports_algorithm(THD *thd, enum_alter_inplace_result result,
return false;
case HA_ALTER_INPLACE_COPY_NO_LOCK:
case HA_ALTER_INPLACE_COPY_LOCK:
- if (requested_algorithm >= Alter_info::ALTER_TABLE_ALGORITHM_NOCOPY)
+ if (algorithm(thd) >= Alter_info::ALTER_TABLE_ALGORITHM_NOCOPY)
{
- ha_alter_info->report_unsupported_error(algorithm(),
+ ha_alter_info->report_unsupported_error(algorithm_clause(thd),
"ALGORITHM=INPLACE");
return true;
}
return false;
case HA_ALTER_INPLACE_NOCOPY_NO_LOCK:
case HA_ALTER_INPLACE_NOCOPY_LOCK:
- if (requested_algorithm == Alter_info::ALTER_TABLE_ALGORITHM_INSTANT)
+ if (algorithm(thd) == Alter_info::ALTER_TABLE_ALGORITHM_INSTANT)
{
ha_alter_info->report_unsupported_error("ALGORITHM=INSTANT",
"ALGORITHM=NOCOPY");
@@ -151,9 +155,9 @@ bool Alter_info::supports_algorithm(THD *thd, enum_alter_inplace_result result,
}
return false;
case HA_ALTER_INPLACE_NOT_SUPPORTED:
- if (requested_algorithm >= Alter_info::ALTER_TABLE_ALGORITHM_INPLACE)
+ if (algorithm(thd) >= Alter_info::ALTER_TABLE_ALGORITHM_INPLACE)
{
- ha_alter_info->report_unsupported_error(algorithm(),
+ ha_alter_info->report_unsupported_error(algorithm_clause(thd),
"ALGORITHM=COPY");
return true;
}
@@ -174,7 +178,7 @@ bool Alter_info::supports_lock(THD *thd, enum_alter_inplace_result result,
case HA_ALTER_INPLACE_EXCLUSIVE_LOCK:
// If SHARED lock and no particular algorithm was requested, use COPY.
if (requested_lock == Alter_info::ALTER_TABLE_LOCK_SHARED &&
- requested_algorithm == Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT &&
+ algorithm(thd) == Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT &&
thd->variables.alter_algorithm ==
Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT)
return false;
@@ -237,6 +241,14 @@ bool Alter_info::vers_prohibited(THD *thd) const
return false;
}
+Alter_info::enum_alter_table_algorithm
+Alter_info::algorithm(const THD *thd) const
+{
+ if (requested_algorithm == ALTER_TABLE_ALGORITHM_NONE)
+ return (Alter_info::enum_alter_table_algorithm) thd->variables.alter_algorithm;
+ return requested_algorithm;
+}
+
Alter_table_ctx::Alter_table_ctx()
: datetime_field(NULL), error_if_not_empty(false),