[MDEV-9548] Alter table (renaming and adding index) fails with "Incorrect key file for table" Created: 2016-02-11  Updated: 2017-10-10  Resolved: 2016-02-12

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 10.0.18, 10.0.23
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: David Gow Assignee: Jan Lindström (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Ubuntu 14.04.1 LTS x86_64, 10.0.23 built from source


Issue Links:
Duplicate
duplicates MDEV-9469 'Incorrect key file' on ALTER TABLE Closed
Problem/Incident
causes MDEV-13668 InnoDB unnecessarily rebuilds table w... Closed
Relates
relates to MDEV-13640 ALTER TABLE CHANGE and ADD INDEX on a... Closed

 Description   

When renaming a column and adding an index on the renamed column in the same alter statement, said statement fails with:

ERROR 1034 (HY000): Incorrect key file for table 't'; try to repair it

This can be reproduced consistently as follows:

DROP TABLE IF EXISTS t;
 
CREATE TABLE t (
        a INT NOT NULL,
        b INT NOT NULL,
        PRIMARY KEY (a)
);
 
ALTER TABLE t
        CHANGE COLUMN b c INT NOT NULL,
        ADD UNIQUE INDEX (c);

In debug builds, the following (or similar) is written to the error log:

InnoDB: Error: no matching column for "<8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f><8f>" in index "c"--temporary-- of table "db"."t"!

This seems to have been broken in 10.0.18 (possibly related to the virtual column changes), as the query succeeds in 10.0.17 and earlier.



 Comments   
Comment by Michael Widenius [ 2016-02-12 ]

This bug affects only InnoDB tables when used with algorithm=inplace

MyISAM tables and also using algorithm=copy works

Comment by Elena Stepanova [ 2016-02-12 ]

We already have this one, MDEV-9469.

Comment by Jan Lindström (Inactive) [ 2016-02-15 ]

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.

Generated at Thu Feb 08 07:35:29 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.