1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-23470 InnoDB: Failing assertion: cmp < 0 in row_ins_check_foreign_constraint

During insertion of clustered index, InnoDB does the check for foreign key
constraints. Problem is that it uses the clustered index entry to search
indexes of referenced tables and it could lead to unexpected result
when there is no foreign index.

Solution:
========
  Rebuild the tuple based on foreign column names before searching it
on reference index when there is no foreign index.
This commit is contained in:
Thirunarayanan Balathandayuthapani
2020-09-02 16:15:02 +05:30
parent 054f96ecff
commit 837bbbafc5
3 changed files with 100 additions and 9 deletions

View File

@ -220,3 +220,19 @@ drop table t1,t2;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
drop table t1,t2;
ERROR 42S02: Unknown table 'test.t2'
#
# MDEV-23470 InnoDB: Failing assertion: cmp < 0 in
# row_ins_check_foreign_constraint
#
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB;
CREATE TABLE t2(f1 VARCHAR(100), f2 INT NOT NULL,
INDEX(f2))ENGINE=InnoDB;
INSERT INTO t1 VALUES(99, 2);
ALTER TABLE t2 ADD FOREIGN KEY(f2) REFERENCES t1(f1);
SET FOREIGN_KEY_CHECKS=0;
DROP INDEX f2 ON t2;
SET FOREIGN_KEY_CHECKS=1;
INSERT INTO t2 VALUES('G', 3);
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`))
DROP TABLE t2, t1;
SET FOREIGN_KEY_CHECKS=DEFAULT;

View File

@ -250,3 +250,22 @@ show create table t2;
drop table t1,t2;
--error ER_BAD_TABLE_ERROR
drop table t1,t2;
--echo #
--echo # MDEV-23470 InnoDB: Failing assertion: cmp < 0 in
--echo # row_ins_check_foreign_constraint
--echo #
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB;
CREATE TABLE t2(f1 VARCHAR(100), f2 INT NOT NULL,
INDEX(f2))ENGINE=InnoDB;
INSERT INTO t1 VALUES(99, 2);
ALTER TABLE t2 ADD FOREIGN KEY(f2) REFERENCES t1(f1);
SET FOREIGN_KEY_CHECKS=0;
DROP INDEX f2 ON t2;
SET FOREIGN_KEY_CHECKS=1;
--error ER_NO_REFERENCED_ROW_2
INSERT INTO t2 VALUES('G', 3);
DROP TABLE t2, t1;
SET FOREIGN_KEY_CHECKS=DEFAULT;