Bug #65701 | character set mismatch when altering foreign keys can lead to missing tables | ||
---|---|---|---|
Submitted: | 21 Jun 2012 16:26 | Modified: | 12 Jun 2013 14:53 |
Reporter: | Ernie Souhrada | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 5.5.24, 5.5.26, 5.6.6 | OS: | Linux (CentOS 6.2) |
Assigned to: | CPU Architecture: | Any | |
Tags: | regression |
[21 Jun 2012 16:26]
Ernie Souhrada
[21 Jun 2012 18:14]
Sveta Smirnova
Thank you for the report. Verified as described. Not repeatable with 5.1
[12 Apr 2013 19:03]
Dmitry Lenev
Hello! Note that bug is still repeatable in current 5.6 tree (5.6.12-bzr). But test case needs slight adjusting. SET FOREIGN_KEY_CHECKS=0; create table dos1 ( fkto2 char(32) not null primary key, fkto3 char(32) not null, fkfrom3 char(32) not null, index(fkto3), index(fkfrom3), foreign key (fkto3) references dos3(fkfrom1), foreign key (fkto2) references dos2(fkfrom1) ) character set=utf8 engine=InnoDB; create table dos2 ( fkfrom1 char(32) not null, fkto3 char(32) not null primary key, index (fkfrom1), foreign key (fkto3) references dos3(fkfrom1) ) character set=utf8 engine=InnoDB; create table dos3 ( fkfrom1 char(32) not null, fkfrom2 char(32) not null, fkto1 char(32) not null primary key, index(fkfrom1), index(fkfrom2), foreign key (fkto1) references dos1(fkfrom3) ) character set=utf8 engine=InnoDB; INSERT INTO dos1 VALUES ('value_fk1_to_2', 'value_fk1_to_3', 'value_fk3_to_1'); INSERT INTO dos2 VALUES ('value_fk1_to_2', 'value_fk2_to_3'); INSERT INTO dos3 VALUES ('value_fk1_to_1', 'value_fk2_to_3', 'value_fk3_to_1'); alter table dos1 change column fkto2 fkto2 char(32) character set ascii not null, change column fkto3 fkto3 char(32) character set ascii not null, change column fkfrom3 fkfrom3 char(32) character set ascii not null; set foreign_key_checks=1; --error 1025 alter table dos2 drop primary key; # "dos2" has gone missing! --error 1146 show create table dos2;
[12 Jun 2013 14:53]
Bugs System
Added a changelog entry for 5.5.33, 5.6.13, 5.7.2: "Setting "foreign_key_checks=0" and running "ALTER TABLE" to change the character set of foreign key columns for a database with multiple tables with foreign key constraints would leave the database in an inconsistent state. Subsequent "ALTER TABLE" operations (using the "COPY" algorithm) with "foreign_key_checks=1" would fail due to the detected inconsistency. Reversion of the partially executed "ALTER TABLE" operation would also fail, resulting in the loss of the table being altered. When running the same "ALTER TABLE" operation with a "RENAME" clause, the inconsistency would not be detected but if the "ALTER TABLE" operation failed for some other reason, reversion of the partially executed "ALTER TABLE" would fail with the same result. The bug fix temporarily disables "foreign_key_checks" while the previous table definition is restored. Thank you for the bug report.
[10 Oct 2014 18:52]
will jaspers
Still broken in 5.5.37 on debian x86_64