matrixorigin / matrixorigin/matrixone
[Bug]: Self-Referencing Foreign Key DELETE Causes Deadlock
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
### Is there an existing issue for the same bug?
- [x] I have checked the existing issues.
### Branch Name
main,3.0-dev
### Commit ID
latest
### Other Environment Information
```Markdown
- Hardware parameters:
- OS type:
- Others:
```
### Actual Behavior
When deleting a row from a table with self-referencing foreign key constraint (`ON DELETE SET NULL`), the DELETE operation **hangs indefinitely** and never completes.
The DELETE operation **hangs indefinitely**:
```
mysql> DELETE FROM t WHERE id = 2;
^C^C^C -- Ctrl-C doesn't work
-- Need to kill the connection
```
### Expected Behavior
The DELETE should:
1. Delete the row with `id = 2`
2. Set `parent_id = NULL` for row with `id = 3` (because it references deleted row)
3. Complete successfully
### Steps to Reproduce
```Markdown
DROP DATABASE IF EXISTS test_fk_self_minimal;
CREATE DATABASE test_fk_self_minimal;
USE test_fk_self_minimal;
-- Create self-referencing table
CREATE TABLE t (
id INT PRIMARY KEY,
parent_id INT,
FOREIGN KEY (parent_id) REFERENCES t(id) ON DELETE SET NULL
);
-- Insert hierarchy
INSERT INTO t VALUES (1, NULL); -- Top level
INSERT INTO t VALUES (2, 1); -- Child of 1
INSERT INTO t VALUES (3, 2); -- Child of 2
-- THIS OPERATION HANGS
DELETE FROM t WHERE id = 2;
```
### Additional information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.