Type:
Task
Priority:
Critical
Resolution:
Fixed
Add support of referential constraints directly in column defininions:
create table t1 (id1 int primary key );
create table t2 (id2 int references t1(id1));
Referenced field name can be omitted if equal to foreign field name:
create table t1 (id int primary key );
create table t2 (id int references t1);
Until 10.5 this syntax was understood by the parser but was silently
ignored.
In case of generated columns this syntax is disabled at parser level
by ER_PARSE_ERROR. Note that separate FOREIGN KEY clause for generated
columns is disabled at storage engine level.
From ISO/IEC 9075-2 (2016):
11.4 <column definition> (p. 842)
<column definition> ::=
<column name> [ <data type or domain name> ]
[ <default clause> | <identity column specification> | <generation clause>
| <system time period start column specification>
| <system time period end column specification> ]
[ <column constraint definition>... ]
...
<column constraint definition> ::=
[ <constraint name definition> ] <column constraint> [ <constraint characteristics> ]
<column constraint> ::=
NOT NULL
| <unique specification>
| <references specification>
| <check constraint definition>
11.8 <referential constraint definition> (p. 857)
<references specification> ::=
REFERENCES <referenced table and columns>
[ MATCH <match type> ] [ <referential triggered action> ]
<referenced table and columns> ::=
<table name> [ <left paren> <referenced column list>
[ <comma> <referenced period specification> ] <right paren> ]
Note
Currently this syntax is accepted but silently ignored.
Reproduce
create or replace table t1 (x int primary key );
create or replace table t2 (x int references t1(x));
show create table t2;
Result
+-------+---------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`x` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------+
Expected
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`x` int(11) DEFAULT NULL,
KEY `x` (`x`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
{"report":{"fcp":1057.9000005722046,"ttfb":222.10000038146973,"pageVisibility":"visible","entityId":79436,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"41e9acd2-9d56-430a-a71d-9ee5bf942f02","navigationType":0,"readyForUser":1151.6000003814697,"redirectCount":0,"resourceLoadedEnd":1352.6000003814697,"resourceLoadedStart":227.9000005722046,"resourceTiming":[{"duration":357.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":227.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":227.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":585.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":357.4000005722046,"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":228.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":228.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":585.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":366.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":228.30000019073486,"connectEnd":228.30000019073486,"connectStart":228.30000019073486,"domainLookupEnd":228.30000019073486,"domainLookupStart":228.30000019073486,"fetchStart":228.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":228.30000019073486,"responseEnd":594.9000005722046,"responseStart":594.9000005722046,"secureConnectionStart":228.30000019073486},{"duration":435.19999980926514,"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":228.5,"connectEnd":228.5,"connectStart":228.5,"domainLookupEnd":228.5,"domainLookupStart":228.5,"fetchStart":228.5,"redirectEnd":0,"redirectStart":0,"requestStart":228.5,"responseEnd":663.6999998092651,"responseStart":663.6999998092651,"secureConnectionStart":228.5},{"duration":438.79999923706055,"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":228.9000005722046,"connectEnd":228.9000005722046,"connectStart":228.9000005722046,"domainLookupEnd":228.9000005722046,"domainLookupStart":228.9000005722046,"fetchStart":228.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":228.9000005722046,"responseEnd":667.6999998092651,"responseStart":667.6999998092651,"secureConnectionStart":228.9000005722046},{"duration":439,"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":229.10000038146973,"connectEnd":229.10000038146973,"connectStart":229.10000038146973,"domainLookupEnd":229.10000038146973,"domainLookupStart":229.10000038146973,"fetchStart":229.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":229.10000038146973,"responseEnd":668.1000003814697,"responseStart":668.1000003814697,"secureConnectionStart":229.10000038146973},{"duration":439.20000076293945,"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":229.19999980926514,"connectEnd":229.19999980926514,"connectStart":229.19999980926514,"domainLookupEnd":229.19999980926514,"domainLookupStart":229.19999980926514,"fetchStart":229.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":229.19999980926514,"responseEnd":668.4000005722046,"responseStart":668.4000005722046,"secureConnectionStart":229.19999980926514},{"duration":510.29999923706055,"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":229.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":229.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":739.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":439.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":229.60000038146973,"connectEnd":229.60000038146973,"connectStart":229.60000038146973,"domainLookupEnd":229.60000038146973,"domainLookupStart":229.60000038146973,"fetchStart":229.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":229.60000038146973,"responseEnd":669,"responseStart":669,"secureConnectionStart":229.60000038146973},{"duration":510.20000076293945,"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":229.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":229.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":739.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":439.69999980926514,"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":229.80000019073486,"connectEnd":229.80000019073486,"connectStart":229.80000019073486,"domainLookupEnd":229.80000019073486,"domainLookupStart":229.80000019073486,"fetchStart":229.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":229.80000019073486,"responseEnd":669.5,"responseStart":669.5,"secureConnectionStart":229.80000019073486},{"duration":1100.6000003814697,"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":231.19999980926514,"connectEnd":231.19999980926514,"connectStart":231.19999980926514,"domainLookupEnd":231.19999980926514,"domainLookupStart":231.19999980926514,"fetchStart":231.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":231.19999980926514,"responseEnd":1331.8000001907349,"responseStart":1331.8000001907349,"secureConnectionStart":231.19999980926514},{"duration":1121.4000005722046,"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":231.19999980926514,"connectEnd":231.19999980926514,"connectStart":231.19999980926514,"domainLookupEnd":231.19999980926514,"domainLookupStart":231.19999980926514,"fetchStart":231.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":231.19999980926514,"responseEnd":1352.6000003814697,"responseStart":1352.6000003814697,"secureConnectionStart":231.19999980926514},{"duration":581.8999996185303,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":751.3000001907349,"connectEnd":751.3000001907349,"connectStart":751.3000001907349,"domainLookupEnd":751.3000001907349,"domainLookupStart":751.3000001907349,"fetchStart":751.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":751.3000001907349,"responseEnd":1333.1999998092651,"responseStart":1333.1999998092651,"secureConnectionStart":751.3000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":47,"responseStart":222,"responseEnd":225,"domLoading":226,"domInteractive":1374,"domContentLoadedEventStart":1374,"domContentLoadedEventEnd":1417,"domComplete":2533,"loadEventStart":2533,"loadEventEnd":2535,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1354.4000005722046},{"name":"bigPipe.sidebar-id.end","time":1355.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1355.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1357.6999998092651},{"name":"activityTabFullyLoaded","time":1425}],"measures":[],"correlationId":"3d885176726890","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":106,"dbReadsTimeInMs":12,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}