Skip to content

Commit

Permalink
statistics: not put pseudo table of partition table into cache (#44374)
Browse files Browse the repository at this point in the history
close #44308
  • Loading branch information
hawkingrei authored Jun 5, 2023
1 parent afdb741 commit 9bac155
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,18 @@ func (h *Handle) GetPartitionStats(tblInfo *model.TableInfo, pid int64, opts ...
if !ok {
tbl = statistics.PseudoTable(tblInfo)
tbl.PhysicalID = pid
h.updateStatsCache(statsCache.update([]*statistics.Table{tbl}, nil, statsCache.version))
if tblInfo.GetPartitionInfo() == nil || h.statsCacheLen() < 64 {
h.updateStatsCache(statsCache.update([]*statistics.Table{tbl}, nil, statsCache.version))
}
return tbl
}
return tbl
}

func (h *Handle) statsCacheLen() int {
return h.statsCache.Load().(statsCache).Len()
}

// updateStatsCache overrides the global statsCache with a new one, it may fail
// if the global statsCache has been modified by others already.
// Callers should add retry loop if necessary.
Expand Down
4 changes: 4 additions & 0 deletions statistics/handle/statscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ type statsCache struct {
minorVersion uint64
}

func (sc statsCache) len() int {
return sc.statsCacheInner.Len()
}

func (sc statsCache) copy() statsCache {
newCache := statsCache{
version: sc.version,
Expand Down

0 comments on commit 9bac155

Please sign in to comment.