From 77cd754229ba74eb87518285f48e1d95d00fbde9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 14 May 2018 23:24:26 +0200 Subject: [PATCH] MDEV-16110 ALTER with ALGORITHM=INPLACE breaks temporary table with virtual columns Part one, non-temporary tables. Rrenaming a column can make destructive changes to the TABLE. This TABLE cannot be used anymore and needs to be reopened even if ALTER TABLE was aborted with an error. --- mysql-test/r/alter_table_errors.result | 10 ++++++++++ mysql-test/t/alter_table_errors.test | 10 ++++++++++ sql/sql_table.cc | 1 + 3 files changed, 21 insertions(+) create mode 100644 mysql-test/r/alter_table_errors.result create mode 100644 mysql-test/t/alter_table_errors.test diff --git a/mysql-test/r/alter_table_errors.result b/mysql-test/r/alter_table_errors.result new file mode 100644 index 00000000000..020a30304d0 --- /dev/null +++ b/mysql-test/r/alter_table_errors.result @@ -0,0 +1,10 @@ +create table t (a int, v int as (a)) engine=innodb; +alter table t change column a b tinyint, algorithm=inplace; +ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, + `v` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +drop table t; diff --git a/mysql-test/t/alter_table_errors.test b/mysql-test/t/alter_table_errors.test new file mode 100644 index 00000000000..d9982ac26f4 --- /dev/null +++ b/mysql-test/t/alter_table_errors.test @@ -0,0 +1,10 @@ +--source include/have_innodb.inc + +# +# MDEV-16110 ALTER with ALGORITHM=INPLACE breaks temporary table with virtual columns +# +create table t (a int, v int as (a)) engine=innodb; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +alter table t change column a b tinyint, algorithm=inplace; +show create table t; +drop table t; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1ed2194b09a..b6d46ff82ab 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7677,6 +7677,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, if (field->default_value) field->default_value->expr->walk(&Item::rename_fields_processor, 1, &column_rename_param); + table->m_needs_reopen= 1; // because new column name is on thd->mem_root } /* Check if field is changed */