pingcap / pingcap/tidb

select for update statement does not collect all keys need to be locked

Open
#45,533 3 comments 0 reactions 0 assignees View on GitHub
sig/transaction type/compatibility type/question
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
CREATE TABLE `test_deadlock` (
`id` varchar(36) NOT NULL,
`first` int(11) NOT NULL,
`second` int(11) NOT NULL,
`data` int(11) NOT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] NONCLUSTERED */,
UNIQUE KEY `uk_first_second` (`first`,`second`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=6 */;

INSERT INTO `test_deadlock` VALUES ('test', 1, 2, RAND() * 1000);

# Connection 1
START TRANSACTION;
SELECT * FROM `test_deadlock` WHERE `first` = 1 AND `second` = 2 FOR UPDATE;

# Connection 2
START TRANSACTION;
SELECT * FROM `test_deadlock` WHERE `id` = 'test' FOR UPDATE;

# Connection 1
UPDATE `test_deadlock` SET `data` = RAND() * 1000 WHERE `id` = 'test';
# ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
```

### 2. What did you expect to see? (Required)
No deadlock error.

### 3. What did you see instead (Required)
Deadlock

### 4. What is your TiDB version? (Required)
2eb698c1d30b510206c0819af23390d61535a9e8

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.