Skip to content

[Improvement] Avoid per-key allocations in sort merge #1161

Closed

Description

@JeonDaehong

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

sort_merge_stream allocates for every primary key it merges: current_row().owned() for the winner key and a new Vec<MergeRow> for the rows sharing it. Both can be reused across keys. Encoded rows compare by their bytes, so the key check can compare against a reused byte buffer.

On a primary-key table with 2M keys written three times (6M input rows, 4 files per round, memory FileIO, c7i.4xlarge, release build), a full read goes from 463 ms to 427 ms, about 8%, with and without deletion-vectors.merge-on-read. Six alternating runs each, ranges don't overlap.

Solution

Keep the key buffer and the row list outside the loop and clear them per key.

Anything else?

No response

Willingness to contribute

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions