apache / apache/datafusion

Limit the max merge degree during re-spill in external sort

Open
#16,908 1 comment 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

This is a follow-up to: https://github.com/apache/datafusion/pull/15700
Part of https://github.com/apache/datafusion/issues/15271

#15700 introduces a comprehensive approach for external sorts: if it's not possible to do the merge for all spills in one pass, it will merge as many spills as possible, do a re-spill, and iterate until we can produce the final output at once.
Note it is also use estimations for the memory accounting, under extreme edge cases this estimation can be inaccurate, causing the actual memory usage larger than the configured memory limit.

To prevent such unintentional cases and to enable performance tuning (merging a smaller number of batches at once is more cache-friendly/faster), we can introduce a additional configuration option:
`max_merge_degree: Maximum number of streams to merge during re-spills in external sorts`

The original context: https://github.com/apache/datafusion/pull/15700#issuecomment-3034804482

### Describe the solution you'd like

This previous attempt can be used as the reference for the solution: https://github.com/apache/datafusion/pull/15610
It has to be re-structured to build upon #15700

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reading PR #15700 to understand the current external-sort re-spill flow, then compare the previous attempt in PR #15610. Add the max_merge_degree configuration described in the issue so re-spills limit the number of merged streams while still producing the final output correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
data-engineering, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.