Skip to content

Commit 3ab7aaf

Browse files
authored
chore(query): add merge ratio in sort spill (#15332)
* chore(query): add merge ratio in sort spill * chore(query): fix tests
1 parent b8996f5 commit 3ab7aaf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/query/pipeline/transforms/src/processors/transforms/transform_sort_merge_base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ use crate::processors::sort::SortSpillMetaWithParams;
6363
/// A spilled block file is at most 8MB.
6464
const SPILL_BATCH_BYTES_SIZE: usize = 8 * 1024 * 1024;
6565

66+
/// The memory will be doubled during merging.
67+
const MERGE_RATIO: usize = 2;
68+
6669
pub trait MergeSort<R: Rows> {
6770
const NAME: &'static str;
6871

@@ -234,9 +237,8 @@ where
234237
self.next_index += 1;
235238

236239
self.inner.add_block(block, cursor)?;
237-
238240
let blocks = if self.may_spill
239-
&& (self.inner.num_bytes() >= self.spilling_bytes_threshold
241+
&& (self.inner.num_bytes() * MERGE_RATIO >= self.spilling_bytes_threshold
240242
|| GLOBAL_MEM_STAT.get_memory_usage() as usize >= self.max_memory_usage)
241243
{
242244
self.prepare_spill()?

tests/suites/0_stateless/20+_others/20_0014_sort_spill.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ NULL 6
7171
NULL NULL
7272
2 5
7373
===================
74-
6
74+
9

0 commit comments

Comments
 (0)