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

Unexpected ER_ERROR_ON_RENAME upon DROP non-existing FOREIGN KEY with ALGORITHM=COPY

Details

    Description

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a INT) ENGINE=InnoDB;
      --error ER_CANT_DROP_FIELD_OR_KEY
      ALTER TABLE t1 DROP FOREIGN KEY x, ALGORITHM=COPY;
       
      # Cleanup
      DROP TABLE t1;
      

      10.5 8c0b9880

      query 'ALTER TABLE t1 DROP FOREIGN KEY x, ALGORITHM=COPY' failed with wrong errno 1025: 'Error on rename of './test/t1' to './test/#sql2-10fa-4' (errno: 152 "Cannot delete a parent row")', instead of 1091...
      

      Without ALGORITHM=COPY it fails with ER_CANT_DROP_FIELD_OR_KEY as expected.

      There is an ancient upstream bug https://bugs.mysql.com/bug.php?id=14347 which seems related, but I'm not sure it's quite the same.

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            elenst Elena Stepanova made changes -
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Aleksey Midenkov [ midenok ]
            julien.fritsch Julien Fritsch made changes -
            Comment [ A comment with security level 'Developers' was removed. ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 107076 ] MariaDB v4 [ 141880 ]
            jplindst Jan Lindström (Inactive) made changes -
            Assignee Aleksey Midenkov [ midenok ] Jan Lindström [ jplindst ]
            jplindst Jan Lindström (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]

            While testing my fix I noticed that DROP CONSTRAINT ..., ALGORITHM=COPY has no effect. If you remove ALGORITHM it works as expected.

            CREATE TABLE t1 (a INT primary key, b int) ENGINE=InnoDB;
            CREATE TABLE t2 (a int primary key, b int, constraint b foreign key (b) references t1(a)) engine=innodb;
            SHOW CREATE TABLE t2;
            Table	Create Table
            t2	CREATE TABLE `t2` (
              `a` int(11) NOT NULL,
              `b` int(11) DEFAULT NULL,
              PRIMARY KEY (`a`),
              KEY `b` (`b`),
              CONSTRAINT `b` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)
            ) ENGINE=InnoDB DEFAULT CHARSET=latin1
            ALTER TABLE t2 DROP CONSTRAINT b, ALGORITHM=COPY;
            SHOW CREATE TABLE t2;
            Table	Create Table
            t2	CREATE TABLE `t2` (
              `a` int(11) NOT NULL,
              `b` int(11) DEFAULT NULL,
              PRIMARY KEY (`a`),
              KEY `b` (`b`),
              CONSTRAINT `b` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)
            ) ENGINE=InnoDB DEFAULT CHARSET=latin1
            

            jplindst Jan Lindström (Inactive) added a comment - While testing my fix I noticed that DROP CONSTRAINT ..., ALGORITHM=COPY has no effect. If you remove ALGORITHM it works as expected. CREATE TABLE t1 (a INT primary key, b int) ENGINE=InnoDB; CREATE TABLE t2 (a int primary key, b int, constraint b foreign key (b) references t1(a)) engine=innodb; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, PRIMARY KEY (`a`), KEY `b` (`b`), CONSTRAINT `b` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ALTER TABLE t2 DROP CONSTRAINT b, ALGORITHM=COPY; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, PRIMARY KEY (`a`), KEY `b` (`b`), CONSTRAINT `b` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
            jplindst Jan Lindström (Inactive) made changes -
            jplindst Jan Lindström (Inactive) made changes -
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            jplindst Jan Lindström (Inactive) added a comment - http://buildbot.askmonty.org/buildbot/grid?category=main&branch=bb-10.4-MDEV-22230 https://github.com/MariaDB/server/commit/ba80fb383c7172eaa77375d2945fad77829df9c6
            jplindst Jan Lindström (Inactive) made changes -
            Assignee Jan Lindström [ jplindst ] Alexey Botchkov [ holyfoot ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            Maybe a more convincing test case would be

            --source include/have_innodb.inc
             
            CREATE TABLE t1 (a INT) ENGINE=InnoDB;
            ALTER TABLE t1 MODIFY COLUMN a VARCHAR(2), DROP FOREIGN KEY IF EXISTS x;
             
            # Cleanup
            DROP TABLE t1;
            

            as it doesn't tamper explicitly with the algorithm and it has "IF EXISTS" for the foreign key drop, so it's a perfectly normal valid ALTER which shouldn't fail. But it does

            11.1 3883eb63

            mysqltest: At line 4: query 'ALTER TABLE t1 MODIFY COLUMN a VARCHAR(2), DROP FOREIGN KEY IF EXISTS x' failed: ER_ERROR_ON_RENAME (1025): Error on rename of './test/t1' to './test/#sql-backup-246583-4' (errno: 152 "Cannot delete a parent row")
            

            elenst Elena Stepanova added a comment - Maybe a more convincing test case would be --source include/have_innodb.inc   CREATE TABLE t1 (a INT ) ENGINE=InnoDB; ALTER TABLE t1 MODIFY COLUMN a VARCHAR (2), DROP FOREIGN KEY IF EXISTS x;   # Cleanup DROP TABLE t1; as it doesn't tamper explicitly with the algorithm and it has "IF EXISTS" for the foreign key drop, so it's a perfectly normal valid ALTER which shouldn't fail. But it does 11.1 3883eb63 mysqltest: At line 4: query 'ALTER TABLE t1 MODIFY COLUMN a VARCHAR(2), DROP FOREIGN KEY IF EXISTS x' failed: ER_ERROR_ON_RENAME (1025): Error on rename of './test/t1' to './test/#sql-backup-246583-4' (errno: 152 "Cannot delete a parent row" )
            elenst Elena Stepanova made changes -
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 11.0 [ 28320 ]
            Fix Version/s 11.1 [ 28549 ]
            Affects Version/s 10.6 [ 24028 ]
            Affects Version/s 10.9 [ 26905 ]
            Affects Version/s 10.10 [ 27530 ]
            Affects Version/s 10.11 [ 27614 ]
            Affects Version/s 11.0 [ 28320 ]
            Affects Version/s 11.1 [ 28549 ]

            The FOREIGN KEY handling was refactored in 10.5.0 by MDEV-20480. I think that it would make sense to fix this only in 10.5 and later major releases, because 10.4 will reach end of life soon.

            marko Marko Mäkelä added a comment - The FOREIGN KEY handling was refactored in 10.5.0 by MDEV-20480 . I think that it would make sense to fix this only in 10.5 and later major releases, because 10.4 will reach end of life soon.
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            Fix Version/s 11.2 [ 28603 ]
            Fix Version/s 10.4 [ 22408 ]
            Assignee Alexey Botchkov [ holyfoot ] Thirunarayanan Balathandayuthapani [ thiru ]
            Priority Minor [ 4 ] Major [ 3 ]

            Needs different patch. So taking over this issue

            thiru Thirunarayanan Balathandayuthapani added a comment - Needs different patch. So taking over this issue
            thiru Thirunarayanan Balathandayuthapani made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            thiru Thirunarayanan Balathandayuthapani made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]

            Patch is in bb-10.4-MDEV-22230

            thiru Thirunarayanan Balathandayuthapani added a comment - Patch is in bb-10.4- MDEV-22230
            thiru Thirunarayanan Balathandayuthapani made changes -
            Assignee Thirunarayanan Balathandayuthapani [ thiru ] Marko Mäkelä [ marko ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            This needs some more work, including test coverage to ensure that ALTER TABLE some_table DROP FOREIGN KEY IF EXISTS fk_in_another_table will not drop a constraint by that name from another table.

            marko Marko Mäkelä added a comment - This needs some more work, including test coverage to ensure that ALTER TABLE some_table DROP FOREIGN KEY IF EXISTS fk_in_another_table will not drop a constraint by that name from another table.
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ] Thirunarayanan Balathandayuthapani [ thiru ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            thiru Thirunarayanan Balathandayuthapani made changes -
            Fix Version/s 10.4.33 [ 29516 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 11.0 [ 28320 ]
            Fix Version/s 11.1 [ 28549 ]
            Fix Version/s 11.2 [ 28603 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            JIraAutomate JiraAutomate made changes -
            Fix Version/s 10.5.24 [ 29517 ]
            Fix Version/s 10.6.17 [ 29518 ]
            Fix Version/s 10.11.7 [ 29519 ]
            Fix Version/s 11.0.5 [ 29520 ]
            Fix Version/s 11.1.4 [ 29024 ]
            Fix Version/s 11.2.3 [ 29521 ]

            People

              thiru Thirunarayanan Balathandayuthapani
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.