From f9d875d212a299c0b0694ff1650e26b505ac7c12 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Mon, 27 Nov 2017 19:48:36 +0300 Subject: [PATCH] SQL: disable engine change [fixes #358] --- mysql-test/suite/versioning/r/alter.result | 2 ++ mysql-test/suite/versioning/t/alter.test | 2 ++ sql/share/errmsg-utf8.txt | 3 +++ sql/sql_table.cc | 13 +++++++++++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 0a3fb3d43e1..f45c479a70b 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -22,6 +22,8 @@ t CREATE TABLE `t` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING alter table t add column y int; ERROR HY000: Not allowed for versioned `test.t`. Change `versioning_alter_history` to proceed with ALTER. +alter table t engine innodb; +ERROR HY000: Not allowed for versioned `test.t`. Change to/from native versioning engine is prohibited. alter table t drop system versioning; show create table t; Table Create Table diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index e75974f8324..47169574ed7 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -12,6 +12,8 @@ show create table t; --error ER_VERS_ALTER_NOT_ALLOWED alter table t add column y int; +--error ER_VERS_ALTER_ENGINE_PROHIBITED +alter table t engine innodb; alter table t drop system versioning; show create table t; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index fb30fe89c95..83c71234bd6 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7848,6 +7848,9 @@ WARN_VERS_PART_NON_HISTORICAL ER_VERS_ALTER_NOT_ALLOWED eng "Not allowed for versioned `%s.%s`. Change `versioning_alter_history` to proceed with ALTER." +ER_VERS_ALTER_ENGINE_PROHIBITED + eng "Not allowed for versioned `%s.%s`. Change to/from native versioning engine is prohibited." + ER_VERS_RANGE_PROHIBITED eng "SYSTEM_TIME range selector is prohibited" diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b04c9acbc38..7c65e515e3d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -8842,11 +8842,21 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, bool error= open_tables(thd, &table_list, &tables_opened, 0, &alter_prelocking_strategy); thd->open_options&= ~HA_OPEN_FOR_ALTER; - bool versioned= table_list->table && table_list->table->versioned(); + + TABLE *table= table_list->table; + bool versioned= table && table->versioned(); bool vers_survival_mod= false; if (versioned) { + if (create_info->db_type && + table->s->db_type() != create_info->db_type && ( + table->file->native_versioned() || + create_info->db_type->flags & HTON_NATIVE_SYS_VERSIONING)) + { + my_error(ER_VERS_ALTER_ENGINE_PROHIBITED, MYF(0), table_list->db, table_list->table_name); + DBUG_RETURN(true); + } bool vers_data_mod= alter_info->data_modifying(); if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE) { @@ -8895,7 +8905,6 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, if (error) DBUG_RETURN(true); - TABLE *table= table_list->table; table->use_all_columns(); MDL_ticket *mdl_ticket= table->mdl_ticket;