diff --git a/executor/stale_txn_test.go b/executor/stale_txn_test.go index de10f6e9a3fee..a6e814b68c172 100644 --- a/executor/stale_txn_test.go +++ b/executor/stale_txn_test.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" + "github.com/pingcap/tidb/sessiontxn" "github.com/pingcap/tidb/sessiontxn/staleread" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/types" @@ -507,15 +508,15 @@ func TestStalenessTransactionSchemaVer(t *testing.T) { // get the specific old schema tk.MustExec(fmt.Sprintf(`START TRANSACTION READ ONLY AS OF TIMESTAMP '%s'`, time1.Format("2006-1-2 15:04:05.000"))) - require.Equal(t, schemaVer1, tk.Session().GetInfoSchema().SchemaMetaVersion()) + require.Equal(t, schemaVer1, sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion()) // schema changed back to the newest tk.MustExec("commit") - require.Equal(t, schemaVer2, tk.Session().GetInfoSchema().SchemaMetaVersion()) + require.Equal(t, schemaVer2, sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion()) // select does not affect the infoschema tk.MustExec(fmt.Sprintf(`SELECT * from t AS OF TIMESTAMP '%s'`, time1.Format("2006-1-2 15:04:05.000"))) - require.Equal(t, schemaVer2, tk.Session().GetInfoSchema().SchemaMetaVersion()) + require.Equal(t, schemaVer2, sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion()) } func TestSetTransactionReadOnlyAsOf(t *testing.T) { @@ -888,28 +889,28 @@ func TestSetTransactionInfoSchema(t *testing.T) { defer tk.MustExec("drop table if exists t") tk.MustExec("create table t (id int primary key);") - schemaVer1 := tk.Session().GetInfoSchema().SchemaMetaVersion() + schemaVer1 := sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion() time1 := time.Now() tk.MustExec("alter table t add c int") // confirm schema changed - schemaVer2 := tk.Session().GetInfoSchema().SchemaMetaVersion() + schemaVer2 := sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion() time2 := time.Now() require.Less(t, schemaVer1, schemaVer2) tk.MustExec(fmt.Sprintf(`SET TRANSACTION READ ONLY AS OF TIMESTAMP '%s'`, time1.Format("2006-1-2 15:04:05.000"))) require.Equal(t, schemaVer1, tk.Session().GetInfoSchema().SchemaMetaVersion()) tk.MustExec("select * from t;") tk.MustExec("alter table t add d int") - schemaVer3 := tk.Session().GetInfoSchema().SchemaMetaVersion() + schemaVer3 := sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion() tk.MustExec(fmt.Sprintf(`SET TRANSACTION READ ONLY AS OF TIMESTAMP '%s'`, time1.Format("2006-1-2 15:04:05.000"))) tk.MustExec("begin;") - require.Equal(t, schemaVer1, tk.Session().GetInfoSchema().SchemaMetaVersion()) + require.Equal(t, schemaVer1, sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion()) tk.MustExec("commit") tk.MustExec(fmt.Sprintf(`SET TRANSACTION READ ONLY AS OF TIMESTAMP '%s'`, time2.Format("2006-1-2 15:04:05.000"))) tk.MustExec("begin;") - require.Equal(t, schemaVer2, tk.Session().GetInfoSchema().SchemaMetaVersion()) + require.Equal(t, schemaVer2, sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion()) tk.MustExec("commit") - require.Equal(t, schemaVer3, tk.Session().GetInfoSchema().SchemaMetaVersion()) + require.Equal(t, schemaVer3, sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema().SchemaMetaVersion()) } func TestStaleSelect(t *testing.T) { diff --git a/session/session.go b/session/session.go index 48ee996e4916d..386ae04619732 100644 --- a/session/session.go +++ b/session/session.go @@ -3882,7 +3882,7 @@ func (s *session) GetInfoSchema() sessionctx.InfoschemaMetaVersion { if snap, ok := vars.SnapshotInfoschema.(infoschema.InfoSchema); ok { logutil.BgLogger().Info("use snapshot schema", zap.Uint64("conn", vars.ConnectionID), zap.Int64("schemaVersion", snap.SchemaMetaVersion())) is = snap - } else if vars.TxnCtx != nil && vars.InTxn() { + } else if vars.TxnCtx != nil { if tmp, ok := vars.TxnCtx.InfoSchema.(infoschema.InfoSchema); ok { is = tmp }