Prevent `SELECT ... AS OF TIMESTAMP` from being used during implicit txn with autocommit = 0.
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
According to the description in Stale Read Product Design, `SELECT ... AS OF TIMESTAMP`
> - Only used in the implicit transaction with autocommit = 1.
However, we can still successfully execute the `SELECT ... AS OF TIMESTAMP` statement even with `autocommit = 0`.
```sql
drop table if exists t;
create table t (id int primary key, v int);
insert into t values (1, 10);
select sleep(0.1);
set @ts1 = now(6);
select sleep(0.1);
update t set v = 20 where id = 1;
set @ts2 = now(6);
select sleep(0.1);
update t set v = 30 where id = 1;
select sleep(1);
set @@tidb_read_staleness = -1;
set @@autocommit = 0;
-- should report error but sometimes it doesn't
select * from t as of timestamp @ts1 where id = 1;
select * from t as of timestamp @ts2 where id = 1;
```
Contributor guide
Assessment
This issue has not been assessed yet.