Skip to content

Commit 6a010b5

Browse files
authored
statistics: skip create pseudo stats for partitions (#51123)
close #50100
1 parent d96244d commit 6a010b5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

pkg/statistics/handle/autoanalyze/autoanalyze.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func getPartitionStats(
467467
partitionStats := make(map[int64]*statistics.Table, len(defs))
468468

469469
for _, def := range defs {
470-
partitionStats[def.ID] = statsHandle.GetPartitionStats(tblInfo, def.ID)
470+
partitionStats[def.ID] = statsHandle.GetPartitionStatsForAutoAnalyze(tblInfo, def.ID)
471471
}
472472

473473
return partitionStats
@@ -599,10 +599,10 @@ func tryAutoAnalyzePartitionTableInDynamicMode(
599599

600600
for _, def := range partitionDefs {
601601
partitionStatsTbl := partitionStats[def.ID]
602-
// 1. If the stats are not loaded, we don't need to analyze it.
602+
// 1. If the statistics are either not loaded or are classified as pseudo, there is no need for analyze.
603603
// 2. If the table is too small, we don't want to waste time to analyze it.
604604
// Leave the opportunity to other bigger tables.
605-
if partitionStatsTbl.Pseudo || partitionStatsTbl.RealtimeCount < AutoAnalyzeMinCnt {
605+
if partitionStatsTbl == nil || partitionStatsTbl.RealtimeCount < AutoAnalyzeMinCnt {
606606
continue
607607
}
608608
if needAnalyze, reason := NeedAnalyzeTable(

pkg/statistics/handle/handle.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (h *Handle) GetTableStats(tblInfo *model.TableInfo) *statistics.Table {
149149
return h.GetPartitionStats(tblInfo, tblInfo.ID)
150150
}
151151

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

163+
// GetPartitionStatsForAutoAnalyze is to get partition stats but it will not return pseudo stats.
164+
func (h *Handle) GetPartitionStatsForAutoAnalyze(tblInfo *model.TableInfo, pid int64) *statistics.Table {
165+
return h.getPartitionStats(tblInfo, pid, false)
166+
}
167+
163168
func (h *Handle) getPartitionStats(tblInfo *model.TableInfo, pid int64, returnPseudo bool) *statistics.Table {
164169
var tbl *statistics.Table
165170
if h == nil {

pkg/statistics/handle/types/interfaces.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ type StatsHandle interface {
445445
// GetPartitionStats retrieves the partition stats from cache.
446446
GetPartitionStats(tblInfo *model.TableInfo, pid int64) *statistics.Table
447447

448+
// GetPartitionStatsForAutoAnalyze retrieves the partition stats from cache, but it will not return pseudo.
449+
GetPartitionStatsForAutoAnalyze(tblInfo *model.TableInfo, pid int64) *statistics.Table
450+
448451
// StatsGC is used to do the GC job.
449452
StatsGC
450453

0 commit comments

Comments
 (0)