Possibly related to MDEV-24532.
--source include/have_innodb.inc
|
|
CREATE TABLE t1 (a INT, b INT, KEY(a), FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=InnoDB;
|
SET FOREIGN_KEY_CHECKS= OFF;
|
ALTER TABLE t1 MODIFY a SMALLINT;
|
SHOW CREATE TABLE t1;
|
SELECT * FROM information_schema.innodb_sys_foreign;
|
SELECT UNIQUE_CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME FROM information_schema.referential_constraints;
|
TRUNCATE TABLE t1;
|
|
# Cleanup
|
DROP TABLE t1;
|
In the test case above, 10.2+ versions accept and execute ALTER TABLE, and the column type gets modified. However, after that
- SHOW CREATE TABLE does not show the foreign key any longer;
- information_schema.innodb_sys_foreign still has a record for the foreign key on t1, but information_schema.referential_constraints does not;
- further TRUNCATE TABLE fails with ER_CANNOT_ADD_FOREIGN.
10.5 1b12e251
|
SHOW CREATE TABLE t1;
|
Table Create Table
|
t1 CREATE TABLE `t1` (
|
`a` smallint(6) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
KEY `a` (`a`),
|
KEY `b` (`b`)
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
SELECT * FROM information_schema.innodb_sys_foreign;
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
test/t1_ibfk_1 test/t1 test/t1 1 0
|
SELECT UNIQUE_CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME FROM information_schema.referential_constraints;
|
UNIQUE_CONSTRAINT_NAME TABLE_NAME REFERENCED_TABLE_NAME
|
TRUNCATE TABLE t1;
|
bug.trunc4 'innodb' [ fail ]
|
Test ended at 2021-01-09 02:27:46
|
|
CURRENT_TEST: bug.trunc4
|
mysqltest: At line 9: query 'TRUNCATE TABLE t1' failed: 1215: Cannot add foreign key constraint for `t1`
|
Reproducible on 10.2-10.5.
On 10.1 and MySQL 5.7 ALTER TABLE fails with ER_ERROR_ON_RENAME, and no further damage is done.
{"report":{"fcp":1346.7000000476837,"ttfb":541.7999999523163,"pageVisibility":"visible","entityId":95750,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"b987e4f7-c831-4ce0-966d-a993474689d5","navigationType":0,"readyForUser":1440.2999999523163,"redirectCount":0,"resourceLoadedEnd":1617.5,"resourceLoadedStart":547.4000000953674,"resourceTiming":[{"duration":207.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":547.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":547.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":755,"responseStart":0,"secureConnectionStart":0},{"duration":207.79999995231628,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":547.6000001430511,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":547.6000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":755.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":249.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":547.7999999523163,"connectEnd":547.7999999523163,"connectStart":547.7999999523163,"domainLookupEnd":547.7999999523163,"domainLookupStart":547.7999999523163,"fetchStart":547.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":547.7999999523163,"responseEnd":797.6000001430511,"responseStart":797.6000001430511,"secureConnectionStart":547.7999999523163},{"duration":321.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":548,"connectEnd":548,"connectStart":548,"domainLookupEnd":548,"domainLookupStart":548,"fetchStart":548,"redirectEnd":0,"redirectStart":0,"requestStart":548,"responseEnd":869.1000001430511,"responseStart":869.1000001430511,"secureConnectionStart":548},{"duration":325.2000000476837,"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":548.2000000476837,"connectEnd":548.2000000476837,"connectStart":548.2000000476837,"domainLookupEnd":548.2000000476837,"domainLookupStart":548.2000000476837,"fetchStart":548.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":548.2000000476837,"responseEnd":873.4000000953674,"responseStart":873.4000000953674,"secureConnectionStart":548.2000000476837},{"duration":325.40000009536743,"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":548.5,"connectEnd":548.5,"connectStart":548.5,"domainLookupEnd":548.5,"domainLookupStart":548.5,"fetchStart":548.5,"redirectEnd":0,"redirectStart":0,"requestStart":548.5,"responseEnd":873.9000000953674,"responseStart":873.9000000953674,"secureConnectionStart":548.5},{"duration":325.59999990463257,"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":548.6000001430511,"connectEnd":548.6000001430511,"connectStart":548.6000001430511,"domainLookupEnd":548.6000001430511,"domainLookupStart":548.6000001430511,"fetchStart":548.6000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":548.6000001430511,"responseEnd":874.2000000476837,"responseStart":874.2000000476837,"secureConnectionStart":548.6000001430511},{"duration":421.60000014305115,"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":548.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":548.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":970.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":325.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":549,"connectEnd":549,"connectStart":549,"domainLookupEnd":549,"domainLookupStart":549,"fetchStart":549,"redirectEnd":0,"redirectStart":0,"requestStart":549,"responseEnd":874.7000000476837,"responseStart":874.7000000476837,"secureConnectionStart":549},{"duration":421.2999999523163,"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":549.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":549.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":970.5,"responseStart":0,"secureConnectionStart":0},{"duration":326,"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":549.2999999523163,"connectEnd":549.2999999523163,"connectStart":549.2999999523163,"domainLookupEnd":549.2999999523163,"domainLookupStart":549.2999999523163,"fetchStart":549.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":549.2999999523163,"responseEnd":875.2999999523163,"responseStart":875.2999999523163,"secureConnectionStart":549.2999999523163},{"duration":549.7999999523163,"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":555,"connectEnd":555,"connectStart":555,"domainLookupEnd":555,"domainLookupStart":555,"fetchStart":555,"redirectEnd":0,"redirectStart":0,"requestStart":555,"responseEnd":1104.7999999523163,"responseStart":1104.7999999523163,"secureConnectionStart":555},{"duration":1024.7999999523163,"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":555.2000000476837,"connectEnd":555.2000000476837,"connectStart":555.2000000476837,"domainLookupEnd":555.2000000476837,"domainLookupStart":555.2000000476837,"fetchStart":555.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":555.2000000476837,"responseEnd":1580,"responseStart":1580,"secureConnectionStart":555.2000000476837},{"duration":131.89999985694885,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":983.1000001430511,"connectEnd":983.1000001430511,"connectStart":983.1000001430511,"domainLookupEnd":983.1000001430511,"domainLookupStart":983.1000001430511,"fetchStart":983.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":983.1000001430511,"responseEnd":1115,"responseStart":1115,"secureConnectionStart":983.1000001430511},{"duration":349.2000000476837,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1268.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1268.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1617.5,"responseStart":0,"secureConnectionStart":0},{"duration":312.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1269.2000000476837,"connectEnd":1269.2000000476837,"connectStart":1269.2000000476837,"domainLookupEnd":1269.2000000476837,"domainLookupStart":1269.2000000476837,"fetchStart":1269.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1269.2000000476837,"responseEnd":1581.7000000476837,"responseStart":1581.7000000476837,"secureConnectionStart":1269.2000000476837},{"duration":315.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1269.7000000476837,"connectEnd":1269.7000000476837,"connectStart":1269.7000000476837,"domainLookupEnd":1269.7000000476837,"domainLookupStart":1269.7000000476837,"fetchStart":1269.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1269.7000000476837,"responseEnd":1584.7999999523163,"responseStart":1584.7999999523163,"secureConnectionStart":1269.7000000476837},{"duration":283.09999990463257,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1339.6000001430511,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1339.6000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1622.7000000476837,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":373,"responseStart":541,"responseEnd":546,"domLoading":545,"domInteractive":1651,"domContentLoadedEventStart":1651,"domContentLoadedEventEnd":1698,"domComplete":1927,"loadEventStart":1927,"loadEventEnd":1928,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1625.7999999523163},{"name":"bigPipe.sidebar-id.end","time":1626.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.start","time":1626.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1628.1000001430511},{"name":"activityTabFullyLoaded","time":1714.7999999523163}],"measures":[],"correlationId":"36d126d5fa5d89","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":102,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Here is another test case. I don't know if it's exactly the same issue, since there is no visible discrepancy here, just the unexpected error, but creating yet another JIRA report about TRUNCATE table with corrupt foreign keys, in addition to this one and
MDEV-24532, seems way too excessive. Feel free to treat it any way you like.--source include/have_innodb.inc
# Cleanup
The test case is admittedly not very practical, but on the "positive" side it doesn't require disabling FOREIGN_KEY_CHECKS.
Unlike with the test case in the description, ALTER does not cause the FK to disappear from SHOW CREATE or I_S tables; however, TRUNCATE still causes ER_CANNOT_ADD_FOREIGN.