From 5dd3f44cc15528bdc713283273701bd6a9027768 Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 22 Oct 2024 19:07:29 +0800 Subject: [PATCH] enhance: Preallocate delete data slice to avoid growslice (#37043) Related to #36887 Signed-off-by: Congqi Xia --- internal/querynodev2/segments/segment_loader.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/querynodev2/segments/segment_loader.go b/internal/querynodev2/segments/segment_loader.go index 4149028deb7bf..4c51db03ef3a7 100644 --- a/internal/querynodev2/segments/segment_loader.go +++ b/internal/querynodev2/segments/segment_loader.go @@ -1183,8 +1183,9 @@ func (loader *segmentLoader) LoadDeltaLogs(ctx context.Context, segment Segment, return nil, err } blob := &storage.Blob{ - Key: bLog.GetLogPath(), - Value: value, + Key: bLog.GetLogPath(), + Value: value, + RowNum: bLog.EntriesNum, } return blob, nil }) @@ -1203,7 +1204,14 @@ func (loader *segmentLoader) LoadDeltaLogs(ctx context.Context, segment Segment, return nil } - deltaData := &storage.DeleteData{} + rowNums := lo.SumBy(blobs, func(blob *storage.Blob) int64 { + return blob.RowNum + }) + deltaData := &storage.DeleteData{ + Pks: make([]storage.PrimaryKey, 0, rowNums), + Tss: make([]uint64, 0, rowNums), + } + reader, err := storage.CreateDeltalogReader(blobs) if err != nil { return err