Type:
Bug
Priority:
Major
Resolution:
Unresolved
Affects Version/s:
10.2(EOL) , 10.3(EOL) , 10.4(EOL) , 10.5 , 10.6
InnoDB fails to rename the foreign key constraint during rename table alter using
copy algorithm.
The following test case repeats the scenario:
--source include/have_innodb.inc
create table t1(f1 int not null, index(f1))engine=innodb;
create table t2(f1 int not null,
foreign key(f1) references t1(f1))engine=innodb;
alter table t1 rename to tm1, algorithm=copy;
show create table tm1;
Table Create Table
tm1 CREATE TABLE `tm1` (
`f1` int(11) NOT NULL,
KEY `f1` (`f1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`f1` int(11) NOT NULL,
KEY `f1` (`f1`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
select * from information_schema.innodb_sys_foreign;
ID FOR_NAME REF_NAME N_COLS TYPE
test/t2_ibfk_1 test/t2 test/t1 1 0
create table t1(f1 int not null)engine=innodb;
Error failed: 1215: Cannot add foreign key constraint
Analysis:
=========
Copy alter algorithm does the following steps:
1) Create a new table (#sql) and copies the row from old table
Doesn't add anything in SYS_FOREIGN
2) Rename t1 to #sql2
Rename the table name in InnoDB dictionary
Rename the file name too
Doesn't rename the constraint in SYS_FOREIGN tables
3) RENAME #sql to tm1
Rename the table name in InnoDB dictionary
Loads the foreign & referenced index from SYS_FOREIGN
using the table name(tm1). But InnoDB doesn't have any FK constraint
with the name (tm1)
4) DROP #sql2
Does check whether the SYS_FOREIGN has the foreign key constraint using the table name.
{"report":{"fcp":1462.5,"ttfb":361.29999999701977,"pageVisibility":"visible","entityId":100358,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"25bf9498-7b00-4a95-8f28-ac7bfa214764","navigationType":0,"readyForUser":1543.4000000059605,"redirectCount":0,"resourceLoadedEnd":1779.1000000089407,"resourceLoadedStart":367.5,"resourceTiming":[{"duration":657.7999999970198,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":367.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":367.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1025.2999999970198,"responseStart":0,"secureConnectionStart":0},{"duration":657.8000000119209,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":367.79999999701977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":367.79999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1025.6000000089407,"responseStart":0,"secureConnectionStart":0},{"duration":667.2000000029802,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":367.90000000596046,"connectEnd":367.90000000596046,"connectStart":367.90000000596046,"domainLookupEnd":367.90000000596046,"domainLookupStart":367.90000000596046,"fetchStart":367.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":367.90000000596046,"responseEnd":1035.1000000089407,"responseStart":1035.1000000089407,"secureConnectionStart":367.90000000596046},{"duration":696.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":368,"connectEnd":368,"connectStart":368,"domainLookupEnd":368,"domainLookupStart":368,"fetchStart":368,"redirectEnd":0,"redirectStart":0,"requestStart":368,"responseEnd":1064.5,"responseStart":1064.5,"secureConnectionStart":368},{"duration":700.1000000089407,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":368.29999999701977,"connectEnd":368.29999999701977,"connectStart":368.29999999701977,"domainLookupEnd":368.29999999701977,"domainLookupStart":368.29999999701977,"fetchStart":368.29999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":368.29999999701977,"responseEnd":1068.4000000059605,"responseStart":1068.4000000059605,"secureConnectionStart":368.29999999701977},{"duration":747.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":368.40000000596046,"connectEnd":368.40000000596046,"connectStart":368.40000000596046,"domainLookupEnd":368.40000000596046,"domainLookupStart":368.40000000596046,"fetchStart":368.40000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":368.40000000596046,"responseEnd":1115.9000000059605,"responseStart":1115.9000000059605,"secureConnectionStart":368.40000000596046},{"duration":748.5999999940395,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":368.6000000089407,"connectEnd":368.6000000089407,"connectStart":368.6000000089407,"domainLookupEnd":368.6000000089407,"domainLookupStart":368.6000000089407,"fetchStart":368.6000000089407,"redirectEnd":0,"redirectStart":0,"requestStart":368.6000000089407,"responseEnd":1117.2000000029802,"responseStart":1117.2000000029802,"secureConnectionStart":368.6000000089407},{"duration":824.2000000029802,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":368.79999999701977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":368.79999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1193,"responseStart":0,"secureConnectionStart":0},{"duration":748.8999999910593,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":368.90000000596046,"connectEnd":368.90000000596046,"connectStart":368.90000000596046,"domainLookupEnd":368.90000000596046,"domainLookupStart":368.90000000596046,"fetchStart":368.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":368.90000000596046,"responseEnd":1117.7999999970198,"responseStart":1117.7999999970198,"secureConnectionStart":368.90000000596046},{"duration":824.0999999940395,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":369.1000000089407,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":369.1000000089407,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1193.2000000029802,"responseStart":0,"secureConnectionStart":0},{"duration":749.2000000029802,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":369.29999999701977,"connectEnd":369.29999999701977,"connectStart":369.29999999701977,"domainLookupEnd":369.29999999701977,"domainLookupStart":369.29999999701977,"fetchStart":369.29999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":369.29999999701977,"responseEnd":1118.5,"responseStart":1118.5,"secureConnectionStart":369.29999999701977},{"duration":1256.6000000089407,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":378,"connectEnd":378,"connectStart":378,"domainLookupEnd":378,"domainLookupStart":378,"fetchStart":378,"redirectEnd":0,"redirectStart":0,"requestStart":378,"responseEnd":1634.6000000089407,"responseStart":1634.6000000089407,"secureConnectionStart":378},{"duration":1399.1000000089407,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":380,"connectEnd":380,"connectStart":380,"domainLookupEnd":380,"domainLookupStart":380,"fetchStart":380,"redirectEnd":0,"redirectStart":0,"requestStart":380,"responseEnd":1779.1000000089407,"responseStart":1779.1000000089407,"secureConnectionStart":380},{"duration":460.70000000298023,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1262.4000000059605,"connectEnd":1262.4000000059605,"connectStart":1262.4000000059605,"domainLookupEnd":1262.4000000059605,"domainLookupStart":1262.4000000059605,"fetchStart":1262.4000000059605,"redirectEnd":0,"redirectStart":0,"requestStart":1262.4000000059605,"responseEnd":1723.1000000089407,"responseStart":1723.1000000089407,"secureConnectionStart":1262.4000000059605}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":200,"responseStart":362,"responseEnd":380,"domLoading":366,"domInteractive":1800,"domContentLoadedEventStart":1800,"domContentLoadedEventEnd":1839,"domComplete":3701,"loadEventStart":3701,"loadEventEnd":3703,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1781.2000000029802},{"name":"bigPipe.sidebar-id.end","time":1782},{"name":"bigPipe.activity-panel-pipe-id.start","time":1782.2000000029802},{"name":"bigPipe.activity-panel-pipe-id.end","time":1784.5},{"name":"activityTabFullyLoaded","time":1845}],"measures":[],"correlationId":"d28ff57814f2c8","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":93,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}