Skip to content

[core] Reuse the key buffer and row list across sort-merge keys - #1162

Merged
JingsongLi merged 1 commit into
apache:mainfrom
JeonDaehong:perf-sort-merge-alloc
Oct 19, 2026
Merged

JingsongLi merged 1 commit into
apache:mainfrom
JeonDaehong:perf-sort-merge-alloc

Conversation

@JeonDaehong

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #1161

Brief change log

sort_merge_stream reuses one key buffer and one Vec<MergeRow> across keys instead of allocating an OwnedRow and a Vec per key. The same-key check compares the encoded row bytes, which is what Row's Ord compares.

PK table, 2M keys written three times, full read: 463 ms → 427 ms (about 8%), with or without DV merge-on-read. Six alternating runs each, no overlap.

Tests

No behavior change; covered by the existing sort-merge and merge engine tests.

Ran the ci.yml steps locally (fmt, clippy, msrv, unit, rest-server, integration, datafusion, python, go).

API and Format

None.

Documentation

None.

sort_merge_stream allocated an OwnedRow and a Vec for every primary key it
merged. Both are now reused across keys. Encoded rows compare by bytes, so
the key check compares the copied bytes directly.
@JeonDaehong

Copy link
Copy Markdown
Contributor Author

@JingsongLi @leaves12138 a small one for the sort-merge read path when you get a chance, numbers are in the description.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@JingsongLi
JingsongLi merged commit 7a446b0 into apache:main Oct 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Avoid per-key allocations in sort merge

2 participants