Skip to content

Commit

Permalink
*: simple code (#46247)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Aug 21, 2023
1 parent 0b2d62b commit ab4d6ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
10 changes: 2 additions & 8 deletions statistics/cmsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,14 +919,13 @@ func checkEmptyTopNs(topNs []*TopN) bool {
}

// SortTopnMeta sort topnMeta
func SortTopnMeta(topnMetas []TopNMeta) []TopNMeta {
func SortTopnMeta(topnMetas []TopNMeta) {
slices.SortFunc(topnMetas, func(i, j TopNMeta) int {
if i.Count != j.Count {
return cmp.Compare(j.Count, i.Count)
}
return bytes.Compare(i.Encoded, j.Encoded)
})
return topnMetas
}

// GetMergedTopNFromSortedSlice returns merged topn
Expand All @@ -935,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
4 changes: 2 additions & 2 deletions statistics/cmsketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ func TestSortTopnMeta(t *testing.T) {
Encoded: []byte("b"),
Count: 2,
}}
sortedData := SortTopnMeta(data)
require.Equal(t, uint64(2), sortedData[0].Count)
SortTopnMeta(data)
require.Equal(t, uint64(2), data[0].Count)
}

func TestMergePartTopN2GlobalTopNWithHists(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,10 @@ func MergeGlobalStatsTopNByConcurrency(mergeConcurrency, mergeBatchSize int, wra
}

globalTopN, popedTopn := statistics.GetMergedTopNFromSortedSlice(sorted, n)
return globalTopN, statistics.SortTopnMeta(append(leftTopn, popedTopn...)), wrapper.AllHg, nil

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

func (h *Handle) getTableByPhysicalID(is infoschema.InfoSchema, physicalID int64) (table.Table, bool) {
Expand Down

0 comments on commit ab4d6ad

Please sign in to comment.