pingcap / pingcap/tidb

FOR UPDATE SKIP LOCKED on JOIN triggers _tidb_rowid resolution error in TiDB

Open
#67,715 11 comments 1 reaction 0 assignees View on GitHub
affects-7.5 affects-8.1 affects-8.5 contribution may-affects-7.1 severity/major sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

```sql
CREATE DATABASE tmp_3;
USE tmp_3;

CREATE TABLE tbl_4 (
col_4_1 INT,
pkid_4 INT,
version_4 VARCHAR(200)
);

CREATE TABLE tbl_7 (
col_7_1 SMALLINT,
pkid_7 INT,
version_7 VARCHAR(200),
INDEX idx_7_0 (col_7_1)
);

-- Query with FOR UPDATE SKIP LOCKED
SELECT
tbl_4.col_4_1, tbl_4.pkid_4, tbl_4.version_4,
tbl_7.col_7_1, tbl_7.pkid_7, tbl_7.version_7
FROM tbl_4
INNER JOIN tbl_7
ON tbl_4.col_4_1 = tbl_7.col_7_1
WHERE tbl_4.col_4_1 = 1
FOR UPDATE SKIP LOCKED;

-- Same query without FOR UPDATE SKIP LOCKED
SELECT
tbl_4.col_4_1, tbl_4.pkid_4, tbl_4.version_4,
tbl_7.col_7_1, tbl_7.pkid_7, tbl_7.version_7
FROM tbl_4
INNER JOIN tbl_7
ON tbl_4.col_4_1 = tbl_7.col_7_1
WHERE tbl_4.col_4_1 = 1;
```

---

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

* Both queries should execute successfully.
* The `FOR UPDATE SKIP LOCKED` clause should not introduce semantic or execution errors.
* Since there is no matching data, both queries are expected to return an empty result set.

---

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

* The query **with `FOR UPDATE SKIP LOCKED` fails** with an internal error:

```sql
ERROR 1105 (HY000): Can't find column tmp_3.tbl_7._tidb_rowid in schema
Column: [tmp_3.tbl_4.col_4_1,tmp_3.tbl_4.pkid_4,tmp_3.tbl_4.version_4,
tmp_3.tbl_7.col_7_1,tmp_3.tbl_7.pkid_7,tmp_3.tbl_7.version_7]
Unique key: []
```

* The **same query without `FOR UPDATE SKIP LOCKED` succeeds** and returns:

```sql
Empty set (0.00 sec)
```

This indicates the issue is specifically triggered by `FOR UPDATE SKIP LOCKED` in a join query, even when no rows are returned.

---

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

```sql
SELECT tidb_version();
```

Result:

```
8.0.11-TiDB-v8.5.3
```

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.