| 1 |
# Setup |
| 2 |
create table parent ( |
| 3 |
pk int primary key, |
| 4 |
id1 int unique, |
| 5 |
id2 int unique |
| 6 |
) engine ndb; |
| 7 |
create table child ( |
| 8 |
pk int primary key, |
| 9 |
ref1 int, |
| 10 |
ref2 int, |
| 11 |
foreign key ref1_idx(ref1) references parent (id1), |
| 12 |
foreign key ref2_idx(ref2) references parent (id2) |
| 13 |
) engine ndb; |
| 14 |
# Verify the foreign keys on child |
| 15 |
SHOW CREATE TABLE test.child; |
| 16 |
Table Create Table |
| 17 |
child CREATE TABLE `child` ( |
| 18 |
`pk` int NOT NULL, |
| 19 |
`ref1` int DEFAULT NULL, |
| 20 |
`ref2` int DEFAULT NULL, |
| 21 |
PRIMARY KEY (`pk`), |
| 22 |
KEY `ref1_idx` (`ref1`), |
| 23 |
KEY `ref2_idx` (`ref2`), |
| 24 |
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`), |
| 25 |
CONSTRAINT `child_fk_2` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`) |
| 26 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 27 |
Foreign keys consistent across NDB and all connected mysqld's DDs |
| 28 |
set debug='+d,ndb_simulate_failure_after_table_rename'; |
| 29 |
# Simple rename child should fail |
| 30 |
# and the foreign key names should remain the same |
| 31 |
rename table child to child1; |
| 32 |
ERROR HY000: Internal error: Simulated : Failed after renaming the table. |
| 33 |
# Verify the foreign keys on child |
| 34 |
SHOW CREATE TABLE test.child; |
| 35 |
Table Create Table |
| 36 |
child CREATE TABLE `child` ( |
| 37 |
`pk` int NOT NULL, |
| 38 |
`ref1` int DEFAULT NULL, |
| 39 |
`ref2` int DEFAULT NULL, |
| 40 |
PRIMARY KEY (`pk`), |
| 41 |
KEY `ref1_idx` (`ref1`), |
| 42 |
KEY `ref2_idx` (`ref2`), |
| 43 |
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`), |
| 44 |
CONSTRAINT `child_fk_2` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`) |
| 45 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 46 |
Foreign keys consistent across NDB and all connected mysqld's DDs |
| 47 |
set debug='+d,ndb_simulate_failure_after_table_rename'; |
| 48 |
# Rename using inplace alter should fail |
| 49 |
# and the foreign key names should remain the same |
| 50 |
alter table child rename to child1, algorithm = inplace; |
| 51 |
ERROR HY000: Internal error: Simulated : Failed after renaming the table. |
| 52 |
# Verify the foreign keys on child |
| 53 |
SHOW CREATE TABLE test.child; |
| 54 |
Table Create Table |
| 55 |
child CREATE TABLE `child` ( |
| 56 |
`pk` int NOT NULL, |
| 57 |
`ref1` int DEFAULT NULL, |
| 58 |
`ref2` int DEFAULT NULL, |
| 59 |
PRIMARY KEY (`pk`), |
| 60 |
KEY `ref1_idx` (`ref1`), |
| 61 |
KEY `ref2_idx` (`ref2`), |
| 62 |
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`), |
| 63 |
CONSTRAINT `child_fk_2` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`) |
| 64 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 65 |
Foreign keys consistent across NDB and all connected mysqld's DDs |
| 66 |
set debug='+d,ndb_simulate_failure_after_table_rename'; |
| 67 |
# Rename using copy alter should fail |
| 68 |
# and the foreign key names should remain the same |
| 69 |
alter table child rename to child1, algorithm = copy; |
| 70 |
ERROR HY000: Internal error: Simulated : Failed after renaming the table. |
| 71 |
# Verify the foreign keys on child |
| 72 |
SHOW CREATE TABLE test.child; |
| 73 |
Table Create Table |
| 74 |
child CREATE TABLE `child` ( |
| 75 |
`pk` int NOT NULL, |
| 76 |
`ref1` int DEFAULT NULL, |
| 77 |
`ref2` int DEFAULT NULL, |
| 78 |
PRIMARY KEY (`pk`), |
| 79 |
KEY `ref1_idx` (`ref1`), |
| 80 |
KEY `ref2_idx` (`ref2`), |
| 81 |
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`), |
| 82 |
CONSTRAINT `child_fk_2` FOREIGN KEY (`ref2`) REFERENCES `parent` (`id2`) |
| 83 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 84 |
Foreign keys consistent across NDB and all connected mysqld's DDs |
| 85 |
# Cleanup |
| 86 |
drop table child, parent; |