Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics: skip create pseudo stats for partitions #51123

Merged
Merged
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
6 changes: 3 additions & 3 deletions pkg/statistics/handle/autoanalyze/autoanalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func getPartitionStats(
partitionStats := make(map[int64]*statistics.Table, len(defs))

for _, def := range defs {
partitionStats[def.ID] = statsHandle.GetPartitionStats(tblInfo, def.ID)
partitionStats[def.ID] = statsHandle.GetPartitionStatsForAutoAnalyze(tblInfo, def.ID)
}

return partitionStats
Expand Down Expand Up @@ -599,10 +599,10 @@ func tryAutoAnalyzePartitionTableInDynamicMode(

for _, def := range partitionDefs {
partitionStatsTbl := partitionStats[def.ID]
// 1. If the stats are not loaded, we don't need to analyze it.
// 1. If the statistics are either not loaded or are classified as pseudo, there is no need for analyze.
// 2. If the table is too small, we don't want to waste time to analyze it.
// Leave the opportunity to other bigger tables.
if partitionStatsTbl.Pseudo || partitionStatsTbl.RealtimeCount < AutoAnalyzeMinCnt {
if partitionStatsTbl == nil || partitionStatsTbl.RealtimeCount < AutoAnalyzeMinCnt {
continue
}
if needAnalyze, reason := NeedAnalyzeTable(
Expand Down
7 changes: 6 additions & 1 deletion pkg/statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (h *Handle) GetTableStats(tblInfo *model.TableInfo) *statistics.Table {
return h.GetPartitionStats(tblInfo, tblInfo.ID)
}

// GetTableStatsForAutoAnalyze is to get table stats but it will
// GetTableStatsForAutoAnalyze is to get table stats but it will not return pseudo stats.
func (h *Handle) GetTableStatsForAutoAnalyze(tblInfo *model.TableInfo) *statistics.Table {
return h.getPartitionStats(tblInfo, tblInfo.ID, false)
}
Expand All @@ -160,6 +160,11 @@ func (h *Handle) GetPartitionStats(tblInfo *model.TableInfo, pid int64) *statist
return h.getPartitionStats(tblInfo, pid, true)
}

// GetPartitionStatsForAutoAnalyze is to get partition stats but it will not return pseudo stats.
func (h *Handle) GetPartitionStatsForAutoAnalyze(tblInfo *model.TableInfo, pid int64) *statistics.Table {
return h.getPartitionStats(tblInfo, pid, false)
}

func (h *Handle) getPartitionStats(tblInfo *model.TableInfo, pid int64, returnPseudo bool) *statistics.Table {
var tbl *statistics.Table
if h == nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/statistics/handle/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ type StatsHandle interface {
// GetPartitionStats retrieves the partition stats from cache.
GetPartitionStats(tblInfo *model.TableInfo, pid int64) *statistics.Table

// GetPartitionStatsForAutoAnalyze retrieves the partition stats from cache, but it will not return pseudo.
GetPartitionStatsForAutoAnalyze(tblInfo *model.TableInfo, pid int64) *statistics.Table

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

Expand Down