diff --git a/mysql-test/suite/innodb/r/alter_table.result b/mysql-test/suite/innodb/r/alter_table.result index 2fb09e2fe5c..e47bfb90152 100644 --- a/mysql-test/suite/innodb/r/alter_table.result +++ b/mysql-test/suite/innodb/r/alter_table.result @@ -38,3 +38,18 @@ Warnings: Warning 1105 ORDER BY ignored as there is a user-defined clustered index in the table 't1' DROP TABLE t1; SET sql_mode=DEFAULT; +# +# MDEV-18775 Server crashes in dict_table_t::instant_column +# upon ADD COLUMN +# +CREATE TABLE tx (pk INT PRIMARY KEY) ENGINE=InnoDB; +CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a), FOREIGN KEY (a) REFERENCES tx (pk)) ENGINE=InnoDB; +SET FOREIGN_KEY_CHECKS=OFF; +ALTER TABLE t1 DROP a; +ERROR HY000: Cannot drop column 'a': needed in a foreign key constraint 'test/t1_ibfk_1' +SET FOREIGN_KEY_CHECKS=ON; +ALTER TABLE t1 ADD b INT; +ALTER TABLE t1 DROP a; +ERROR HY000: Cannot drop index 'a': needed in a foreign key constraint +ALTER TABLE t1 ADD c INT; +DROP TABLE t1, tx; diff --git a/mysql-test/suite/innodb/t/alter_table.test b/mysql-test/suite/innodb/t/alter_table.test index ece24eb45c7..d0943e7d407 100644 --- a/mysql-test/suite/innodb/t/alter_table.test +++ b/mysql-test/suite/innodb/t/alter_table.test @@ -38,3 +38,24 @@ ALTER TABLE t1 ORDER BY a; DROP TABLE t1; SET sql_mode=DEFAULT; + +--echo # +--echo # MDEV-18775 Server crashes in dict_table_t::instant_column +--echo # upon ADD COLUMN +--echo # + +CREATE TABLE tx (pk INT PRIMARY KEY) ENGINE=InnoDB; +CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a), FOREIGN KEY (a) REFERENCES tx (pk)) ENGINE=InnoDB; + +SET FOREIGN_KEY_CHECKS=OFF; + +--error ER_FK_COLUMN_CANNOT_DROP +ALTER TABLE t1 DROP a; + +SET FOREIGN_KEY_CHECKS=ON; + +ALTER TABLE t1 ADD b INT; +--error ER_DROP_INDEX_FK +ALTER TABLE t1 DROP a; +ALTER TABLE t1 ADD c INT; +DROP TABLE t1, tx; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 47cc31ce9dc..c04c69ba8e2 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -5142,14 +5142,12 @@ error_handled: ut_ad(!user_table->drop_aborted); err_exit: -#ifdef UNIV_DEBUG /* Clear the to_be_dropped flag in the data dictionary cache. */ for (ulint i = 0; i < ctx->num_to_drop_index; i++) { DBUG_ASSERT(ctx->drop_index[i]->is_committed()); DBUG_ASSERT(ctx->drop_index[i]->to_be_dropped); ctx->drop_index[i]->to_be_dropped = 0; } -#endif /* UNIV_DEBUG */ row_mysql_unlock_data_dictionary(ctx->trx);