This commit is contained in:
Aliaksandr Valialkin 2024-05-21 00:06:58 +02:00
parent 5e61b40fef
commit d75b0df747
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -258,7 +258,8 @@ func (shard *pipeTopkProcessorShard) addRow(br *blockResult, byColumns []string,
r.timestamp = timestamp
rows := shard.rows
if len(rows) > 0 && !topkLess(shard.ps, r, rows[0]) {
maxRows := shard.ps.offset + shard.ps.limit
if uint64(len(rows)) >= maxRows && !topkLess(shard.ps, r, rows[0]) {
// Fast path - nothing to add.
return
}
@ -282,7 +283,7 @@ func (shard *pipeTopkProcessorShard) addRow(br *blockResult, byColumns []string,
shard.stateSizeBudget -= r.sizeBytes()
// Push r to shard.rows.
if uint64(len(rows)) < shard.ps.offset+shard.ps.limit {
if uint64(len(rows)) < maxRows {
heap.Push(shard, r)
shard.stateSizeBudget -= int(unsafe.Sizeof(r))
} else {