pingcap / pingcap/tidb

When passing SKIP LOCKED TiDB ignores FOR UPDATE

Open
#69,720 3 comments 0 reactions 0 assignees View on GitHub
contribution first-time-contributor may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/transaction type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

When passing SKIP LOCKED TiDB silently ignores FOR UPDATE. This is not asking for SKIP LOCKED support i.e https://github.com/pingcap/tidb/issues/18207 but rather TiDB should either report an error when using SKIP LOCKED or ignore the SKIP LOCKED but still process FOR UPDATE

### 1. Minimal reproduce step (Required)

```
❯ /opt/homebrew/opt/mysql-client@8.4/bin/mysql --host 127.0.0.1 --port 4000 -u root
Server version: 8.0.11-TiDB-v8.5.6 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

mysql> CREATE table job4 (`batch_id` int NOT NULL, PRIMARY KEY (`batch_id`));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into job4 (batch_id) values (0);
Query OK, 1 row affected (0.00 sec)

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from job4 for update skip locked;
+----------+
| batch_id |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
```

Then while that transaction is running

```
❯ /opt/homebrew/opt/mysql-client@8.4/bin/mysql --host 127.0.0.1 --port 4000 -u root
Server version: 8.0.11-TiDB-v8.5.6 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from job4 for update skip locked;
+----------+
| batch_id |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
```

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

Either:
SKIP LOCKED supported -> zero rows
SKIP LOCKED ignored -> query hangs until lock can be obtained
SKIP LOCKED unsupported -> error

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

FOR UPDATE is silently ignored and multiple queries can "lock" the same row when SKIP LOCKED is passed.

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

Release Version: v8.5.6
Edition: Community
Git Commit Hash: ae18096e023780bb56bfce33698abec0d4640d0a
Git Branch: HEAD
UTC Build Time: 2026-04-14 07:11:54
GoVersion: go1.25.8
Race Enabled: false
Check Table Before Drop: false
Store: tikv

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two concurrent transaction sequences from the issue against TiDB v8.5.6, then trace the handling of FOR UPDATE with SKIP LOCKED. Done means TiDB consistently supports SKIP LOCKED, waits when it is ignored, or returns an explicit unsupported-syntax error instead of allowing both queries to lock the same row.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql, sql
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.