-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDEV-19191 Partial support of foreign keys in partitioned tables #3641
base: main
Are you sure you want to change the base?
Changes from all commits
07e23fc
dbdade6
1c2c7e7
ae7010d
0681985
0e5c3e4
7d6cb82
82dc524
af4a999
c20afce
7d42eee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,10 +245,9 @@ KEY parent_id (parent_id) | |
) ENGINE=InnoDB; | ||
ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 1; | ||
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id); | ||
ERROR HY000: Partitioned tables do not support FOREIGN KEY | ||
ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 2; | ||
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id); | ||
ERROR HY000: Partitioned tables do not support FOREIGN KEY | ||
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") | ||
Comment on lines
247
to
+250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message looks incorrect here. Shouldn’t this fail because a duplicate constraint name |
||
DROP TABLE t1, t2; | ||
create table t1 (a varchar(5), b int signed, c varchar(10), d datetime) | ||
partition by range columns(b,c) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,12 +237,11 @@ CREATE TABLE t1 ( | |
|
||
ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 1; | ||
|
||
--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING | ||
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id); | ||
|
||
ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 2; | ||
|
||
--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING | ||
--error ER_CANT_CREATE_TABLE | ||
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id); | ||
|
||
DROP TABLE t1, t2; | ||
Comment on lines
-240
to
247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some functional testing with DML statements is needed here to demonstrate that the Please also add a comment here that there are further tests about this in |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- foreign_null.result | ||
+++ foreign_null,COPY.result | ||
+++ foreign_null,COPY.reject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this line changed? |
||
@@ -139,6 +139,7 @@ | ||
ALTER TABLE `t#2` DROP INDEX f1; | ||
SET FOREIGN_KEY_CHECKS=1; | ||
|
@@ -12,7 +12,7 @@ | |
ALTER TABLE `t#1` DROP INDEX f2; | ||
SET FOREIGN_KEY_CHECKS=1; | ||
ALTER TABLE `t#2` MODIFY COLUMN f1 INT NOT NULL; | ||
+ERROR HY000: Error on rename of './test/#sql-alter' to './test/t@00232' (errno: 150 "Foreign key constraint is incorrectly formed") | ||
+ERROR HY000: Can't create table `test`.`t#2` (errno: 150 "Foreign key constraint is incorrectly formed") | ||
DROP TABLE `t#2`, `t#1`; | ||
# Self referential modifying column | ||
CREATE TABLE t1(f1 INT, f2 INT, index(f2), foreign key(f1) references t1(f2) ON UPDATE CASCADE)engine=innodb; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,7 +509,7 @@ t4 CREATE TABLE `t4` ( | |
CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
alter table t3 add constraint dc foreign key (a) references t1(a); | ||
ERROR HY000: Can't create table `test`.`t3` (errno: 121 "Duplicate key on write or update") | ||
ERROR HY000: Duplicate constraint name | ||
Comment on lines
511
to
+512
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message fails to include the duplicate constraint name |
||
SET FOREIGN_KEY_CHECKS=0; | ||
alter table t3 add constraint dc foreign key (a) references t1(a); | ||
ERROR HY000: Failed to add the foreign key constraint 'test/dc' to system tables | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,20 +25,43 @@ CREATE TABLE t (a INT PRIMARY KEY) ENGINE=InnoDB; | |
# corresponding to the 51 characters below: 5*51=255. | ||
let $d255=###################################################; | ||
let $d250=##################################################; | ||
let $d245=#####################; | ||
# FIXME: MDEV-29258 | ||
# let $d245=#################################################; | ||
--replace_result $d255 d255 | ||
eval CREATE DATABASE `$d255`; | ||
|
||
--replace_result $d255 d255 | ||
--error ER_IDENT_CAUSES_TOO_LONG_PATH | ||
eval CREATE TABLE `$d255`.`$d255` | ||
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB; | ||
|
||
--replace_result $d255 d255 | ||
--error ER_IDENT_CAUSES_TOO_LONG_PATH | ||
eval CREATE OR REPLACE TABLE `$d255`.`$d255` | ||
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB; | ||
|
||
--replace_result $d255 d255 | ||
--error ER_IDENT_CAUSES_TOO_LONG_PATH | ||
eval CREATE TABLE `$d255`.`_$d250` | ||
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB; | ||
|
||
--replace_result $d255 d255 | ||
--error ER_IDENT_CAUSES_TOO_LONG_PATH | ||
eval CREATE OR REPLACE TABLE `$d255`.`_$d250` | ||
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB; | ||
|
||
--replace_result $d255 d255 | ||
eval CREATE TABLE `$d255`.`$d250` | ||
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB; | ||
|
||
--replace_result $d255 d255 $d245 d245 | ||
eval CREATE OR REPLACE TABLE `$d255`.`$d245` | ||
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB; | ||
|
||
--replace_result $d255 d255 $d245 d245 | ||
eval DROP TABLE `$d255`.`$d245`; | ||
|
||
--echo # | ||
--echo # MDEV-29258 Failing assertion for name length on RENAME TABLE | ||
--echo # | ||
|
@@ -53,7 +76,6 @@ eval DROP TABLE `$d255`.`$d250`; | |
eval RENAME TABLE `$d255`.`$d245` TO `$d255`.`$d250`; | ||
--replace_result $d250 d250 $d255 d255 | ||
eval RENAME TABLE `$d255`.`$d250` TO a; | ||
--replace_result $d255 d255 | ||
DROP TABLE a,t; | ||
|
||
--echo # | ||
|
@@ -75,3 +97,26 @@ DROP TABLE u; | |
eval DROP DATABASE `$d255`; | ||
|
||
--echo # End of 10.3 tests | ||
|
||
--echo # | ||
--echo # MDEV-28933 CREATE OR REPLACE fails to recreate same constraint name | ||
--echo # | ||
set names utf8; | ||
let $d= `select repeat('❎', 45)`; | ||
let $t= `select repeat('❎', 64)`; | ||
eval create database `$d`; | ||
eval use `$d`; | ||
create table t (a int primary key) engine=innodb; | ||
eval create table u ( | ||
a int primary key, | ||
constraint `$t` foreign key d (a) references t (a)) engine=innodb; | ||
select * from information_schema.innodb_sys_foreign; | ||
select * from information_schema.innodb_sys_foreign_cols; | ||
eval create or replace table u ( | ||
a int primary key, | ||
constraint `$t` foreign key d (a) references t (a)) engine=innodb; | ||
select * from information_schema.innodb_sys_foreign; | ||
select * from information_schema.innodb_sys_foreign_cols; | ||
show create table u; | ||
use test; | ||
eval drop database `$d`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not sufficient to demonstrate that the table can be created. Some functional testing is needed as well, to demonstrate that the foreign keys actually work.
Given that this test uses
ENGINE=MyISAM
andFOREIGN KEY
constraints are currently implemented only inENGINE=InnoDB
, this test seem to demonstrate that things are changing for the worse. We’d allow a DDL operation that was previously rejected because it was known not to work. I don’t think that this change is acceptable.