Skip to content

Commit

Permalink
MDEV-25509 Atomic DDL: Assertion `err != DB_DUPLICATE_KEY' fails
Browse files Browse the repository at this point in the history
                after previous error upon multi-RENAME

- InnoDB fails to rename the foreign key constraint while
rollbacking the rename operation. In that case, InnoDB should
rename the FK constraint too.
  • Loading branch information
Thirunarayanan committed Apr 30, 2021
1 parent fd8c68c commit 9fe681c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/r/innodb-truncate.result
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ALTER TABLE t1 RENAME TO t3;
ERROR HY000: Error on rename of './test/t1' to './test/t3' (errno: 150 "Foreign key constraint is incorrectly formed")
ALTER TABLE t1 FORCE;
TRUNCATE TABLE t1;
ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `test`.`t3` (`f2`))
ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `test`.`t1` (`f2`))
DROP TABLE t2, t1;
#
# MDEV-24861 Assertion `trx->rsegs.m_redo.rseg' failed
Expand Down
14 changes: 14 additions & 0 deletions mysql-test/suite/innodb/r/rename_table.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
call mtr.add_suppression("InnoDB: In RENAME TABLE table `test`.`t4` is referenced in foreign key constraints which are not compatible with the new table definition.");
CREATE DATABASE test_jfg;
CREATE DATABASE test_jfg2;
CREATE TABLE test_jfg.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
Expand Down Expand Up @@ -26,3 +27,16 @@ RENAME TABLE t1 TO non_existing_db.t1;
ERROR HY000: Error on rename of './test/t1' to './non_existing_db/t1' (errno: 168 "Unknown (generic) error from engine")
FOUND 1 /\[ERROR\] InnoDB: Cannot rename file '.*t1\.ibd' to '.*non_existing_db/ in mysqld.1.err
DROP TABLE t1;
#
# MDEV-25509 Atomic DDL: Assertion `err != DB_DUPLICATE_KEY'
# fails after previous error upon multi-RENAME
#
SET FOREIGN_KEY_CHECKS= OFF;
CREATE TABLE t1 (pk INT PRIMARY KEY, f INT, FOREIGN KEY (f) REFERENCES t4 (x)) ENGINE=InnoDB;
ALTER TABLE t1 DROP KEY f;
CREATE TABLE t2 (a INT) ENGINE=InnoDB;
RENAME TABLE t1 TO t3, t3 TO t4;
ERROR HY000: Error on rename of './test/t3' to './test/t4' (errno: 150 "Foreign key constraint is incorrectly formed")
RENAME TABLE t2 TO t3;
DROP TABLE t3, t1;
SET FOREIGN_KEY_CHECKS=DEFAULT;
16 changes: 16 additions & 0 deletions mysql-test/suite/innodb/t/rename_table.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
--source include/have_innodb.inc
--source include/not_embedded.inc

call mtr.add_suppression("InnoDB: In RENAME TABLE table `test`.`t4` is referenced in foreign key constraints which are not compatible with the new table definition.");

CREATE DATABASE test_jfg;
CREATE DATABASE test_jfg2;
CREATE TABLE test_jfg.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
Expand Down Expand Up @@ -43,3 +45,17 @@ let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;

# Cleanup
DROP TABLE t1;

--echo #
--echo # MDEV-25509 Atomic DDL: Assertion `err != DB_DUPLICATE_KEY'
--echo # fails after previous error upon multi-RENAME
--echo #
SET FOREIGN_KEY_CHECKS= OFF;
CREATE TABLE t1 (pk INT PRIMARY KEY, f INT, FOREIGN KEY (f) REFERENCES t4 (x)) ENGINE=InnoDB;
ALTER TABLE t1 DROP KEY f;
CREATE TABLE t2 (a INT) ENGINE=InnoDB;
--error ER_ERROR_ON_RENAME
RENAME TABLE t1 TO t3, t3 TO t4;
RENAME TABLE t2 TO t3;
DROP TABLE t3, t1;
SET FOREIGN_KEY_CHECKS=DEFAULT;
5 changes: 4 additions & 1 deletion storage/innobase/row/row0uins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ static bool row_undo_ins_parse_undo_rec(undo_node_t* node, bool dict_locked)
ptr[len] = 0;
const char* name = reinterpret_cast<char*>(ptr);
if (strcmp(table->name.m_name, name)) {
dict_table_rename_in_cache(table, name, false, true);
dict_table_rename_in_cache(
table, name,
!dict_table_t::is_temporary_name(name),
true);
} else if (table->space) {
const auto s = table->space->name();
if (len != s.size() || memcmp(name, s.data(), len)) {
Expand Down

0 comments on commit 9fe681c

Please sign in to comment.