123 lines
3.3 KiB
Plaintext
123 lines
3.3 KiB
Plaintext
-- source include/have_ndb.inc
|
|
|
|
connect (con1,localhost,root,,test);
|
|
connect (con2,localhost,root,,test);
|
|
|
|
###
|
|
### PK vs PK
|
|
###
|
|
create table parent (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key (a,b),
|
|
unique(b,c) using hash,
|
|
index(c,a)) engine = ndb;
|
|
|
|
create table child (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key (b,a),
|
|
unique(c,b) using hash,
|
|
index(c,a)) engine = ndb;
|
|
|
|
insert into parent values (1,2,3);
|
|
|
|
alter table child add constraint fkname foreign key (c,a) references parent(a,b) on delete restrict on update restrict;
|
|
|
|
--error ER_NO_REFERENCED_ROW_2
|
|
insert into child values (2,1,2);
|
|
--error ER_NO_REFERENCED_ROW_2
|
|
insert into child values (1,1,1);
|
|
|
|
insert into child values (2,1,1);
|
|
--error ER_ROW_IS_REFERENCED_2
|
|
delete from parent;
|
|
|
|
delete from child;
|
|
alter table child drop foreign key fkname;
|
|
|
|
alter table child add constraint fkname foreign key (b,a) references parent(a,b) on delete restrict on update restrict;
|
|
|
|
--error ER_NO_REFERENCED_ROW_2
|
|
insert into child values (1,2,2);
|
|
--error ER_NO_REFERENCED_ROW_2
|
|
insert into child values (2,3,1);
|
|
|
|
insert into child values (2,1,1);
|
|
--error ER_ROW_IS_REFERENCED_2
|
|
delete from parent;
|
|
|
|
delete from child;
|
|
alter table child drop foreign key fkname;
|
|
|
|
alter table child add constraint fkname foreign key (c,b) references parent(a,b) on delete restrict on update restrict;
|
|
|
|
--error ER_NO_REFERENCED_ROW_2
|
|
insert into child values (1,2,2);
|
|
--error ER_NO_REFERENCED_ROW_2
|
|
insert into child values (2,3,1);
|
|
|
|
insert into child values (2,2,1);
|
|
--error ER_ROW_IS_REFERENCED_2
|
|
delete from parent;
|
|
|
|
drop table child, parent;
|
|
|
|
--echo #
|
|
--echo # Bug#21664899 : FAILURE CREATING COMPOSITE FKS REFERENCING COMPOSITE PKS OF PARENT
|
|
--echo #
|
|
|
|
--echo #create table t1
|
|
create table t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key pk1(a,b)
|
|
) engine=ndbcluster;
|
|
|
|
--echo #create t2 with a unique key on single column
|
|
create table t2 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
unique key uniquet2a(a),
|
|
constraint fkt2ab foreign key (a,b) references t1(a,b)
|
|
) engine=ndbcluster;
|
|
|
|
--echo #verify the presence of uniquet2a, fkt2ab & and an extra key for fkt2ab
|
|
--disable_warnings
|
|
show create table t2;
|
|
--enable_warnings
|
|
alter table t2 drop key uniquet2a;
|
|
|
|
--echo #alter add a unique constraint on single key
|
|
alter table t2 add constraint uniquet2a unique (a);
|
|
--echo #verify the presence of uniquet2a, fkt2ab & and an extra key for fkt2ab
|
|
--disable_warnings
|
|
show create table t2;
|
|
--enable_warnings
|
|
|
|
--echo #alter add a unique constraint on all cols in fk
|
|
alter table t2 add constraint uniquet2ab unique (a,b);
|
|
--echo #verify the presence of uniquet2a, uniquet2ab, fkt2ab. no extra key for fkt2ab
|
|
--disable_warnings
|
|
show create table t2;
|
|
--enable_warnings
|
|
|
|
--echo #try adding fk(a,b,c) referring t1(a,b,c), it should fail without parent index.
|
|
--error ER_FK_NO_INDEX_PARENT
|
|
alter table t2 add constraint fkt2abc foreign key (a,b,c) references t1(a,b,c);
|
|
|
|
--echo #now add a unique key but on a different column order and try again
|
|
alter table t1 add constraint uniquet1abc unique (c,a,b);
|
|
alter table t2 add constraint fkt2abc foreign key (a,b,c) references t1(a,b,c);
|
|
--echo #verify the presence of new fk
|
|
--disable_warnings
|
|
show create table t2;
|
|
--enable_warnings
|
|
|
|
--echo #cleanup
|
|
drop table t2, t1;
|