diff --git a/pkg/executor/set.go b/pkg/executor/set.go index 89a65bb77a2e4..7649027df2abb 100644 --- a/pkg/executor/set.go +++ b/pkg/executor/set.go @@ -326,7 +326,11 @@ func (e *SetExecutor) loadSnapshotInfoSchemaIfNeeded(name string, snapshotTS uin if name != variable.TiDBSnapshot && name != variable.TiDBTxnReadTS { return nil } - vars := e.Ctx().GetSessionVars() + return loadSnapshotInfoSchemaIfNeeded(e.Ctx(), snapshotTS) +} + +func loadSnapshotInfoSchemaIfNeeded(sctx sessionctx.Context, snapshotTS uint64) error { + vars := sctx.GetSessionVars() if snapshotTS == 0 { vars.SnapshotInfoschema = nil return nil @@ -334,12 +338,12 @@ func (e *SetExecutor) loadSnapshotInfoSchemaIfNeeded(name string, snapshotTS uin logutil.BgLogger().Info("load snapshot info schema", zap.Uint64("conn", vars.ConnectionID), zap.Uint64("SnapshotTS", snapshotTS)) - dom := domain.GetDomain(e.Ctx()) + dom := domain.GetDomain(sctx) snapInfo, err := dom.GetSnapshotInfoSchema(snapshotTS) if err != nil { return err } - vars.SnapshotInfoschema = temptable.AttachLocalTemporaryTableInfoSchema(e.Ctx(), snapInfo) + vars.SnapshotInfoschema = temptable.AttachLocalTemporaryTableInfoSchema(sctx, snapInfo) return nil } diff --git a/pkg/executor/show.go b/pkg/executor/show.go index 523593d340eb5..8b3e9b1085204 100644 --- a/pkg/executor/show.go +++ b/pkg/executor/show.go @@ -2381,6 +2381,10 @@ func runWithSystemSession(ctx context.Context, sctx sessionctx.Context, fn func( return err } defer b.ReleaseSysSession(ctx, sysCtx) + + if err = loadSnapshotInfoSchemaIfNeeded(sysCtx, sctx.GetSessionVars().SnapshotTS); err != nil { + return err + } // `fn` may use KV transaction, so initialize the txn here if err = sessiontxn.NewTxn(ctx, sysCtx); err != nil { return err