Skip to content

INSERT IGNORE didn't lock the referenced row in parent table #56655

@YangKeao

Description

@YangKeao

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Prepare:

create table parent (id int primary key);
create table child(id int primary key, ref int, foreign key (ref) references parent(id));

insert into parent values (1);

Execute:

Transaction 1 Transaction 2
BEGIN; BEGIN;
INSERT IGNORE INTO child VALUES (1, 1);
UPDATE parent SET id = 2 WHERE id = 1
COMMIT;
COMMIT;

2. What did you expect to see? (Required)

The statement UPDATE in transaction 2 is blocked until the transaction 1 COMMIT, and it will finally return an error.

3. What did you see instead (Required)

Both transactions are not blocked. The constraint is broken:

Then the constraint is not consistent:

mysql> select * from parent;
+----+
| id |
+----+
|  2 |
+----+
1 row in set (0.00 sec)

mysql> select * from child;
+----+------+
| id | ref  |
+----+------+
|  1 |    1 |
+----+------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                  |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.4.0-this-is-a-placeholder
Edition: Community
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.23.0
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions