| 1 |
-- source include/have_innodb.inc |
| 2 |
|
| 3 |
# Check the replication of the FOREIGN_KEY_CHECKS variable. |
| 4 |
|
| 5 |
-- source include/master-slave.inc |
| 6 |
|
| 7 |
CREATE TABLE t1 (a INT AUTO_INCREMENT KEY) ENGINE=INNODB; |
| 8 |
CREATE TABLE t2 (b INT AUTO_INCREMENT KEY, c INT, FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=INNODB; |
| 9 |
|
| 10 |
SET FOREIGN_KEY_CHECKS=0; |
| 11 |
INSERT INTO t1 VALUES (10); |
| 12 |
INSERT INTO t1 VALUES (NULL),(NULL),(NULL); |
| 13 |
INSERT INTO t2 VALUES (5,0); |
| 14 |
INSERT INTO t2 VALUES (NULL,LAST_INSERT_ID()); |
| 15 |
SET FOREIGN_KEY_CHECKS=1; |
| 16 |
SELECT * FROM t1 ORDER BY a; |
| 17 |
SELECT * FROM t2 ORDER BY b; |
| 18 |
sync_slave_with_master; |
| 19 |
SELECT * FROM t1 ORDER BY a; |
| 20 |
SELECT * FROM t2 ORDER BY b; |
| 21 |
|
| 22 |
connection master; |
| 23 |
SET TIMESTAMP=1000000000; |
| 24 |
CREATE TABLE t3 ( a INT UNIQUE ); |
| 25 |
SET FOREIGN_KEY_CHECKS=0; |
| 26 |
--error ER_DUP_ENTRY |
| 27 |
INSERT INTO t3 VALUES (1),(1); |
| 28 |
sync_slave_with_master; |
| 29 |
|
| 30 |
connection master; |
| 31 |
SET FOREIGN_KEY_CHECKS=0; |
| 32 |
DROP TABLE IF EXISTS t1,t2,t3; |
| 33 |
SET FOREIGN_KEY_CHECKS=1; |
| 34 |
sync_slave_with_master; |
| 35 |
|
| 36 |
# |
| 37 |
# Bug #32468 delete rows event on a table with foreign key constraint fails |
| 38 |
# |
| 39 |
|
| 40 |
connection master; |
| 41 |
|
| 42 |
create table t1 (b int primary key) engine = INNODB; |
| 43 |
create table t2 (a int primary key, b int, foreign key (b) references t1(b)) engine = INNODB; |
| 44 |
|
| 45 |
insert into t1 set b=1; |
| 46 |
insert into t2 set a=1, b=1; |
| 47 |
|
| 48 |
set foreign_key_checks=0; |
| 49 |
delete from t1; |
| 50 |
|
| 51 |
--echo must sync w/o a problem (could not with the buggy code) |
| 52 |
sync_slave_with_master; |
| 53 |
select count(*) from t1 /* must be zero */; |
| 54 |
|
| 55 |
|
| 56 |
# cleanup for bug#32468 |
| 57 |
|
| 58 |
connection master; |
| 59 |
drop table t2,t1; |
| 60 |
set foreign_key_checks=1; |
| 61 |
|
| 62 |
--echo # |
| 63 |
--echo # MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails |
| 64 |
--echo # |
| 65 |
|
| 66 |
create table t1 (id int primary key)engine=innodb; |
| 67 |
create table t2 (id int not null primary key auto_increment, |
| 68 |
id2 int default null, key f1 (id2), |
| 69 |
constraint f1 foreign key (id2) references t1 (id) on delete cascade) engine=innodb; |
| 70 |
error ER_ROW_IS_REFERENCED_2; |
| 71 |
drop table t1,t2; |
| 72 |
sync_slave_with_master; |
| 73 |
show tables; |
| 74 |
connection master; |
| 75 |
drop table t1; |
| 76 |
sync_slave_with_master; |
| 77 |
|
| 78 |
--source include/rpl_end.inc |