This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 7a446b0d [core] Reuse the key buffer and row list across sort-merge
keys (#1162)
7a446b0d is described below
commit 7a446b0df13883cfd6751ff742e594974150a1ff
Author: JeonDaehong <[email protected]>
AuthorDate: Mon Oct 19 21:15:14 2026 +0900
[core] Reuse the key buffer and row list across sort-merge keys (#1162)
---
crates/paimon/src/table/sort_merge.rs | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/crates/paimon/src/table/sort_merge.rs
b/crates/paimon/src/table/sort_merge.rs
index 9bb072e2..e43e8698 100644
--- a/crates/paimon/src/table/sort_merge.rs
+++ b/crates/paimon/src/table/sort_merge.rs
@@ -1410,6 +1410,9 @@ fn sort_merge_stream(
// Output indices: (batch_buffer_idx, row_idx) for interleave.
let mut output_indices: Vec<(usize, usize)> =
Vec::with_capacity(batch_size);
+ // Reused for every key, so grouping allocates nothing per key.
+ let mut winner_key: Vec<u8> = Vec::new();
+ let mut same_key_rows: Vec<MergeRow> = Vec::new();
loop {
let winner_idx = tree.winner();
@@ -1418,20 +1421,20 @@ fn sort_merge_stream(
break;
}
- // Capture the winner's key for grouping same-key rows.
- let winner_key = {
- let cursor = cursors[winner_idx].as_ref().unwrap();
- cursor.current_row().owned()
- };
+ // Capture the winner's key for grouping same-key rows. Encoded
+ // rows compare by their bytes, so byte equality is key equality.
+ let winner = cursors[winner_idx].as_ref().unwrap();
+ winner_key.clear();
+ winner_key.extend_from_slice(winner.current_row().as_ref());
// Collect all rows with the same key across all streams.
- let mut same_key_rows: Vec<MergeRow> = Vec::new();
+ same_key_rows.clear();
loop {
let current_winner = tree.winner();
let matches = match &cursors[current_winner] {
None => false,
- Some(c) => c.current_row().cmp(&winner_key.row()) ==
Ordering::Equal,
+ Some(c) => c.current_row().as_ref() ==
winner_key.as_slice(),
};
if !matches {
break;