From 7dd9c2563334a10ac6f6a5843642598d2d449d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=B6=85?= Date: Sat, 2 Apr 2022 11:12:29 +0800 Subject: [PATCH] cherry pick #33653 to release-6.0 Signed-off-by: ti-srebot --- executor/builder.go | 1 + executor/stale_txn_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/executor/builder.go b/executor/builder.go index 2730c2260fb7f..9568a07bd062b 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -121,6 +121,7 @@ func newExecutorBuilder(ctx sessionctx.Context, is infoschema.InfoSchema, ti *Te ctx: ctx, is: is, Ti: ti, + snapshotTSCached: isStaleness, snapshotTS: snapshotTS, isStaleness: isStaleness, readReplicaScope: replicaReadScope, diff --git a/executor/stale_txn_test.go b/executor/stale_txn_test.go index dbd692685e901..3676777b2c73b 100644 --- a/executor/stale_txn_test.go +++ b/executor/stale_txn_test.go @@ -1322,3 +1322,21 @@ func TestPlanCacheWithStaleReadByBinaryProto(t *testing.T) { require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10")) } + +func TestIssue30872(t *testing.T) { + store, _, clean := testkit.CreateMockStoreAndDomain(t) + defer clean() + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("set tidb_txn_mode='pessimistic'") + tk.MustExec("set tx_isolation = 'READ-COMMITTED'") + tk.MustExec("create table t1 (id int primary key, v int)") + tk.MustExec("insert into t1 values(1, 10)") + time.Sleep(time.Millisecond * 100) + tk.MustExec("set @a=now(6)") + time.Sleep(time.Millisecond * 100) + tk.MustExec("update t1 set v=100 where id=1") + tk.MustExec("set autocommit=0") + tk.MustQuery("select * from t1 as of timestamp @a").Check(testkit.Rows("1 10")) +}