Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Sep 19, 2023
1 parent 3431d52 commit 4f718d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
7 changes: 1 addition & 6 deletions executor/analyze_global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ func (e *AnalyzeExec) handleGlobalStats(ctx context.Context, globalStatsMap glob
}

for _, value := range tableAllPartitionStats {
for _, col := range value.Columns {
col.FMSketch.DestroyAndPutToPool()
}
for _, idx := range value.Indices {
idx.FMSketch.DestroyAndPutToPool()
}
value.ReleaseAndPutToPool()
}
}

Expand Down
25 changes: 21 additions & 4 deletions statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ func (g *GlobalStatusHandler) MergePartitionStats2GlobalStats(
loadTablePartitionStatsFn loadTablePartitionStatsFunc,
) (globalStats *GlobalStats, err error) {
partitionNum := len(globalTableInfo.Partition.Definitions)
<<<<<<< HEAD
=======
externalCache := false
if allPartitionStats == nil {
allPartitionStats = make(map[int64]*statistics.Table)
} else {
externalCache = true
}
// initialized the globalStats
globalStats = new(GlobalStats)
>>>>>>> 2d79e445e2 (update)
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 @@ -133,11 +144,16 @@ func (g *GlobalStatusHandler) MergePartitionStats2GlobalStats(

tableInfo := partitionTable.Meta()
var partitionStats *statistics.Table
<<<<<<< HEAD
if allPartitionStats != nil {
partitionStats, ok = allPartitionStats[partitionID]
}

// If preload partition stats isn't provided, then we load partition stats directly and set it into allPartitionStats.
=======
partitionStats, ok = allPartitionStats[partitionID]
// If pre-load partition stats isn't provided, then we load partition stats directly and set it into allPartitionStats
>>>>>>> 2d79e445e2 (update)
if allPartitionStats == nil || partitionStats == nil || !ok {
var err1 error
partitionStats, err1 = loadTablePartitionStatsFn(tableInfo, &def)
Expand All @@ -149,9 +165,6 @@ func (g *GlobalStatusHandler) MergePartitionStats2GlobalStats(
err = err1
return
}
if allPartitionStats == nil {
allPartitionStats = make(map[int64]*statistics.Table)
}
allPartitionStats[partitionID] = partitionStats
}

Expand Down Expand Up @@ -259,7 +272,11 @@ func (g *GlobalStatusHandler) MergePartitionStats2GlobalStats(
}
globalStats.Hg[i].NDV = globalStatsNDV
}

if !externalCache {
for _, value := range allPartitionStats {
value.ReleaseAndPutToPool()
}
}
return
}

Expand Down
10 changes: 10 additions & 0 deletions statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ func (t *Table) IsOutdated() bool {
return false
}

// ReleaseAndPutToPool releases data strucutres of Table and put itself back to pool.
func (t *Table) ReleaseAndPutToPool() {
for _, col := range t.Columns {
col.FMSketch.DestroyAndPutToPool()
}
for _, idx := range t.Indices {
idx.FMSketch.DestroyAndPutToPool()
}
}

// ID2UniqueID generates a new HistColl whose `Columns` is built from UniqueID of given columns.
func (coll *HistColl) ID2UniqueID(columns []*expression.Column) *HistColl {
cols := make(map[int64]*Column)
Expand Down

0 comments on commit 4f718d4

Please sign in to comment.