1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# Setup
create table parent (
pk int primary key,
id1 int unique,
id2 int unique,
ref1 int,
ref2 int,
constraint fk_p1 foreign key ref1_idx(ref1) references parent (id1),
foreign key ref2_idx(ref2) references parent (id2)
) engine ndb;
# Verify the foreign keys on parent
SHOW CREATE TABLE test.parent;
Table Create Table
parent CREATE TABLE `parent` (
`pk` int NOT NULL,
`id1` int DEFAULT NULL,
`id2` int DEFAULT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
UNIQUE KEY `id1` (`id1`),
UNIQUE KEY `id2` (`id2`),
KEY `fk_p1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `fk_p1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`),
CONSTRAINT `parent_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
create table child (
pk int primary key,
ref1 int,
ref2 int,
constraint fk_c1 foreign key ref1_idx(ref1) references parent (id1),
foreign key ref2_idx(ref2) references parent (id2)
) engine ndb;
# Verify the foreign keys on child
SHOW CREATE TABLE test.child;
Table Create Table
child CREATE TABLE `child` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Drop foreign keys one by one and verify the other FKs integrity
alter table parent
drop foreign key fk_p1,
algorithm = inplace;
# Verify the foreign keys on parent and child
SHOW CREATE TABLE test.parent;
Table Create Table
parent CREATE TABLE `parent` (
`pk` int NOT NULL,
`id1` int DEFAULT NULL,
`id2` int DEFAULT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
UNIQUE KEY `id1` (`id1`),
UNIQUE KEY `id2` (`id2`),
KEY `fk_p1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `parent_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
SHOW CREATE TABLE test.child;
Table Create Table
child CREATE TABLE `child` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
alter table parent
drop foreign key parent_fk_1,
algorithm = inplace;
# Verify the foreign keys on parent and child
SHOW CREATE TABLE test.parent;
Table Create Table
parent CREATE TABLE `parent` (
`pk` int NOT NULL,
`id1` int DEFAULT NULL,
`id2` int DEFAULT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
UNIQUE KEY `id1` (`id1`),
UNIQUE KEY `id2` (`id2`),
KEY `fk_p1` (`ref1`),
KEY `ref2_idx` (`ref2`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
No foreign keys found on table `test.parent`
SHOW CREATE TABLE test.child;
Table Create Table
child CREATE TABLE `child` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
alter table child
drop foreign key fk_c1,
algorithm = inplace;
# Verify the foreign keys on child
SHOW CREATE TABLE test.child;
Table Create Table
child CREATE TABLE `child` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
alter table child
drop foreign key child_fk_1,
algorithm = inplace;
# Verify the foreign keys on child
SHOW CREATE TABLE test.child;
Table Create Table
child CREATE TABLE `child` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
No foreign keys found on table `test.child`
# Cleanup
drop table child, parent;
|