Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-17531

Crash in RENAME TABLE with FOREIGN KEY and FULLTEXT INDEX

Details

    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).

      Attachments

        Issue Links

          Activity

            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.
            

            elenst Elena Stepanova added a comment - 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.

            People

              marko Marko Mäkelä
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.