diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index c0318adf56a13..ea668826e089b 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -3181,8 +3181,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) }