summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2021-04-28 03:56:24 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2021-04-28 03:56:24 +0530
commit4cd92143eae9b397589e5b449d1a85c43b3e4f6b (patch)
tree6b75de8622d121d828c0e83bd9382c01cfe0c10e
parent5bc12ca9c294002c09b32238e8bdf4de3dc138dc (diff)
downloadmariadb-git-4cd92143eae9b397589e5b449d1a85c43b3e4f6b.tar.gz
MDEV-25630 Rollback of instant operation adds wrong column to secondary indexbb-10.4-MDEV-25630
Problem: ======= InnoDB alter fails before applying instant operation. So rollback assigns wrong column to the secondary index field. It leads to the assert failure in the consecutive alter. Fix: === InnoDB shouldn't do rollback of instant operation when it fails before applying instant operation.
-rw-r--r--mysql-test/suite/innodb/r/instant_alter.result27
-rw-r--r--mysql-test/suite/innodb/t/instant_alter.test20
-rw-r--r--storage/innobase/handler/handler0alter.cc7
3 files changed, 54 insertions, 0 deletions
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();