mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 11:01:52 +01:00
a6066e230e
- Adding lock_wait_timeout value as 1 make sure that truncate table fails instead of making MDL timeout.
59 lines
2 KiB
Text
59 lines
2 KiB
Text
CREATE TABLE parent (a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
INSERT INTO parent SET a=1;
|
|
CREATE TABLE child (a INT PRIMARY KEY, FOREIGN KEY (a) REFERENCES parent(a)
|
|
ON UPDATE CASCADE)
|
|
ENGINE=InnoDB;
|
|
INSERT INTO child SET a=1;
|
|
TRUNCATE TABLE parent;
|
|
ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`))
|
|
TRUNCATE TABLE child;
|
|
INSERT INTO child SET a=1;
|
|
UPDATE parent SET a=2;
|
|
SELECT * FROM child;
|
|
a
|
|
2
|
|
connect dml,localhost,root;
|
|
SET DEBUG_SYNC='foreign_constraint_update_cascade SIGNAL fk WAIT_FOR go';
|
|
UPDATE parent SET a=3;
|
|
connection default;
|
|
SET DEBUG_SYNC='now WAIT_FOR fk';
|
|
SET lock_wait_timeout=1;
|
|
TRUNCATE TABLE child;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
SET DEBUG_SYNC='now SIGNAL go';
|
|
connection dml;
|
|
SELECT * FROM child;
|
|
a
|
|
3
|
|
SET DEBUG_SYNC='foreign_constraint_check_for_update SIGNAL fk WAIT_FOR go';
|
|
DELETE FROM parent;
|
|
connection default;
|
|
SET DEBUG_SYNC='now WAIT_FOR fk';
|
|
SET lock_wait_timeout=1;
|
|
TRUNCATE TABLE child;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
SET DEBUG_SYNC='now SIGNAL go';
|
|
connection dml;
|
|
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON UPDATE CASCADE)
|
|
SELECT * FROM child;
|
|
a
|
|
3
|
|
INSERT INTO parent SET a=5;
|
|
SET DEBUG_SYNC='foreign_constraint_check_for_ins SIGNAL fk WAIT_FOR go';
|
|
INSERT INTO child SET a=5;
|
|
connection default;
|
|
SET DEBUG_SYNC='now WAIT_FOR fk';
|
|
SET foreign_key_checks=0;
|
|
TRUNCATE TABLE parent;
|
|
SET DEBUG_SYNC='now SIGNAL go';
|
|
connection dml;
|
|
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON UPDATE CASCADE)
|
|
SELECT * FROM parent;
|
|
a
|
|
SELECT * FROM child;
|
|
a
|
|
3
|
|
disconnect dml;
|
|
connection default;
|
|
SET DEBUG_SYNC = RESET;
|
|
DROP TABLE child, parent;
|