-- source include/have_ndb.inc ### ### insert PK vs PK ### create table t1 ( a int not null, b int not null, c int not null, d int not null, e int not null, f int not null, primary key (a), unique(c) using hash, index(e)) engine = ndb; alter table t1 add constraint fkname foreign key (a) references t1(a) on delete restrict on update restrict; insert into t1 values (1,1,1,1,1,1); alter table t1 drop foreign key fkname; delete from t1; ### ### insert PK vs UK ### alter table t1 add constraint fkname foreign key (c) references t1(a) on delete restrict on update restrict; insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,3,3,2,2); alter table t1 drop foreign key fkname; delete from t1; ### ### insert PK vs OI ### alter table t1 add constraint fkname foreign key (e) references t1(a) on delete restrict on update restrict; insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,2,2,3,3); alter table t1 drop foreign key fkname; delete from t1; ### ### insert UK vs PK ### alter table t1 add constraint fkname foreign key (a) references t1(c) on delete restrict on update restrict; # # Bug#27930382 Foreign key constraint violations, false positive # (Manual tests 2018-06-13 indicates that innodb still has the same bug) # insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,3,3,2,2); alter table t1 drop foreign key fkname; delete from t1; ### ### insert UK vs UK ### alter table t1 add constraint fkname foreign key (c) references t1(c) on delete restrict on update restrict; # # Bug#27930382 Foreign key constraint violations, false positive # (Manual tests 2018-06-13 indicates that innodb still has the same bug) # insert into t1 values (1,1,1,1,1,1); alter table t1 drop foreign key fkname; delete from t1; ### ### insert UK vs OI ### alter table t1 add constraint fkname foreign key (e) references t1(c) on delete restrict on update restrict; # # Bug#27930382 Foreign key constraint violations, false positive # (Manual tests 2018-06-13 indicates that innodb still has the same bug) # insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,2,2,3,3); alter table t1 drop foreign key fkname; delete from t1; drop table t1; ### ### insert PK vs PK ### create table t1 ( a int not null, b int not null, c int not null, d int not null, e int not null, f int not null, primary key (a,b), unique(c,d) using hash, index(e,f)) engine = ndb; alter table t1 add constraint fkname foreign key (a,b) references t1(a,b) on delete no action on update no action; insert into t1 values (1,1,1,1,1,1); alter table t1 drop foreign key fkname; delete from t1; ### ### insert PK vs UK ### alter table t1 add constraint fkname foreign key (c,d) references t1(a,b) on delete no action on update no action; insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,3,3,2,2); alter table t1 drop foreign key fkname; delete from t1; ### ### insert PK vs OI ### alter table t1 add constraint fkname foreign key (e,f) references t1(a,b) on delete no action on update no action; insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,2,2,3,3); alter table t1 drop foreign key fkname; delete from t1; ### ### insert UK vs PK ### alter table t1 add constraint fkname foreign key (a,b) references t1(c,d) on delete no action on update no action; insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,3,3,2,2); alter table t1 drop foreign key fkname; delete from t1; ### ### insert UK vs UK ### alter table t1 add constraint fkname foreign key (c,d) references t1(c,d) on delete no action on update no action; insert into t1 values (1,1,1,1,1,1); alter table t1 drop foreign key fkname; delete from t1; ### ### insert UK vs OI ### alter table t1 add constraint fkname foreign key (e,f) references t1(c,d) on delete no action on update no action; insert into t1 values (1,1,1,1,1,1); --error 1452 insert into t1 values (2,2,2,2,3,3); alter table t1 drop foreign key fkname; delete from t1; drop table t1; --echo # --echo # Truncating table with self referencing Foreign key --echo # create table t2 ( pk2 int not null primary key, c int, foreign key (c) references t2(pk2) ) engine=NDB; --let $ndb_table_name=t2 --let $ndb_self_ref=1 --source print_foreign_keys.inc truncate table t2; --echo Verify all the foreign key are re-created after truncate --let $ndb_table_name=t2 --let $ndb_self_ref=1 --source print_foreign_keys.inc --disable_warnings show create table t2; --enable_warnings drop table t2;