Visibility of T1 after deletion of T2
- 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
CREATE TABLE t0 (c0 INT);
INSERT INTO t0 VALUES (-2);
INSERT INTO t0 VALUES (-1);
INSERT INTO t0 VALUES (1);
INSERT INTO t0 VALUES (2);
/* T1 */ BEGIN;
/* T2 */ BEGIN;
/* T2 */ DELETE FROM t0 WHERE c0 >= 0;
/* T1 */ SELECT * FROM t0;
/* T2 */ COMMIT;
/* T1 */ UPDATE t0 SET c0 = 0;
/* T1 */ SELECT * FROM t0;
/* T1 */ COMMIT;
```
### 2. What did you expect to see? (Required)
In PG.
```sql
postgres=# /* T1 */ BEGIN;
BEGIN
postgres=# /* T2 */ BEGIN;
BEGIN
postgres=*# /* T1 */ SELECT * FROM t0;
c0
----
-2
-1
1
2
(4 rows)
postgres=*# /* T2 */ DELETE FROM t0 WHERE c0 >= 0;
DELETE 2
postgres=*# /* T2 */ COMMIT;
COMMIT
postgres=*# /* T1 */ UPDATE t0 SET c0 = 0;
UPDATE 2
postgres=*# /* T1 */ SELECT * FROM t0;
c0
----
0
0
(2 rows)
postgres=*# /* T1 */ COMMIT;
COMMIT
```
### 3. What did you see instead (Required)
```sql
mysql> SHOW VARIABLES LIKE 'transaction_isolation';
+-----------------------+-----------------+
| Variable_name | Value |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
+-----------------------+-----------------+
1 row in set (0.00 sec)
/* T1 */ BEGIN;
/* T2 */ BEGIN;
/* T2 */ DELETE FROM t0 WHERE c0 >= 0;
Query OK, 2 rows affected (0.00 sec)
/* T1 */ SELECT * FROM t0;
+------+
| c0 |
+------+
| -2 |
| -1 |
| 1 |
| 2 |
+------+
4 rows in set (0.00 sec)
/* T2 */ COMMIT;
/* T1 */ UPDATE t0 SET c0 = 0;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
/* T1 */ SELECT * FROM t0;
+------+
| c0 |
+------+
| 0 |
| 0 |
| 1 |
| 2 |
+------+
4 rows in set (0.00 sec)
/* T1 */ COMMIT;
```
### 4. What is your TiDB version? (Required)
Release Version: v8.2.0
Edition: Community
Git Commit Hash: 821e491a20fbab36604b36b647b5bae26a2c1418
Git Branch: HEAD
UTC Build Time: 2024-07-05 09:16:25
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Contributor guide
Research direction
Run the provided SQL reproduction on TiDB v8.2.0 and compare its repeatable-read results with the PostgreSQL behavior shown in the issue. Trace the transaction visibility handling for rows deleted by T2 before T1's update, and consider the issue done when T1 updates only the rows visible after T2 commits and the final query matches the expected two rows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100