From 1c5ad420d3a87f9f0d67b6e3b7c0e4ac4c63ab7f Mon Sep 17 00:00:00 2001 From: Han Fei Date: Wed, 7 Jun 2017 19:13:24 +0800 Subject: [PATCH] executor: avoid allocating a lot of memory at first in topn. (#3392) --- executor/sort.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/executor/sort.go b/executor/sort.go index f1b3652b888af..183393cb0cf4b 100644 --- a/executor/sort.go +++ b/executor/sort.go @@ -186,7 +186,11 @@ func (e *TopnExec) Next() (*Row, error) { if !e.fetched { e.Idx = int(e.limit.Offset) e.totalCount = int(e.limit.Offset + e.limit.Count) - e.Rows = make([]*orderByRow, 0, e.totalCount+1) + cap := e.totalCount + 1 + if cap > 1024 { + cap = 1024 + } + e.Rows = make([]*orderByRow, 0, cap) e.heapSize = 0 for { srcRow, err := e.children[0].Next()