Skip to content

Commit

Permalink
*: avoid sort
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Aug 19, 2023
1 parent 4c69ebb commit 22c7f07
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions statistics/cmsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,7 @@ func GetMergedTopNFromSortedSlice(sorted []TopNMeta, n uint32) (*TopN, []TopNMet
}

func getMergedTopNFromSortedSlice(sorted []TopNMeta, n uint32) (*TopN, []TopNMeta) {
slices.SortFunc(sorted, func(i, j TopNMeta) int {
if i.Count != j.Count {
return cmp.Compare(j.Count, i.Count)
}
return bytes.Compare(i.Encoded, j.Encoded)
})
SortTopnMeta(sorted)
n = mathutil.Min(uint32(len(sorted)), n)

var finalTopN TopN
Expand Down
2 changes: 1 addition & 1 deletion statistics/cmsketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func TestSortTopnMeta(t *testing.T) {
Encoded: []byte("b"),
Count: 2,
}}
SortTopnMeta(&data)
SortTopnMeta(data)
require.Equal(t, uint64(2), data[0].Count)
}

Expand Down
2 changes: 1 addition & 1 deletion statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ func MergeGlobalStatsTopNByConcurrency(mergeConcurrency, mergeBatchSize int, wra
globalTopN, popedTopn := statistics.GetMergedTopNFromSortedSlice(sorted, n)

result := append(leftTopn, popedTopn...)
statistics.SortTopnMeta(&result)
statistics.SortTopnMeta(result)
return globalTopN, result, wrapper.AllHg, nil
}

Expand Down

0 comments on commit 22c7f07

Please sign in to comment.