statistics: use slices.BinarySearchFunc to simple TopN.FindTopN (#46996)

ref pingcap/tidb#45933
This commit is contained in:
Weizhen Wang
2023-09-15 11:42:09 +08:00
committed by GitHub
parent 331ae3db19
commit 9ec78729fa

View File

@ -639,13 +639,8 @@ func (c *TopN) FindTopN(d []byte) int {
if c == nil {
return -1
}
match := false
idx := sort.Search(len(c.TopN), func(i int) bool {
cmpRst := bytes.Compare(c.TopN[i].Encoded, d)
if cmpRst == 0 {
match = true
}
return cmpRst >= 0
idx, match := slices.BinarySearchFunc(c.TopN, d, func(a TopNMeta, b []byte) int {
return bytes.Compare(a.Encoded, b)
})
if !match {
return -1