Skip to content

Commit

Permalink
*: Use TxnManager.GetTxnInfoSchema() to get the txn infoschema (#30934)
Browse files Browse the repository at this point in the history
close #30933
  • Loading branch information
lcwangchao authored Dec 22, 2021
1 parent 9063d3b commit 1f6d2dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (a *ExecStmt) RebuildPlan(ctx context.Context) (int64, error) {
sessiontxn.AssertTxnManagerInfoSchema(a.Ctx, ret.InfoSchema)
})

a.InfoSchema = ret.InfoSchema
a.InfoSchema = sessiontxn.GetTxnManager(a.Ctx).GetTxnInfoSchema()
a.SnapshotTS = ret.LastSnapshotTS
a.IsStaleness = ret.IsStaleness
a.ReplicaReadScope = ret.ReadReplicaScope
Expand Down
5 changes: 3 additions & 2 deletions executor/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (*ExecStm
sessiontxn.AssertTxnManagerInfoSchema(c.Ctx, ret.InfoSchema)
})

finalPlan, names, err := planner.Optimize(ctx, c.Ctx, stmtNode, ret.InfoSchema)
is := sessiontxn.GetTxnManager(c.Ctx).GetTxnInfoSchema()
finalPlan, names, err := planner.Optimize(ctx, c.Ctx, stmtNode, is)
if err != nil {
return nil, err
}
Expand All @@ -96,7 +97,7 @@ func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (*ExecStm
SnapshotTS: ret.LastSnapshotTS,
IsStaleness: ret.IsStaleness,
ReplicaReadScope: ret.ReadReplicaScope,
InfoSchema: ret.InfoSchema,
InfoSchema: is,
Plan: finalPlan,
LowerPriority: lowerPriority,
Text: stmtNode.Text(),
Expand Down
8 changes: 5 additions & 3 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,9 @@ func (s *session) ExecutePreparedStmt(ctx context.Context, stmtID uint32, args [
txnCtxProvider := &sessiontxn.SimpleTxnContextProvider{
InfoSchema: is,
}
if err = sessiontxn.GetTxnManager(s).SetContextProvider(txnCtxProvider); err != nil {

txnManager := sessiontxn.GetTxnManager(s)
if err = txnManager.SetContextProvider(txnCtxProvider); err != nil {
return nil, err
}

Expand All @@ -2143,9 +2145,9 @@ func (s *session) ExecutePreparedStmt(ctx context.Context, stmtID uint32, args [
defer s.txn.onStmtEnd()

if ok {
return s.cachedPlanExec(ctx, is, snapshotTS, stmtID, preparedStmt, args)
return s.cachedPlanExec(ctx, txnManager.GetTxnInfoSchema(), snapshotTS, stmtID, preparedStmt, args)
}
return s.preparedStmtExec(ctx, is, snapshotTS, stmtID, preparedStmt, args)
return s.preparedStmtExec(ctx, txnManager.GetTxnInfoSchema(), snapshotTS, stmtID, preparedStmt, args)
}

func (s *session) DropPreparedStmt(stmtID uint32) error {
Expand Down

0 comments on commit 1f6d2dd

Please sign in to comment.