diff --git a/pkg/sessionctx/variable/session.go b/pkg/sessionctx/variable/session.go index 4e5a093a3806a..606dab8630108 100644 --- a/pkg/sessionctx/variable/session.go +++ b/pkg/sessionctx/variable/session.go @@ -3611,8 +3611,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) }