pingcap / pingcap/tidb

​​RR isolation fails to guarantee repeatable read in DATE type

Open
#61,219 7 comments 0 reactions 0 assignees View on GitHub
sig/transaction 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
/* t1 */ drop table if exists t;
/* t1 */ create table t (accountDay date, stock int, primary key(accountday));
/* t1 */ insert into t values ('2025-05-01', 1);

/* t1 */ begin;
/* t1 */ update t set accountDay = '2025-04-29' where accountDay = '2025-05-01';

/* t2 */ begin;
/* t2 */ select accountDay, stock from t where stock > 0; -- first query in t2
/* t2 */ insert into t values ('2025-05-01', 2); -- waiting

/* t1 */ commit;

/* t2 */ select accountDay, stock from t where stock > 0; -- second query in t2
/* t2 */ commit;
```

The First query in t2 didn't have any problem:
```
mysql> select accountDay, stock from t where stock > 0;
+------------+-------+
| accountDay | stock |
+------------+-------+
| 2025-05-01 | 1 |
+------------+-------+
1 row in set (0.00 sec)
```

But the second query didn't work well:
```
mysql> select accountDay, stock from t where stock > 0;
+------------+-------+
| accountDay | stock |
+------------+-------+
| 2025-05-01 | 2 |
+------------+-------+
1 row in set (0.00 sec)
```

The correct result of the second query is in the following: (should be performed the same as MariaDB)
```
mysql> select accountDay, stock from t where stock > 0;
+------------+-------+
| accountDay | stock |
+------------+-------+
| 2025-04-29 | 1 |
| 2025-05-01 | 2 |
+------------+-------+
1 row in set (0.00 sec)
```

### 2. What did you expect to see? (Required)
The second query should be: ( in MariaDB v10.4.0)
```
mysql> select accountDay, stock from t where stock > 0;
+------------+-------+
| accountDay | stock |
+------------+-------+
| 2025-04-29 | 1 |
| 2025-05-01 | 2 |
+------------+-------+
1 row in set (0.00 sec)
```

### 3. What did you see instead (Required)
The second query:
```
mysql> select accountDay, stock from t where stock > 0;
+------------+-------+
| accountDay | stock |
+------------+-------+
| 2025-05-01 | 2 |
+------------+-------+
1 row in set (0.00 sec)
```

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

v8.5.1

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied two-transaction SQL reproduction against TiDB v8.5.1 and compare its repeatable-read result with MariaDB v10.4.0. Trace the DATE update and subsequent insert under RR to determine why the second query returns only the new row; the issue is done when it returns both expected rows without weakening isolation guarantees.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.