[MDEV-17531] Crash in RENAME TABLE with FOREIGN KEY and FULLTEXT INDEX Created: 2018-10-24  Updated: 2019-01-28  Resolved: 2018-10-25

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB, Storage Engine - XtraDB
Affects Version/s: 10.0.7, 10.1.0, 10.2.0, 10.3.0
Fix Version/s: 10.0.37, 10.3.11, 10.1.37, 10.2.19

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: ddl, foreign-keys, fulltext, upstream

Issue Links:
Blocks
blocks MDEV-17533 Merge new release of InnoDB 5.6.42 to... Closed

 Description   

A bug fix in MySQL 5.6.13 for RENAME TABLE introduced a regression for the following test case:

CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
CREATE DATABASE best;
CREATE TABLE t3 (a INT PRIMARY KEY,
CONSTRAINT t2_ibfk_1 FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB;
CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB;
--error ER_TABLE_EXISTS_ERROR
RENAME TABLE best.t2 TO test.t2;
SHOW CREATE TABLE best.t2;
DROP TABLE best.t2,t3,t1;

10.0 642394197e397fa73d776ee1fecdbd07f54607ff

Version: '10.0.37-MariaDB-debug'  socket: '/dev/shm/10.0/mysql-test/var/tmp/mysqld.1.sock'  port: 16000  Source distribution
2018-10-24 10:57:33 7fe9b3592700  InnoDB: Assertion failure in thread 140641713071872 in file que0que.cc line 1248
InnoDB: Failing assertion: trx->error_state == DB_SUCCESS

There was a fix for this in MySQL 5.6.42 and 5.7.24 (without a test case).



 Comments   
Comment by Elena Stepanova [ 2018-10-24 ]

On current 10.2 (ab1ce2204e9) the test case doesn't work for me, it fails like so:

MariaDB [test]> CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
    -> FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB;
ERROR 1005 (HY000): Can't create table `best`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
MariaDB [test]> show warnings;
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                                             |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning |  150 | Create  table `best`.`t2` with foreign key constraint failed. Referenced table `best`.`t1` not found in the data dictionary near 'FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB'. |
| Error   | 1005 | Can't create table `best`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")                                                                                          |
| Warning | 1215 | Cannot add foreign key constraint                                                                                                                                                   |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

And if I modify it to reference `test`.`t1` specifically, then it doesn't crash, although produces a bunch of error messages which look pretty weird:

Version: '10.2.19-MariaDB-debug-log'  socket: '/home/elenst/bld/10.2/mysql-test/var/tmp/mysqld.1.sock'  port: 16000  Source distribution
2018-10-24 12:26:00 139894668666624 [ERROR] InnoDB: Possible reasons:
2018-10-24 12:26:00 139894668666624 [ERROR] InnoDB: (1) Table rename would cause two FOREIGN KEY constraints to have the same internal name in case-insensitive comparison.
2018-10-24 12:26:00 139894668666624 [ERROR] InnoDB: (2) Table `test`.`t2` exists in the InnoDB internal data dictionary though MySQL is trying to rename table `best`.`t2` to it. Have you deleted the .frm file and not used DROP TABLE?
2018-10-24 12:26:00 139894668666624 [Note] InnoDB: Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2018-10-24 12:26:00 139894668666624 [ERROR] InnoDB: If table `test`.`t2` is a temporary table #sql..., then it can be that there are still queries running on the table, and it will be dropped automatically when the queries end. You can drop the orphaned table inside InnoDB by creating an InnoDB table with the same name in another database and copying the .frm file to the current database. Then MySQL thinks the table exists, and DROP TABLE will succeed.

Generated at Thu Feb 08 08:37:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.