summaryrefslogtreecommitdiff
path: root/mysql-test/suite/versioning
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2018-05-30 13:19:03 +0300
committerAleksey Midenkov <midenok@gmail.com>2019-10-10 00:20:34 +0300
commit75ba5c815d0272b35a28225d495a4a03fe63d29f (patch)
treeaac71c2c74e9130a2e8ae16ba9e979ff04905d89 /mysql-test/suite/versioning
parent6684989801cd0e93be5646716bb3cffedd271ce6 (diff)
downloadmariadb-git-75ba5c815d0272b35a28225d495a4a03fe63d29f.tar.gz
MDEV-16210 FK constraints on versioned tables use historical rows, which may cause constraint violation
Constraint check is done on secondary index update. F.ex. DELETE does row_upd_sec_index_entry() and checks constraints in row_upd_check_references_constraints(). UPDATE is optimized for the case when order is not changed (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE) and doesn't do row_upd_sec_index_entry(), so it doesn't check constraints. Since for versioned DELETE we do UPDATE actually, but expect behaviour of DELETE in terms of constraints, we should deny this optimization to get constraints checked. Fix wrong referenced table check when versioned DELETE inserts history in parent table. Set check_ref to false in this case. Removed unused dup_chk_only argument for row_ins_sec_index_entry() and added check_ref argument. MDEV-18057 fix was superseded by this fix and reverted. foreign.test: All key_type combinations: pk, unique, sec(ondary).
Diffstat (limited to 'mysql-test/suite/versioning')
-rw-r--r--mysql-test/suite/versioning/r/foreign.result19
-rw-r--r--mysql-test/suite/versioning/t/foreign.test23
2 files changed, 23 insertions, 19 deletions
diff --git a/mysql-test/suite/versioning/r/foreign.result b/mysql-test/suite/versioning/r/foreign.result
index e5ffb6c5f0c..6a9746b62e2 100644
--- a/mysql-test/suite/versioning/r/foreign.result
+++ b/mysql-test/suite/versioning/r/foreign.result
@@ -298,15 +298,18 @@ select count(*) from subchild;
count(*)
0
drop table subchild, child, parent;
-CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=InnoDB;
-CREATE TABLE t2 (f2 INT, FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=InnoDB WITH SYSTEM VERSIONING;
-SET FOREIGN_KEY_CHECKS= OFF;
-INSERT IGNORE INTO t2 VALUES (1);
-SET FOREIGN_KEY_CHECKS= ON;
-UPDATE t2 SET f2= 2;
+#
+# MDEV-18057 Assertion `(node->state == 5) || (node->state == 6)' failed in row_upd_sec_step upon DELETE after UPDATE failed due to FK violation
+#
+create or replace table t1 (f1 int, key(f1)) engine=innodb;
+create or replace table t2 (f2 int, foreign key (f2) references t1 (f1)) engine=innodb with system versioning;
+set foreign_key_checks= off;
+insert ignore into t2 values (1);
+set foreign_key_checks= on;
+update t2 set f2= 2;
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`))
-DELETE FROM t2;
-DROP TABLE t2, t1;
+delete from t2;
+drop table t2, t1;
#
# MDEV-18879 Corrupted record inserted by FOREIGN KEY operation
#
diff --git a/mysql-test/suite/versioning/t/foreign.test b/mysql-test/suite/versioning/t/foreign.test
index d60172f99bc..9f015630e0a 100644
--- a/mysql-test/suite/versioning/t/foreign.test
+++ b/mysql-test/suite/versioning/t/foreign.test
@@ -1,7 +1,6 @@
+--source suite/versioning/key_type.inc
--source suite/versioning/common.inc
-let $KEY_TYPE= primary key;
-
--echo #################
--echo # Test RESTRICT #
--echo #################
@@ -331,19 +330,21 @@ select count(*) from subchild;
drop table subchild, child, parent;
+--echo #
+--echo # MDEV-18057 Assertion `(node->state == 5) || (node->state == 6)' failed in row_upd_sec_step upon DELETE after UPDATE failed due to FK violation
+--echo #
+create or replace table t1 (f1 int, key(f1)) engine=innodb;
+create or replace table t2 (f2 int, foreign key (f2) references t1 (f1)) engine=innodb with system versioning;
-CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=InnoDB;
-CREATE TABLE t2 (f2 INT, FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=InnoDB WITH SYSTEM VERSIONING;
-
-SET FOREIGN_KEY_CHECKS= OFF;
-INSERT IGNORE INTO t2 VALUES (1);
+set foreign_key_checks= off;
+insert ignore into t2 values (1);
-SET FOREIGN_KEY_CHECKS= ON;
+set foreign_key_checks= on;
--error ER_NO_REFERENCED_ROW_2
-UPDATE t2 SET f2= 2;
-DELETE FROM t2;
+update t2 set f2= 2;
+delete from t2;
-DROP TABLE t2, t1;
+drop table t2, t1;
--echo #
--echo # MDEV-18879 Corrupted record inserted by FOREIGN KEY operation