diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index b803d968836..110939b5fdb 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -2854,3 +2854,30 @@ SELECT COUNT(*) FROM t1; COUNT(*) 16 DROP TABLE t1; +# +# MDEV-25630 Rollback of instant operation adds wrong +# column to secondary index +# +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT, f4 INT, +PRIMARY KEY(f1, f4), +KEY(f2))ENGINE=InnoDB; +CREATE TABLE t2 (f1 INT, f2 INT, PRIMARY KEY(f1), +FOREIGN KEY fk (f2) REFERENCES t2(f1) +)ENGINE=InnoDB; +ALTER TABLE t1 ADD f5 INT; +SET FOREIGN_KEY_CHECKS=0; +ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1) +REFERENCES x(x); +ERROR HY000: Failed to add the foreign key constraint 'test/fk' to system tables +ALTER TABLE t1 DROP COLUMN f5; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL, + `f2` int(11) DEFAULT NULL, + `f3` int(11) DEFAULT NULL, + `f4` int(11) NOT NULL, + PRIMARY KEY (`f1`,`f4`), + KEY `f2` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test index 3d567cb0704..3872f080d6b 100644 --- a/mysql-test/suite/innodb/t/instant_alter.test +++ b/mysql-test/suite/innodb/t/instant_alter.test @@ -917,3 +917,23 @@ INSERT INTO t1(a, b) SELECT '', '' FROM seq_1_to_16; SELECT COUNT(*) FROM t1; # Cleanup DROP TABLE t1; + +--echo # +--echo # MDEV-25630 Rollback of instant operation adds wrong +--echo # column to secondary index +--echo # +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT, f4 INT, + PRIMARY KEY(f1, f4), + KEY(f2))ENGINE=InnoDB; +CREATE TABLE t2 (f1 INT, f2 INT, PRIMARY KEY(f1), + FOREIGN KEY fk (f2) REFERENCES t2(f1) + )ENGINE=InnoDB; + +ALTER TABLE t1 ADD f5 INT; +SET FOREIGN_KEY_CHECKS=0; +--error ER_FK_FAIL_ADD_SYSTEM +ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1) + REFERENCES x(x); +ALTER TABLE t1 DROP COLUMN f5; +SHOW CREATE TABLE t1; +DROP TABLE t1, t2; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index f523f9a361b..a330cbc5460 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -766,6 +766,13 @@ inline void dict_table_t::rollback_instant( const ulint* col_map) { ut_d(dict_sys.assert_locked()); + + if (cols == old_cols) { + /* Alter fails before instant operation happens. + So there is no need to do rollback instant operation */ + return; + } + dict_index_t* index = indexes.start; mtr_t mtr; mtr.start();