diff --git a/pkg/sessionctx/variable/session.go b/pkg/sessionctx/variable/session.go index eec4abbdf73b9..2435ab8e7af8f 100644 --- a/pkg/sessionctx/variable/session.go +++ b/pkg/sessionctx/variable/session.go @@ -2606,6 +2606,8 @@ func (s *SessionVars) LazyCheckKeyNotExists() bool { // GetTemporaryTable returns a TempTable by tableInfo. func (s *SessionVars) GetTemporaryTable(tblInfo *model.TableInfo) tableutil.TempTable { if tblInfo.TempTableType != model.TempTableNone { + s.TxnCtxMu.Lock() + defer s.TxnCtxMu.Unlock() if s.TxnCtx.TemporaryTables == nil { s.TxnCtx.TemporaryTables = make(map[int64]tableutil.TempTable) }