statistics: avoid copy twice when to decode the topn (#47563)
ref pingcap/tidb#47275
This commit is contained in:
@ -463,17 +463,15 @@ func DecodeCMSketchAndTopN(data []byte, topNRows []chunk.Row) (*CMSketch, *TopN,
|
||||
}
|
||||
|
||||
// DecodeTopN decodes a TopN from the given byte slice.
|
||||
func DecodeTopN(topNRows []chunk.Row) (*TopN, error) {
|
||||
pbTopN := make([]*tipb.CMSketchTopN, 0, len(topNRows))
|
||||
func DecodeTopN(topNRows []chunk.Row) *TopN {
|
||||
topN := NewTopN(len(topNRows))
|
||||
for _, row := range topNRows {
|
||||
data := make([]byte, len(row.GetBytes(0)))
|
||||
copy(data, row.GetBytes(0))
|
||||
pbTopN = append(pbTopN, &tipb.CMSketchTopN{
|
||||
Data: data,
|
||||
Count: row.GetUint64(1),
|
||||
})
|
||||
topN.AppendTopN(data, row.GetUint64(1))
|
||||
}
|
||||
return TopNFromProto(pbTopN), nil
|
||||
topN.Sort()
|
||||
return topN
|
||||
}
|
||||
|
||||
// DecodeCMSketch encodes the given CMSketch to byte slice.
|
||||
|
||||
@ -134,7 +134,7 @@ func TopNFromStorage(sctx sessionctx.Context, tblID int64, isIndex int, histID i
|
||||
if err != nil || len(rows) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
return statistics.DecodeTopN(rows)
|
||||
return statistics.DecodeTopN(rows), nil
|
||||
}
|
||||
|
||||
// FMSketchFromStorage reads FMSketch from storage
|
||||
|
||||
Reference in New Issue
Block a user