diff --git a/pkg/store/mockstore/unistore/cophandler/cop_handler.go b/pkg/store/mockstore/unistore/cophandler/cop_handler.go index 62448f0f0853b..7097f07104476 100644 --- a/pkg/store/mockstore/unistore/cophandler/cop_handler.go +++ b/pkg/store/mockstore/unistore/cophandler/cop_handler.go @@ -19,6 +19,7 @@ import ( "context" "fmt" "strings" + "sync" "time" "github.com/golang/protobuf/proto" @@ -50,6 +51,32 @@ import ( "github.com/pingcap/tipb/go-tipb" ) +var globalLocationMap *locationMap = newLocationMap() + +type locationMap struct { + lmap map[string]*time.Location + mu sync.RWMutex +} + +func newLocationMap() *locationMap { + return &locationMap{ + lmap: make(map[string]*time.Location), + } +} + +func (l *locationMap) getLocation(name string) (*time.Location, bool) { + l.mu.RLock() + defer l.mu.RUnlock() + result, ok := l.lmap[name] + return result, ok +} + +func (l *locationMap) setLocation(name string, value *time.Location) { + l.mu.Lock() + defer l.mu.Unlock() + l.lmap[name] = value +} + // MPPCtx is the mpp execution context type MPPCtx struct { RPCClient client.Client @@ -309,9 +336,14 @@ func buildDAG(reader *dbreader.DBReader, lockStore *lockstore.MemStore, req *cop case "System": tz = time.Local default: - tz, err = time.LoadLocation(dagReq.TimeZoneName) - if err != nil { - return nil, nil, errors.Trace(err) + var ok bool + tz, ok = globalLocationMap.getLocation(dagReq.TimeZoneName) + if !ok { + tz, err = time.LoadLocation(dagReq.TimeZoneName) + if err != nil { + return nil, nil, errors.Trace(err) + } + globalLocationMap.setLocation(dagReq.TimeZoneName, tz) } } sctx := flagsAndTzToSessionContext(dagReq.Flags, tz)