Repository navigation
fix: reserve initial table memory in aggregate streams - #25900
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #25900 +/- ##
==========================================
- Coverage 82.59% 82.59% -0.01%
==========================================
Files 1144 1144
Lines 441832 441960 +128
Branches 441832 441960 +128
==========================================
+ Hits 364942 365016 +74
- Misses 54814 54844 +30
- Partials 22076 22100 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Weijun-H
approved these changes
Sep 30, 2026
Omega359
pushed a commit
to Omega359/arrow-datafusion
that referenced
this pull request
Oct 11, 2026
## Which issue does this PR close? None ## Rationale for this change pre allocated memory and held memory should be counted ## What changes are included in this PR? reserve the hash table memory on creation, similar to what was already done in: - apache#24692 ## What is the testing strategy for this PR? added unit tests ## Are there any user-facing changes? No
comphead
added a commit
to comphead/arrow-datafusion-comet
that referenced
this pull request
Nov 15, 2026
CometFairMemoryPool limited each consumer that can spill to (task_share - unspillable) / num_spill, where num_spill counted every registered consumer that can spill. DataFusion registers each operator's consumer when it builds the stream tree, before any batch flows, so the operators above a blocking one counted while they held nothing. A sort below a window and four aggregates was held to a sixth of the task's share and spilled while most of it was unused. Count only the active consumers that can spill, plus the one asking. A consumer is active while it holds more than its low-water mark, the least it has held since its first reservation, because from DataFusion 56 an aggregate reserves its initial table when the plan starts (apache/datafusion#25900). The task's total is still checked against the task's share, so a consumer that starts later is refused until the others give memory back. A sort below an OrderedFinalAggregateStream, which apache#7096 held to half of the share, can now fill the share while the aggregate is idle. It gives part of that back before the aggregate's first request, which a test checks with the share set to the sort's own peak. The apache#6880 test of a PartialMerge over a sort-merge join used a 16 MiB pool because the sorts below the join got a fraction of it. They now get the whole share while they read, so it uses 2 and 8 MiB, like its sibling test. Closes apache#7628.
Abhishek-Mohan
pushed a commit
to Abhishek-Mohan/datafusion-comet
that referenced
this pull request
Nov 18, 2026
…7630) * fix: divide fair_unified's task share among active consumers CometFairMemoryPool limited each consumer that can spill to (task_share - unspillable) / num_spill, where num_spill counted every registered consumer that can spill. DataFusion registers each operator's consumer when it builds the stream tree, before any batch flows, so the operators above a blocking one counted while they held nothing. A sort below a window and four aggregates was held to a sixth of the task's share and spilled while most of it was unused. Count only the active consumers that can spill, plus the one asking. A consumer is active while it holds more than its low-water mark, the least it has held since its first reservation, because from DataFusion 56 an aggregate reserves its initial table when the plan starts (apache/datafusion#25900). The task's total is still checked against the task's share, so a consumer that starts later is refused until the others give memory back. A sort below an OrderedFinalAggregateStream, which apache#7096 held to half of the share, can now fill the share while the aggregate is idle. It gives part of that back before the aggregate's first request, which a test checks with the share set to the sort's own peak. The apache#6880 test of a PartialMerge over a sort-merge join used a 16 MiB pool because the sorts below the join got a fraction of it. They now get the whole share while they read, so it uses 2 and 8 MiB, like its sibling test. Closes apache#7628. * test: pin the count(DISTINCT) chain and the merge reservation for the fair pool Restore the count(DISTINCT) chain test, so a DataFusion bump that changes how much the lower aggregate frees fails a test instead of a query. Run the ordered final aggregate test with DataFusion's default merge reservation and with 1024 groups per batch, and check that the task's total keeps the bytes of a consumer that reserved only once. Say that the sort frees its merge reservation before emitting, and move the memory pool note to the 1.3.0 migration section, since apache#7096 is not in 1.2.0. * fix: keep a share in fair_unified for sorts that have not started DataFusion 55.2's ExternalSorter fails with "Not enough memory to continue external sort" when its first request is refused, since it has nothing to spill yet. A hash aggregate below a sort keeps its output reserved until it has emitted all of it, and emits slices whose buffers the sort is charged for in full. With idle consumers taking no share, the aggregate could fill the task's share and fail the sort above it. A sort that has registered but not reserved now takes a share from every consumer that can spill except another sort, so the aggregate below it is held to half, as before apache#7628's fix. A sort below another sort is not, because a sort gives memory back before it emits and emits compact batches. A test runs a sort above a final and a single aggregate at 100% to 200% of the aggregate's own peak. CometTaskMetricsSuite's child-sort spill test now uses a smaller pool, since the idle shuffle writer above the sort no longer takes half of it.
andygrove
added a commit
to apache/datafusion-comet
that referenced
this pull request
Nov 21, 2026
The merge brought in tests written against DataFusion 55.2: - Field::with_metadata takes impl Into<Metadata> in Arrow 60, so pass the array of pairs directly. - AggregateExec::input_order_mode is now group_clustering_mode, and a fully sorted input is GroupClusteringMode::Full. - Two #7630 fair pool tests set the task share to exactly the peak of the lowest operator. DataFusion 56 has each aggregate reserve its initial table when the plan starts (apache/datafusion#25900), so the aggregates above hold a few KiB while it runs, and the sort or first aggregate spilled. Add what the aggregates above reserve over empty input to the share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
None
Rationale for this change
pre allocated memory and held memory should be counted
What changes are included in this PR?
reserve the hash table memory on creation, similar to what was already done in:
What is the testing strategy for this PR?
added unit tests
Are there any user-facing changes?
No