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

'Incorrect key file' on ALTER TABLE

Details

    • 10.0.24

    Description

      Somewhere between MariaDB 10.0.12 and MariaDB 10.0.21 the behavior of ALTER TABLE changed. We have one special ALTER TABLE statement that worked until version 10.0.12 (and maybe later) but stopped to work at version 10.0.21 (maybe earlier). We tried version 10.1.10 as well, which still produces the error.

      How to reproduce:

      First create a table like this:

      CREATE TABLE `w_findispmon05u` (
      `atpkey` INT(11) NOT NULL DEFAULT '0',
      `atzo05` INT(11) NULL DEFAULT NULL,
      `pos` BIGINT(21) NULL DEFAULT NULL,
      `f5BnvB` INT(9) NULL DEFAULT NULL,
      `f5atbvb` INT(11) NULL DEFAULT NULL,
      `f5atbwmg` INT(11) NULL DEFAULT NULL,
      `f5pBneu` BIGINT(12) NULL DEFAULT NULL,
      `atbwdt` INT(11) NULL DEFAULT NULL,
      `atbwzt` INT(11) NULL DEFAULT NULL,
      `atbart` VARCHAR(10) NULL DEFAULT NULL
      )
      COLLATE='utf8_general_ci'
      ENGINE=InnoDB;

      Next do an ALTER table like this:

      ALTER TABLE `w_findispmon05u`
      CHANGE COLUMN `atpkey` `f5atpkey` INT(11) NOT NULL DEFAULT '0' FIRST,
      CHANGE COLUMN `atzo05` `f5atzo05` INT(11) NULL DEFAULT NULL AFTER `f5atpkey`,
      CHANGE COLUMN `atbwdt` `f5atbwdt` INT(11) NULL DEFAULT NULL AFTER `f5pBneu`,
      CHANGE COLUMN `atbwzt` `f5atbwzt` INT(11) NULL DEFAULT NULL AFTER `f5atbwdt`,
      CHANGE COLUMN `atbart` `f5atbart` VARCHAR(10) NULL DEFAULT NULL AFTER `f5atbwzt`,
      ADD INDEX `atpkey` (`f5atpkey`),
      ADD INDEX `inatkey` (`f5atzo05`, `pos`),
      ADD INDEX `pos` (`pos`, `f5atzo05`);

      The message is 'Incorrect key file for table 'w_findispmon05u'; try to repair it'.

      If the ALTER table is split into two statements as follows, the error disappears.

      ALTER TABLE `w_findispmon05u`
      CHANGE COLUMN `atpkey` `f5atpkey` INT(11) NOT NULL DEFAULT '0' FIRST,
      CHANGE COLUMN `atzo05` `f5atzo05` INT(11) NULL DEFAULT NULL AFTER `f5atpkey`,
      CHANGE COLUMN `atbwdt` `f5atbwdt` INT(11) NULL DEFAULT NULL AFTER `f5pBneu`,
      CHANGE COLUMN `atbwzt` `f5atbwzt` INT(11) NULL DEFAULT NULL AFTER `f5atbwdt`,
      CHANGE COLUMN `atbart` `f5atbart` VARCHAR(10) NULL DEFAULT NULL AFTER `f5atbwzt`;

      ALTER TABLE `w_findispmon05u`
      ADD INDEX `atpkey` (`f5atpkey`),
      ADD INDEX `inatkey` (`f5atzo05`, `pos`),
      ADD INDEX `pos` (`pos`, `f5atzo05`);

      We see this behavior with different operating systems (Windows 7 64Bit, various Linux variants), so we think that this does not matter.

      To test it with the version 10.1.10, we just used the MSI installer for Windows 64 Bit with all default settings. The error can be reproduced this way.

      Attachments

        Issue Links

          Activity

            Thanks for the report and the test case.

            The problem appeared in 10.0 tree (10.0.18 release) with the following revision:

            commit b53bcd438f171fcbc3a4ad5051434e1b87c844fe
            Author: Jan Lindström <jan.lindstrom@mariadb.com>
            Date:   Mon Mar 30 18:53:10 2015 +0300
             
                MDEV-7367: Updating a virtual column corrupts table which crashes server
                
                Analysis: MySQL table definition contains also virtual columns. Similarly,
                index fielnr references MySQL table fields. However, InnoDB table definition
                does not contain virtual columns. Therefore, when matching MySQL key fieldnr
                we need to use actual column name to find out referenced InnoDB dictionary
                column name.
                
                Fix: Add new function to match MySQL index key columns to InnoDB dictionary.

            elenst Elena Stepanova added a comment - Thanks for the report and the test case. The problem appeared in 10.0 tree (10.0.18 release) with the following revision: commit b53bcd438f171fcbc3a4ad5051434e1b87c844fe Author: Jan Lindström <jan.lindstrom@mariadb.com> Date: Mon Mar 30 18:53:10 2015 +0300   MDEV-7367: Updating a virtual column corrupts table which crashes server Analysis: MySQL table definition contains also virtual columns. Similarly, index fielnr references MySQL table fields. However, InnoDB table definition does not contain virtual columns. Therefore, when matching MySQL key fieldnr we need to use actual column name to find out referenced InnoDB dictionary column name. Fix: Add new function to match MySQL index key columns to InnoDB dictionary.
            jeremycole Jeremy Cole added a comment -

            Note that MDEV-9548, marked as a duplicate, has a much simpler test case.

            jeremycole Jeremy Cole added a comment - Note that MDEV-9548 , marked as a duplicate, has a much simpler test case.

            commit c0b6c27dbede85952b3e6cd04b6393267e1aa656
            Author: Jan Lindström <jan.lindstrom@mariadb.com>
            Date: Mon Feb 15 14:43:42 2016 +0200

            MDEV-9548: Alter table (renaming and adding index) fails with "Incorrect key file for table"
            MDEV-9469: 'Incorrect key file' on ALTER TABLE

            InnoDB needs to rebuild table if column name is changed and
            added index (or foreign key) is created based on this new
            name in same alter table.

            jplindst Jan Lindström (Inactive) added a comment - commit c0b6c27dbede85952b3e6cd04b6393267e1aa656 Author: Jan Lindström <jan.lindstrom@mariadb.com> Date: Mon Feb 15 14:43:42 2016 +0200 MDEV-9548 : Alter table (renaming and adding index) fails with "Incorrect key file for table" MDEV-9469 : 'Incorrect key file' on ALTER TABLE InnoDB needs to rebuild table if column name is changed and added index (or foreign key) is created based on this new name in same alter table.

            People

              jplindst Jan Lindström (Inactive)
              thomas.mischke Thomas Mischke
              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.