pingcap / pingcap/tidb

Pessimistic and optimistic transactions return different results

Open
#42,486 0 comments 0 reactions 0 assignees View on GitHub
sig/transaction type/bug
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
optimistic test case
/* init */ CREATE TABLE t1(c0 INT);
/* init */ INSERT INTO t1 VALUES (1);

/* tx1 */ BEGIN OPTIMISTIC;
/* tx2 */ BEGIN OPTIMISTIC;
/* tx1 */ INSERT INTO t1(c0) VALUES (2);
/* tx1 */ COMMIT;
/* tx2 */ DELETE FROM t1;
/* tx2 */ COMMIT;
/* tx2 */ SELECT * FROM t1;

pessimistic test case
/* init */ CREATE TABLE t1(c0 INT);
/* init */ INSERT INTO t1 VALUES (1);

/* tx1 */ BEGIN PESSIMISTIC;
/* tx2 */ BEGIN PESSIMISTIC;
/* tx1 */ INSERT INTO t1(c0) VALUES (2);
/* tx1 */ COMMIT;
/* tx2 */ DELETE FROM t1;
/* tx2 */ COMMIT;
/* tx2 */ SELECT * FROM t1;
```

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

After executing the two test cases, the final SELECT statement returns the same resutls.

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

After executing optimistic transactions, the final SELECT statement returns [(2)].
After executing pessimistic transactions, the final SELECT statement returns empty set.

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

```sql
Release Version: v6.6.0
Edition: Community
Git Commit Hash: f4ca0821fb96a2bdd37d2fb97eb26c07fc58d4e4
Git Branch: heads/refs/tags/v6.6.0
UTC Build Time: 2023-02-17 14:49:02
GoVersion: go1.19.5
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
```

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.