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

*: remove useless cache in the MergePartitionStats2GlobalStats #47217

Merged
merged 4 commits into from
Sep 26, 2023
Merged
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
29 changes: 10 additions & 19 deletions statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func MergePartitionStats2GlobalStats(
loadTablePartitionStatsFn loadTablePartitionStatsFunc,
) (globalStats *GlobalStats, err error) {
partitionNum := len(globalTableInfo.Partition.Definitions)
allPartitionStats := make(map[int64]*statistics.Table)
if len(histIDs) == 0 {
for _, col := range globalTableInfo.Columns {
// The virtual generated column stats can not be merged to the global stats.
Expand Down Expand Up @@ -122,27 +121,21 @@ func MergePartitionStats2GlobalStats(
err = errors.Errorf("unknown physical ID %d in stats meta table, maybe it has been dropped", partitionID)
return
}

tableInfo := partitionTable.Meta()
var partitionStats *statistics.Table

partitionStats, ok = allPartitionStats[partitionID]
// If pre-load partition stats isn't provided, then we load partition stats directly and set it into allPartitionStats
if !ok {
var err1 error
partitionStats, err1 = loadTablePartitionStatsFn(tableInfo, &def)
if err1 != nil {
if skipMissingPartitionStats && types.ErrPartitionStatsMissing.Equal(err) {
globalStats.MissingPartitionStats = append(globalStats.MissingPartitionStats, fmt.Sprintf("partition `%s`", def.Name.L))
continue
}
err = err1
return
partitionStats, err1 := loadTablePartitionStatsFn(tableInfo, &def)
if err1 != nil {
if skipMissingPartitionStats && types.ErrPartitionStatsMissing.Equal(err) {
globalStats.MissingPartitionStats = append(globalStats.MissingPartitionStats, fmt.Sprintf("partition `%s`", def.Name.L))
continue
}
allPartitionStats[partitionID] = partitionStats
err = err1
return
}

for i := 0; i < globalStats.Num; i++ {
// GetStatsInfo will return the copy of the statsInfo, so we don't need to worry about the data race.
// partitionStats will be released after the for loop.
hg, cms, topN, fms, analyzed := partitionStats.GetStatsInfo(histIDs[i], isIndex)
skipPartition := false
if !analyzed {
Expand Down Expand Up @@ -189,6 +182,7 @@ func MergePartitionStats2GlobalStats(
allFms[i] = append(allFms[i], fms)
}
}
partitionStats.ReleaseAndPutToPool()
}

// After collect all the statistics from the partition-level stats,
Expand Down Expand Up @@ -247,9 +241,6 @@ func MergePartitionStats2GlobalStats(
globalStats.Fms[i].DestroyAndPutToPool()
globalStats.Hg[i].NDV = globalStatsNDV
}
for _, value := range allPartitionStats {
value.ReleaseAndPutToPool()
}
return
}

Expand Down