Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Done
-
Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 5.5
-
Fix Version/s: 5.5.46
-
Component/s: Storage Engine - InnoDB, Storage Engine - XtraDB
-
Labels:
-
Environment:Win 7 Pro SP1 64-bit
-
Sprint:10.1.8-4
Description
A table can disappear when running ALTER queries on it.
This was tested with MariaDB 5.5.45-winx64, but not in 10.0.21-winx64.
How to reproduce
This problem is reproducible all the time with the aforementioned MariaDB version.
Initial situation
This is the database state before problem. I've removed non-relevant structure.
DROP DATABASE IF EXISTS `test`; CREATE DATABASE `test` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'; USE `test`; CREATE TABLE `test_location` ( `idlocation` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`idlocation`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; CREATE TABLE `test_person` ( `idperson` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`idperson`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; CREATE TABLE `test_item` ( `iditem` int(10) unsigned NOT NULL AUTO_INCREMENT, `idlocation` int(10) unsigned DEFAULT NULL, `idperson` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`iditem`), KEY `fk_test_location_idx` (`idlocation`) USING BTREE, KEY `fk_test_person_idx` (`idperson`) USING BTREE, CONSTRAINT `fk_test_location` FOREIGN KEY (`idlocation`) REFERENCES `test_location` (`idlocation`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_test_person` FOREIGN KEY (`idperson`) REFERENCES `test_person` (`idperson`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
Database corruption
Then I run these commands to alter the database structure.
Note: Both ALTER TABLE statements must be run in order to trigger the problem.
USE `test`; SET FOREIGN_KEY_CHECKS=0; ALTER TABLE `test_item` DROP INDEX `fk_test_person_idx`; ALTER TABLE `test_item` DROP FOREIGN KEY `fk_test_location`;
This will issue error 1025 - Error on rename of '.\test#sql-5108_4' to '.\test\test_item' (errno: 150).
Content of .err log file:
150925 15:05:08 InnoDB: Error: in ALTER TABLE `test`.`test_item` InnoDB: has or is referenced in foreign key constraints InnoDB: which are not compatible with the new table definition. 150925 15:05:08 InnoDB: Error: in ALTER TABLE `test`.`test_item` InnoDB: has or is referenced in foreign key constraints InnoDB: which are not compatible with the new table definition.
At this point the table is not listed anymore with SHOW TABLES. When trying to recreate it:
USE `test`; SET FOREIGN_KEY_CHECKS=0; CREATE TABLE `test_item` ( `iditem` int(10) unsigned NOT NULL AUTO_INCREMENT, `idlocation` int(10) unsigned DEFAULT NULL, `idperson` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`iditem`), KEY `fk_test_location_idx` (`idlocation`) USING BTREE, KEY `fk_test_person_idx` (`idperson`) USING BTREE, CONSTRAINT `fk_test_location` FOREIGN KEY (`idlocation`) REFERENCES `test_location` (`idlocation`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_test_person` FOREIGN KEY (`idperson`) REFERENCES `test_person` (`idperson`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
This will issue error 1005 - Can't create table 'test.test_item' (errno: 121).
"Fix"
To be able to recreate the table, the service must be restarted. After restart, CREATE TABLE statement work.
However, all data is lost.
I know the queries are run in wrong order, but losing a whole table and its data is not acceptable when running "invalid" SQL.
Gliffy Diagrams
Attachments
Issue Links
- relates to
-
MDEV-7809 Crash after modifying FK on version 5.5
-
- Closed
-
- links to
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
It's an upstream bug https://bugs.mysql.com/bug.php?id=68148 which was fixed in 5.6.12 and thus in 10.0 before GA. Do you think there is a critical need to backport the fix into 5.5?