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
|
# Setup
create table parent (
pk int primary key,
id1 int unique,
id2 int unique
) engine ndb;
create table child (
pk int primary key,
ref1 int,
ref2 int,
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 `ref1_idx` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`),
CONSTRAINT `child_fk_2` 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
set debug='+d,ndb_simulate_failure_after_table_rename';
# Simple rename child should fail
# and the foreign key names should remain the same
rename table child to child1;
ERROR HY000: Internal error: Simulated : Failed after renaming the table.
# 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 `ref1_idx` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`),
CONSTRAINT `child_fk_2` 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
set debug='+d,ndb_simulate_failure_after_table_rename';
# Rename using inplace alter should fail
# and the foreign key names should remain the same
alter table child rename to child1, algorithm = inplace;
ERROR HY000: Internal error: Simulated : Failed after renaming the table.
# 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 `ref1_idx` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`),
CONSTRAINT `child_fk_2` 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
set debug='+d,ndb_simulate_failure_after_table_rename';
# Rename using copy alter should fail
# and the foreign key names should remain the same
alter table child rename to child1, algorithm = copy;
ERROR HY000: Internal error: Simulated : Failed after renaming the table.
# 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 `ref1_idx` (`ref1`),
KEY `ref2_idx` (`ref2`),
CONSTRAINT `child_fk_1` FOREIGN KEY (`ref1`) REFERENCES `parent` (`id1`),
CONSTRAINT `child_fk_2` 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
# Cleanup
drop table child, parent;
|