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.
- relates to
-
MDEV-7809
Crash after modifying FK on version 5.5
-
-
Closed
- links to
-
{"report":{"fcp":1049.4000005722046,"ttfb":282,"pageVisibility":"visible","entityId":53351,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ee653ac3-29a3-4e4d-8180-e05ab2e4b510","navigationType":0,"readyForUser":1154.1999998092651,"redirectCount":0,"resourceLoadedEnd":1452,"resourceLoadedStart":287,"resourceTiming":[{"duration":296.6000003814697,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":287,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":287,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":583.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":296.70000076293945,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":287.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":287.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":583.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":305.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":287.4000005722046,"connectEnd":287.4000005722046,"connectStart":287.4000005722046,"domainLookupEnd":287.4000005722046,"domainLookupStart":287.4000005722046,"fetchStart":287.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":287.4000005722046,"responseEnd":592.9000005722046,"responseStart":592.9000005722046,"secureConnectionStart":287.4000005722046},{"duration":338.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":287.69999980926514,"connectEnd":287.69999980926514,"connectStart":287.69999980926514,"domainLookupEnd":287.69999980926514,"domainLookupStart":287.69999980926514,"fetchStart":287.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":287.69999980926514,"responseEnd":626.1999998092651,"responseStart":626.1999998092651,"secureConnectionStart":287.69999980926514},{"duration":342,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":287.80000019073486,"connectEnd":287.80000019073486,"connectStart":287.80000019073486,"domainLookupEnd":287.80000019073486,"domainLookupStart":287.80000019073486,"fetchStart":287.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":287.80000019073486,"responseEnd":629.8000001907349,"responseStart":629.8000001907349,"secureConnectionStart":287.80000019073486},{"duration":342.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":288,"connectEnd":288,"connectStart":288,"domainLookupEnd":288,"domainLookupStart":288,"fetchStart":288,"redirectEnd":0,"redirectStart":0,"requestStart":288,"responseEnd":630.3000001907349,"responseStart":630.3000001907349,"secureConnectionStart":288},{"duration":342.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":288.1000003814697,"connectEnd":288.1000003814697,"connectStart":288.1000003814697,"domainLookupEnd":288.1000003814697,"domainLookupStart":288.1000003814697,"fetchStart":288.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":288.1000003814697,"responseEnd":630.6999998092651,"responseStart":630.6999998092651,"secureConnectionStart":288.1000003814697},{"duration":448.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":288.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":288.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":737,"responseStart":0,"secureConnectionStart":0},{"duration":342.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":288.69999980926514,"connectEnd":288.69999980926514,"connectStart":288.69999980926514,"domainLookupEnd":288.69999980926514,"domainLookupStart":288.69999980926514,"fetchStart":288.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":288.69999980926514,"responseEnd":631.1000003814697,"responseStart":631.1000003814697,"secureConnectionStart":288.69999980926514},{"duration":448.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":288.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":288.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":737.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":342.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":289,"connectEnd":289,"connectStart":289,"domainLookupEnd":289,"domainLookupStart":289,"fetchStart":289,"redirectEnd":0,"redirectStart":0,"requestStart":289,"responseEnd":631.6999998092651,"responseStart":631.6999998092651,"secureConnectionStart":289},{"duration":986.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":295.5,"connectEnd":295.5,"connectStart":295.5,"domainLookupEnd":295.5,"domainLookupStart":295.5,"fetchStart":295.5,"redirectEnd":0,"redirectStart":0,"requestStart":295.5,"responseEnd":1282.4000005722046,"responseStart":1282.4000005722046,"secureConnectionStart":295.5},{"duration":1155,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":297,"connectEnd":297,"connectStart":297,"domainLookupEnd":297,"domainLookupStart":297,"fetchStart":297,"redirectEnd":0,"redirectStart":0,"requestStart":297,"responseEnd":1452,"responseStart":1452,"secureConnectionStart":297},{"duration":538.6000003814697,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":748.1999998092651,"connectEnd":748.1999998092651,"connectStart":748.1999998092651,"domainLookupEnd":748.1999998092651,"domainLookupStart":748.1999998092651,"fetchStart":748.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":748.1999998092651,"responseEnd":1286.8000001907349,"responseStart":1286.8000001907349,"secureConnectionStart":748.1999998092651},{"duration":425.19999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1042.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1042.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1467.3000001907349,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":115,"responseStart":282,"responseEnd":296,"domLoading":285,"domInteractive":1473,"domContentLoadedEventStart":1473,"domContentLoadedEventEnd":1519,"domComplete":3085,"loadEventStart":3085,"loadEventEnd":3087,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1456.6000003814697},{"name":"bigPipe.sidebar-id.end","time":1457.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1457.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1460.1999998092651},{"name":"activityTabFullyLoaded","time":1527.5}],"measures":[],"correlationId":"549706fce9495b","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":96,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}