pingcap / pingcap/tidb

Pessimistic Transaction: SELECT returns old snapshot after UPDATE to the same value

Open
#64,888 3 comments 1 reaction 0 assignees View on GitHub
contribution first-time-contributor severity/moderate sig/transaction 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)

1. Prepare a TiDB cluster (tested on v8.5.4) with the default Pessimistic Transaction mode and Repeatable Read isolation level.
2. Create a test table and insert initial data:
```sql
CREATE TABLE t (id INT, val INT);
INSERT INTO t VALUES (1, 1);
```
3. Open two terminal sessions (Session A and Session B).
4. Session A:
```sql
BEGIN;
SELECT * FROM t; -- Output: id:1, val:1
```
5. Session B:
```sql
UPDATE t SET val = 10 WHERE id = 1;
COMMIT;
```
6. Session A:
```sql
UPDATE t SET val = 10 WHERE id = 1; -- Result: Query OK, 1 row affected (or 0 rows changed), Rows matched: 1
```
7. Session A:
```sql
SELECT * FROM t;
```

### 2. What did you expect to see? (Required)
Since the update by Step 6 succeeded, Session A should see the updated value val = 10 in Step 7.

### 3. What did you see instead (Required)
I saw val = 1 in Step 7.

If I changed the val = 20 in Step 6, then Step 7 would be able to see his own write val=20.

### 4. What is your TiDB version? (Required)
```
Release Version: v8.5.4
Edition: Community
Git Commit Hash: e4e814fdc0afe9c3a6e5e96f129d83df802ab820
Git Branch: HEAD
UTC Build Time: 2025-11-26 15:53:39
GoVersion: go1.23.12
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```

This should be similar to the MariaDB bug: [https://jira.mariadb.org/browse/MDEV-26642](https://jira.mariadb.org/browse/MDEV-26642), which was fixed in their recent versions.

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.