Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
YangKeao opened this issue Oct 15, 2024 · 0 comments · Fixed by #56661
Closed

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

YangKeao opened this issue Oct 15, 2024 · 0 comments · Fixed by #56661
Assignees
Labels
severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@YangKeao
Copy link
Member

YangKeao commented Oct 15, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant