pingcap / pingcap/tidb

Query in transaction may return rows with same primary key column value

Open
#44,200 1 comment 0 reactions 1 assignee Claimed by @crazycs520 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!

This is a sub-issue of https://github.com/pingcap/tidb/issues/24195#issuecomment-825572552

### 1. Minimal reproduce step (Required)

```sql
/* t1 */ drop table if exists t;
/* t1 */ create table t (c1 varchar(10), c2 int, primary key (c1) nonclustered);
/* t1 */ insert into t values ('a', 1);
/* t1 */ begin;
/* t1 */ update t set c1='b' where c1='a';
/* t2 */ begin;
/* t2 */ select * from t;
/* t2 */ insert into t values ('a', 2); -- Blocked until t1 commited.
/* t1 */ commit;
/* t2 */ select * from t use index(primary) order by c1, c2; -- [('a', 1), ('a', 2)]
```

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

MySQL 8.0.29 returns:
```sql
/* t2 */ select * from t use index(primary) order by c1, c2;
+----+----+
| c1 | c2 |
+----+----+
| a | 2 |
+----+----+
```

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

Currently TiDB returns:
```sql
/* t2 */ select * from t use index(primary) order by c1, c2;
+----+----+
| c1 | c2 |
+----+----+
| a | 1 |
| a | 2 |
+----+----+
```

Since column c1 is a primary key, the query result breaks the primary key unique constraint.

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

```sql
***************************[ 1. row ]***************************
tidb_version() | Release Version: v7.2.0-alpha-277-geca4e9be28
Edition: Community
Git Commit Hash: eca4e9be284e92aca3d5fbb16e44c6a7655fdf82
Git Branch: master
UTC Build Time: 2023-05-26 02:22:59
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore
```

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.