diff --git a/pkg/sessionctx/variable/session.go b/pkg/sessionctx/variable/session.go index e7bc825cb36f3..1307feba252c8 100644 --- a/pkg/sessionctx/variable/session.go +++ b/pkg/sessionctx/variable/session.go @@ -3553,8 +3553,9 @@ func (s *SessionVars) GetNegateStrMatchDefaultSelectivity() float64 { // GetRelatedTableForMDL gets the related table for metadata lock. func (s *SessionVars) GetRelatedTableForMDL() *sync.Map { - s.TxnCtx.tdmLock.Lock() - defer s.TxnCtx.tdmLock.Unlock() + mu := &s.TxnCtx.tdmLock + mu.Lock() + defer mu.Unlock() if s.TxnCtx.relatedTableForMDL == nil { s.TxnCtx.relatedTableForMDL = new(sync.Map) }