This bug report is effectively a duplicate of a MySQL bug I just reported in Oracle's bug tracker: https://bugs.mysql.com/bug.php?id=98976 . I was investigating whether MariaDB 10.4 would allow the customer to fix their database dump. I'm copying over the description from there.
This bug report is related to #88718: https://bugs.mysql.com/bug.php?id=88718
We have customers that dumped their database with a MySQL version affected by #88718. Thus the dump contains an incorrect case for the referenced columns of some foreign keys. This incorrect case is not always corrected on a reimport into a fixed MySQL 8 version. Specifically the case will still be broken if the table is created before the referenced table is.
I have added a minimal reproducer dump to the "How to repeat" field [MariaDB note: I attached it as a file] . The foreign key appears to be fully functional after the import, but it will still show the wrong case. Find below a session within the `mysql` command line client.
mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.01 sec)
mysql> use test;
Database changed
mysql> /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE a (
-> A_UPPERCASE_ID INT NOT NULL PRIMARY KEY,
-> b_ref INT NOT NULL,
->
-> FOREIGN KEY (b_ref) REFERENCES b (b_uppercase_id)
-> );
Query OK, 0 rows affected (0.08 sec)
mysql>
mysql> CREATE TABLE b (
-> B_UPPERCASE_ID INT NOT NULL PRIMARY KEY
-> );
Query OK, 0 rows affected (0.06 sec)
mysql>
mysql> CREATE TABLE c (
-> C_UPPERCASE_ID INT NOT NULL PRIMARY KEY,
-> b_ref INT NOT NULL,
->
-> FOREIGN KEY (b_ref) REFERENCES b (b_uppercase_id)
-> );
Query OK, 0 rows affected (0.09 sec)
mysql> /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW CREATE TABLE a \G SHOW CREATE TABLE b \G SHOW CREATE TABLE c \G*************************** 1. row ***************************
Table: a
Create Table: CREATE TABLE `a` (
`A_UPPERCASE_ID` int NOT NULL,
`b_ref` int NOT NULL,
PRIMARY KEY (`A_UPPERCASE_ID`),
KEY `b_ref` (`b_ref`),
CONSTRAINT `a_ibfk_1` FOREIGN KEY (`b_ref`) REFERENCES `b` (`b_uppercase_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)
*************************** 1. row ***************************
Table: b
Create Table: CREATE TABLE `b` (
`B_UPPERCASE_ID` int NOT NULL,
PRIMARY KEY (`B_UPPERCASE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)
*************************** 1. row ***************************
Table: c
Create Table: CREATE TABLE `c` (
`C_UPPERCASE_ID` int NOT NULL,
`b_ref` int NOT NULL,
PRIMARY KEY (`C_UPPERCASE_ID`),
KEY `b_ref` (`b_ref`),
CONSTRAINT `c_ibfk_1` FOREIGN KEY (`b_ref`) REFERENCES `b` (`B_UPPERCASE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.01 sec)
=======
=======> Note that the case of the foreign key has been corrected for table `c`, but not for table `a`.
=======
mysql> INSERT INTO b (B_UPPERCASE_ID) VALUES (1);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO a (A_UPPERCASE_ID, b_ref) VALUES (1, 1);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO a (A_UPPERCASE_ID, b_ref) VALUES (2, 2);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`a`, CONSTRAINT `a_ibfk_1` FOREIGN KEY (`b_ref`) REFERENCES `b` (`b_uppercase_id`))
=======
=======> Note how the foreign key is fully functional.
=======
The case will still be broken after dumping the database again:
root@6c3c3cc1c192:/# mysqldump -proot test |grep CONSTRAINT
mysqldump: [Warning] Using a password on the command line interface can be insecure.
CONSTRAINT `a_ibfk_1` FOREIGN KEY (`b_ref`) REFERENCES `b` (`b_uppercase_id`)
CONSTRAINT `c_ibfk_1` FOREIGN KEY (`b_ref`) REFERENCES `b` (`B_UPPERCASE_ID`)
Thus the customer is unable to fix the case of their foreign keys without manually editing the database dump.
bug.sql 2020-03-17 15:47 0.5 kB Tim Düsterhus
relates to
MDEV-16417
Store Foreign Key metadata outside of InnoDB
In Review
{"report":{"fcp":840.6000003814697,"ttfb":164,"pageVisibility":"visible","entityId":84204,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":16,"apdex":1,"journeyId":"47a4ae5f-096a-49c1-9101-fa667178a708","navigationType":0,"readyForUser":963.8000001907349,"redirectCount":0,"resourceLoadedEnd":1014.2000007629395,"resourceLoadedStart":185.5,"resourceTiming":[{"duration":75.20000076293945,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":185.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":185.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":260.70000076293945,"responseStart":0,"secureConnectionStart":0},{"duration":74.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":185.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":185.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":260.70000076293945,"responseStart":0,"secureConnectionStart":0},{"duration":157.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":186,"connectEnd":186,"connectStart":186,"domainLookupEnd":186,"domainLookupStart":186,"fetchStart":186,"redirectEnd":0,"redirectStart":0,"requestStart":186,"responseEnd":343.6000003814697,"responseStart":343.6000003814697,"secureConnectionStart":186},{"duration":308.79999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":186.20000076293945,"connectEnd":186.20000076293945,"connectStart":186.20000076293945,"domainLookupEnd":186.20000076293945,"domainLookupStart":186.20000076293945,"fetchStart":186.20000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":186.20000076293945,"responseEnd":495,"responseStart":494.9000005722046,"secureConnectionStart":186.20000076293945},{"duration":312,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":186.30000019073486,"connectEnd":186.30000019073486,"connectStart":186.30000019073486,"domainLookupEnd":186.30000019073486,"domainLookupStart":186.30000019073486,"fetchStart":186.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":186.30000019073486,"responseEnd":498.30000019073486,"responseStart":498.30000019073486,"secureConnectionStart":186.30000019073486},{"duration":312.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":186.4000005722046,"connectEnd":186.4000005722046,"connectStart":186.4000005722046,"domainLookupEnd":186.4000005722046,"domainLookupStart":186.4000005722046,"fetchStart":186.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":186.4000005722046,"responseEnd":498.80000019073486,"responseStart":498.80000019073486,"secureConnectionStart":186.4000005722046},{"duration":312.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":186.5,"connectEnd":186.5,"connectStart":186.5,"domainLookupEnd":186.5,"domainLookupStart":186.5,"fetchStart":186.5,"redirectEnd":0,"redirectStart":0,"requestStart":186.5,"responseEnd":499.30000019073486,"responseStart":499.30000019073486,"secureConnectionStart":186.5},{"duration":318.5999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":186.70000076293945,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":186.70000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":505.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":313,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":186.70000076293945,"connectEnd":186.70000076293945,"connectStart":186.70000076293945,"domainLookupEnd":186.70000076293945,"domainLookupStart":186.70000076293945,"fetchStart":186.70000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":186.70000076293945,"responseEnd":499.70000076293945,"responseStart":499.70000076293945,"secureConnectionStart":186.70000076293945},{"duration":318.5999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":186.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":186.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":505.5,"responseStart":0,"secureConnectionStart":0},{"duration":313.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":187,"connectEnd":187,"connectStart":187,"domainLookupEnd":187,"domainLookupStart":187,"fetchStart":187,"redirectEnd":0,"redirectStart":0,"requestStart":187,"responseEnd":500.5,"responseStart":500.5,"secureConnectionStart":187},{"duration":609.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":188.20000076293945,"connectEnd":188.20000076293945,"connectStart":188.20000076293945,"domainLookupEnd":188.20000076293945,"domainLookupStart":188.20000076293945,"fetchStart":188.20000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":188.20000076293945,"responseEnd":797.8000001907349,"responseStart":797.8000001907349,"secureConnectionStart":188.20000076293945},{"duration":825.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":188.30000019073486,"connectEnd":188.30000019073486,"connectStart":188.30000019073486,"domainLookupEnd":188.30000019073486,"domainLookupStart":188.30000019073486,"fetchStart":188.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":188.30000019073486,"responseEnd":1014.2000007629395,"responseStart":1014.2000007629395,"secureConnectionStart":188.30000019073486},{"duration":276.8999996185303,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":521.9000005722046,"connectEnd":521.9000005722046,"connectStart":521.9000005722046,"domainLookupEnd":521.9000005722046,"domainLookupStart":521.9000005722046,"fetchStart":521.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":521.9000005722046,"responseEnd":798.8000001907349,"responseStart":798.8000001907349,"secureConnectionStart":521.9000005722046},{"duration":254.39999961853027,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":831.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":831.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1086,"responseStart":0,"secureConnectionStart":0},{"duration":226.4000005722046,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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","startTime":859.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":859.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1086.2000007629395,"responseStart":0,"secureConnectionStart":0},{"duration":225.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/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","startTime":861.1000003814697,"connectEnd":861.1000003814697,"connectStart":861.1000003814697,"domainLookupEnd":861.1000003814697,"domainLookupStart":861.1000003814697,"fetchStart":861.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":861.1000003814697,"responseEnd":1086.7000007629395,"responseStart":1086.7000007629395,"secureConnectionStart":861.1000003814697},{"duration":230.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/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","startTime":861.6000003814697,"connectEnd":861.6000003814697,"connectStart":861.6000003814697,"domainLookupEnd":861.6000003814697,"domainLookupStart":861.6000003814697,"fetchStart":861.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":861.6000003814697,"responseEnd":1092.1000003814697,"responseStart":1092.1000003814697,"secureConnectionStart":861.6000003814697}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":10,"responseStart":164,"responseEnd":182,"domLoading":183,"domInteractive":1067,"domContentLoadedEventStart":1067,"domContentLoadedEventEnd":1135,"domComplete":1726,"loadEventStart":1726,"loadEventEnd":1727,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1045},{"name":"bigPipe.sidebar-id.end","time":1045.7000007629395},{"name":"bigPipe.activity-panel-pipe-id.start","time":1045.9000005722046},{"name":"bigPipe.activity-panel-pipe-id.end","time":1048.4000005722046},{"name":"activityTabFullyLoaded","time":1193.1000003814697}],"measures":[],"correlationId":"4d47b975aa223a","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":86,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}