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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
# 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;
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 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 `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
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
# Simple rename parent
rename table parent to parent1;
# Verify the foreign keys on parent and child
SHOW CREATE TABLE test.parent1;
Table Create Table
parent1 CREATE TABLE `parent1` (
`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 `parent1` (`id1`),
CONSTRAINT `parent1_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent1` (`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 `parent1` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent1` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Rename parent using copy algorithm
alter table parent1 rename to parent2, algorithm = copy;
# Verify the foreign keys on parent and child
SHOW CREATE TABLE test.parent2;
Table Create Table
parent2 CREATE TABLE `parent2` (
`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 `parent2` (`id1`),
CONSTRAINT `parent2_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent2` (`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 `parent2` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent2` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Rename parent using inplace algorithm
alter table parent2 rename to parent3, algorithm = inplace;
# Verify the foreign keys on parent and child
SHOW CREATE TABLE test.parent3;
Table Create Table
parent3 CREATE TABLE `parent3` (
`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 `parent3` (`id1`),
CONSTRAINT `parent3_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent3` (`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 `parent3` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent3` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Simple rename child
rename table child to child1;
# Verify the foreign keys on child
SHOW CREATE TABLE test.child1;
Table Create Table
child1 CREATE TABLE `child1` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child1_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent3` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent3` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Rename child using copy algorithm
alter table child1 rename to child2, algorithm = copy;
# Verify the foreign keys on child
SHOW CREATE TABLE test.child2;
Table Create Table
child2 CREATE TABLE `child2` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child2_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent3` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent3` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Rename child using inplace algorithm
alter table child2 rename to child3, algorithm = inplace;
# Verify the foreign keys on child
SHOW CREATE TABLE test.child3;
Table Create Table
child3 CREATE TABLE `child3` (
`pk` int NOT NULL,
`ref1` int DEFAULT NULL,
`ref2` int DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `fk_c1` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child3_fk_1` FOREIGN KEY (`ref2`) REFERENCES `parent3` (`id2`),
CONSTRAINT `fk_c1` FOREIGN KEY (`ref1`) REFERENCES `parent3` (`id1`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Foreign keys consistent across NDB and all connected mysqld's DDs
# Cleanup
drop table child3, parent3;
|