TiDB v8.5 can not detect the dead lock
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```sql
drop table if exists table1;
create table table1(id int primary key, a int);
insert into table1(id, a) values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
```
| T1 | T2 | Result |
| :------------------------------------------------ | :------------------------------------------ | :----------------------------------------------------------- |
| begin; | | ok |
| | begin; | ok |
| update table1 set a = 10 where id = 1; | | ok |
| | insert into table1 values (9, 9); | ok |
| | update table1 set a = 8 where id = 1; | waiting... |
| select id, a from table1 where id > 5 for update; | | ok |
| -- wait for 1min | -- T2 return error, but not dead lock found. | [40001][1205] Lock wait timeout exceeded; try restarting transaction |
| commit; | | ok |
| | commit; | ok |
The update in T2 and the first update in T1 form a WW dependency;
At the same time, the select for update in T1 and the insert in T2 also form a WW dependency.
Therefore, the deadlock that should have occurred was not detected by TiDB.
In contrast, MySQL can correctly detect the deadlock.
### 2. What did you expect to see? (Required)
```sql
mysql> update table1 set a = 8 where id = 1; -- when T1 execute select statement, T2 immediately return
[40001][1213] Deadlock found when trying to get lock; try restarting transaction
```
MySQL v8.4 can correctly detect the deadlock, and rollback the transaction automatically.
### 3. What did you see instead (Required)
```sql
mysql> update table1 set a = 8 where id = 1; -- after 50s
[40001][1205] Lock wait timeout exceeded; try restarting transaction
```
TiDB v8.5.0 can't detect the dead lock, and do not rollback the transaction automatically.
### 4. What is your TiDB version? (Required)
TiDB v8.5.0
```sql
Release Version: v8.5.0
Edition: Community
Git Commit Hash: d13e52ed6e22cc5789bed7c64c861578cd2ed55b
Git Branch: HEAD
UTC Build Time: 2024-12-18 02:26:06
GoVersion: go1.23.3
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```
Contributor guide
Assessment
This issue has not been assessed yet.