| 1 |
--source include/have_ndb.inc |
| 2 |
--source include/have_multi_ndb.inc |
| 3 |
|
| 4 |
--connection server1 |
| 5 |
--echo #setup tables |
| 6 |
create table parent( |
| 7 |
a int unique, |
| 8 |
b int unique |
| 9 |
) engine ndb; |
| 10 |
insert into parent values (1, 2), (2, 1); |
| 11 |
create table child( |
| 12 |
ref int |
| 13 |
) engine ndb; |
| 14 |
|
| 15 |
--echo #Testing create FK, using copy algorithm |
| 16 |
let $ddl_query= alter table child add |
| 17 |
constraint fk1 foreign key(ref) references parent(a), |
| 18 |
algorithm = copy; |
| 19 |
let $expect_alter_failure= 1; |
| 20 |
--source ndb_fk_schema_dist_test_parent.inc |
| 21 |
|
| 22 |
--echo #Testing drop FK, using inplace algorithm |
| 23 |
let $ddl_query= alter table child drop foreign key fk1, algorithm=inplace; |
| 24 |
let $expect_alter_failure= 0; |
| 25 |
--source ndb_fk_schema_dist_test_parent.inc |
| 26 |
|
| 27 |
--echo #restore fk for further testing |
| 28 |
alter table child add constraint fk1 foreign key(ref) references parent(a); |
| 29 |
|
| 30 |
--echo #Testing drop child table |
| 31 |
let $ddl_query= drop table child; |
| 32 |
let $expect_alter_failure= 0; |
| 33 |
--source ndb_fk_schema_dist_test_parent.inc |
| 34 |
|
| 35 |
--echo #Testing create table |
| 36 |
let $ddl_query= create table child( |
| 37 |
ref int, |
| 38 |
constraint fk1 foreign key (ref) references parent(a) |
| 39 |
) engine ndb; |
| 40 |
let $expect_alter_failure= 1; |
| 41 |
--source ndb_fk_schema_dist_test_parent.inc |
| 42 |
|
| 43 |
--echo #Testing multiple alter FK create/drops : I |
| 44 |
let $ddl_query= alter table child |
| 45 |
drop foreign key fk1, |
| 46 |
add constraint fk2 foreign key (ref) references parent(b); |
| 47 |
let $expect_alter_failure= 0; |
| 48 |
--source ndb_fk_schema_dist_test_parent.inc |
| 49 |
|
| 50 |
--echo #setup for child referring multiple parents |
| 51 |
create table parent2( |
| 52 |
a int unique |
| 53 |
) engine ndb; |
| 54 |
show create table child; |
| 55 |
alter table child |
| 56 |
drop foreign key fk2, |
| 57 |
add constraint fk1 foreign key (ref) references parent(a); |
| 58 |
|
| 59 |
--echo #Testing multiple alter FK create/drops : II |
| 60 |
--echo #This also tests the fix for Bug#27646160 |
| 61 |
--echo #Also cache parent2 |
| 62 |
--connection server1 |
| 63 |
select * from parent2; |
| 64 |
let $ddl_query= alter table child |
| 65 |
drop foreign key fk1, |
| 66 |
add constraint fk2 foreign key (ref) references parent2(a); |
| 67 |
let $expect_alter_failure= 0; |
| 68 |
--source ndb_fk_schema_dist_test_parent.inc |
| 69 |
--echo #altering column in parent2 should fail with error |
| 70 |
flush tables parent2; |
| 71 |
--error ER_FK_INCOMPATIBLE_COLUMNS |
| 72 |
alter table parent2 |
| 73 |
change column a a varchar(64) not null; |
| 74 |
|
| 75 |
--echo #setup to test drop database |
| 76 |
drop table child; |
| 77 |
create database test1; |
| 78 |
create table test1.child( |
| 79 |
ref1 int, |
| 80 |
ref2 int, |
| 81 |
foreign key fk1(ref1) references test.parent(a), |
| 82 |
foreign key fk2(ref2) references test.parent2(a) |
| 83 |
) engine ndb; |
| 84 |
|
| 85 |
--echo #Testing drop database |
| 86 |
--echo #cache parent2 |
| 87 |
--connection server1 |
| 88 |
select * from parent2; |
| 89 |
let $ddl_query= drop database test1; |
| 90 |
let $expect_alter_failure= 0; |
| 91 |
--source ndb_fk_schema_dist_test_parent.inc |
| 92 |
--echo #altering column in parent2 should also pass |
| 93 |
flush tables parent2; |
| 94 |
alter table parent2 |
| 95 |
change column a a varchar(64) not null; |
| 96 |
|
| 97 |
--echo #cleanup |
| 98 |
drop table parent, parent2; |
| 99 |
|
| 100 |
--echo #setup to test mock table resolution |
| 101 |
--connection server1 |
| 102 |
set foreign_key_checks=0; |
| 103 |
|
| 104 |
create table child ( |
| 105 |
a int, |
| 106 |
foreign key fk1(a) references parent(a) |
| 107 |
) engine ndb; |
| 108 |
|
| 109 |
create table parent ( |
| 110 |
a int unique |
| 111 |
) engine ndb; |
| 112 |
insert into parent values (1), (2); |
| 113 |
|
| 114 |
set foreign_key_checks=1; |
| 115 |
|
| 116 |
--echo #Now drop child and test |
| 117 |
let $ddl_query= drop table child; |
| 118 |
let $expect_alter_failure= 0; |
| 119 |
--source ndb_fk_schema_dist_test_parent.inc |
| 120 |
|
| 121 |
--echo #cleanup |
| 122 |
drop table parent; |