Query in transaction behavior is inconsistent with MySQL
- 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-906882492
### 1. Minimal reproduce step (Required)
```sql
/* t1 */ drop table if exists t;
/* t1 */ create table t (c1 varchar(10), c2 int, primary key(c1));
/* t1 */ insert into t values ('a', 1);
/* t1 */ begin;
/* t1 */ update t set c1='b' where c1='a';
/* t2 */ begin;
/* t2 */ insert into t values ('a', 2);
/* t1 */ commit;
/* t2 */ select * from t;
```
For the last query, TiDB return:
```sql
+----+----+
| c1 | c2 |
+----+----+
| a | 2 |
+----+----+
```
But MySQL 8.0.29 return:
```sql
+----+----+
| c1 | c2 |
+----+----+
| a | 2 |
| b | 1 |
+----+----+
```
Theoretically, transaction `t2` start_ts is small than transaction `t1`, then the last query shouldn't see row `b 1`.
But if transaction `t2` query once after begin, MySQL query result will same with TiDB:
```sql
/* t1 */ drop table if exists t;
/* t1 */ create table t (c1 varchar(10), c2 int, primary key(c1));
/* 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);
/* t1 */ commit;
/* t2 */ select * from t;
```
For the last query, both TiDB and MySQL 8.0.29 return:
```
+----+----+
| c1 | c2 |
+----+----+
| a | 2 |
+----+----+
```
### 4. What is your TiDB version? (Required)
```sql
***************************[ 1. row ]***************************
tidb_version() | Release Version: v7.2.0-alpha-306-gc4756df3b4
Edition: Community
Git Commit Hash: c4756df3b4e6ba6b5a532e0999ac3a28c40fa31a
Git Branch: master
UTC Build Time: 2023-05-31 09:14:58
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore
```
Contributor guide
Assessment
This issue has not been assessed yet.