Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions pkg/statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,33 +202,6 @@ func (h *Handle) getStatsByPhysicalID(physicalTableID int64, tblInfo *model.Tabl
return nil, false
}

// GetPartitionStatsByID retrieves the partition stats from cache by partition ID.
func (h *Handle) GetPartitionStatsByID(is infoschema.InfoSchema, pid int64) *statistics.Table {
return h.getPartitionStatsByID(is, pid)
}

func (h *Handle) getPartitionStatsByID(is infoschema.InfoSchema, pid int64) *statistics.Table {
var statsTbl *statistics.Table
intest.Assert(h != nil, "stats handle is nil")
tbl, ok := h.Get(pid)
if !ok {
tbl, ok := h.TableInfoByID(is, pid)
if !ok {
return nil
}
// TODO: it's possible don't rely on the full table meta to do it here.
statsTbl = statistics.PseudoTable(tbl.Meta(), false, true)
statsTbl.PhysicalID = pid
if tbl.Meta().GetPartitionInfo() == nil || h.Len() < 64 {
h.UpdateStatsCache(types.CacheUpdate{
Updated: []*statistics.Table{statsTbl},
})
}
return nil
}
return tbl
}

// FlushStats flushes the cached stats update into store.
func (h *Handle) FlushStats() {
if err := h.DumpStatsDeltaToKV(true); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/statistics/handle/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,6 @@ type StatsHandle interface {
// Note: this function may return nil if the table is not found in the cache.
GetNonPseudoPhysicalTableStats(physicalTableID int64) (*statistics.Table, bool)

// GetPartitionStatsByID retrieves the partition stats from cache by partition ID.
// TODO: remove this function and use GetPhysicalTableStats instead.
GetPartitionStatsByID(is infoschema.InfoSchema, pid int64) *statistics.Table

// StatsGC is used to do the GC job.
StatsGC

Expand Down
6 changes: 4 additions & 2 deletions pkg/statistics/handle/usage/session_stats_collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ func (s *statsUsageImpl) needDumpStatsDelta(is infoschema.InfoSchema, dumpAll bo
// Dump the stats to kv at least once 5 minutes.
return true
}
statsTbl := s.statsHandle.GetPartitionStatsByID(is, id)
if statsTbl == nil || statsTbl.Pseudo || statsTbl.RealtimeCount == 0 || float64(item.Count)/float64(statsTbl.RealtimeCount) > DumpStatsDeltaRatio {
// use GetNonPseudoPhysicalTableStats to avoid creating pseudo tables and dropping instantly
statsTable, found := s.statsHandle.GetNonPseudoPhysicalTableStats(id)
if !found || statsTable == nil || statsTable.RealtimeCount == 0 ||
float64(item.Count)/float64(statsTable.RealtimeCount) > DumpStatsDeltaRatio {
// Dump the stats when there are many modifications.
return true
}
Expand Down