Skip to content

Commit

Permalink
statistics: fix init topn not sorted (#34234)
Browse files Browse the repository at this point in the history
ref #32758, close #34216
  • Loading branch information
time-and-fate authored Apr 26, 2022
1 parent 2f2fa06 commit e158017
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions statistics/handle/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (h *Handle) initStatsHistograms(is infoschema.InfoSchema, cache *statsCache
}

func (h *Handle) initStatsTopN4Chunk(cache *statsCache, iter *chunk.Iterator4Chunk) {
affectedIndexes := make(map[int64]*statistics.Index)
affectedIndexes := make(map[*statistics.Index]struct{})
for row := iter.Begin(); row != iter.End(); row = iter.Next() {
table, ok := cache.Get(row.GetInt64(0))
if !ok {
Expand All @@ -192,12 +192,12 @@ func (h *Handle) initStatsTopN4Chunk(cache *statsCache, iter *chunk.Iterator4Chu
if idx.TopN == nil {
idx.TopN = statistics.NewTopN(32)
}
affectedIndexes[row.GetInt64(1)] = idx
affectedIndexes[idx] = struct{}{}
data := make([]byte, len(row.GetBytes(2)))
copy(data, row.GetBytes(2))
idx.TopN.AppendTopN(data, row.GetUint64(3))
}
for _, idx := range affectedIndexes {
for idx := range affectedIndexes {
idx.TopN.Sort()
}
}
Expand Down

0 comments on commit e158017

Please sign in to comment.