Repository navigation
Conversation
Under memory pressure the Partial aggregate emits its groups early and continues with an empty table. The skip probe then paired the cumulative input rows with only the groups since the last emit, so it stayed below the ratio threshold even for unique keys and the stream kept hashing. Count the groups emitted early and pass them to the probe together with the groups still in the table, in both `PartialHashAggregateStream` and the legacy `GroupedHashAggregateStream`. Closes apache#27350
vinycalves
reviewed
Nov 12, 2026
vinycalves
left a comment
There was a problem hiding this comment.
One logic question; no code suggestions.
There was a problem hiding this comment.
Could counting early-emitted groups make the probe skip a low-cardinality query before later duplicates reduce it? Is there a test for that?
Contributor
Author
There was a problem hiding this comment.
good question. I was actually thinking about the same yesterday, what would happen if high cardinality groups come first and break the pattern, planning to resume this today
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?
Rationale for this change
Under memory pressure the Partial aggregate emits its groups early and continues with an empty table. The skip probe then compared all input rows with only the groups since the last emit, so it stayed below
skip_partial_aggregation_probe_ratio_thresholdeven for unique keys. The query sends the same rows downstream either way, but spends several times the Partial CPU hashing them.What changes are included in this PR?
PartialHashAggregateStreamand the legacyGroupedHashAggregateStreamcount the groups they emit early and pass them toSkipAggregationProbetogether with the groups still in the table. The sum is the output row count so far, so the probe measures the reduction the Partial actually achieves.What is the testing strategy for this PR?
test_partial_aggregation_skips_after_early_emitsruns both streams over unique keys with a memory limit that forces early emits before the probe threshold. Onmainboth skip 0 rows.datafusion-cliwith the query from the issue (2M unique keys,target_partitions = 2),AggregateExec: mode=Partial, 3 runs:mainemits / skipped / CPUmemory_limit = '4M'-m 16M --mem-pool-type fairWith 20M rows over 200K keys, 8 partitions and a fair 32M pool, Partial CPU drops from 345 ms to 46 ms. Queries that still reduce well under memory pressure (20K or 2K keys) keep aggregating.
Are there any user-facing changes?
No API changes. Memory-limited queries over high-cardinality keys now skip partial aggregation, as they already do without a limit.