Skip to content

fix: clear memory after emit all in count distinct - #24888

Merged
rluvaton merged 2 commits into
apache:mainfrom
rluvaton:release-memory-after-emit-all-in-count-distinct
Sep 3, 2026
Merged

fix: clear memory after emit all in count distinct#24888
rluvaton merged 2 commits into
apache:mainfrom
rluvaton:release-memory-after-emit-all-in-count-distinct

Conversation

@rluvaton

@rluvaton rluvaton commented Sep 2, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

after emit all, the memory is still being held in count distinct causing OOM issues

What changes are included in this PR?

release memory in emit all and added tests

What is the testing strategy for this PR?

integration test

Are there any user-facing changes?

no


Founded while running:

@github-actions github-actions Bot added core Core DataFusion crate functions Changes to functions implementation labels Sep 2, 2026
@rluvaton rluvaton changed the title fix: clear memory after emit all fix: clear memory after emit all in count distinct Sep 2, 2026
@codecov-commenter

codecov-commenter commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.63%. Comparing base (d2b626c) to head (5bc99b6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24888   +/-   ##
=======================================
  Coverage   81.63%   81.63%           
=======================================
  Files        1123     1123           
  Lines      409537   409541    +4     
  Branches   409537   409541    +4     
=======================================
+ Hits       334308   334329   +21     
+ Misses      55594    55572   -22     
- Partials    19635    19640    +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kumarUjjawal kumarUjjawal 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.

Looks good 👍

@rluvaton
rluvaton added this pull request to the merge queue Sep 3, 2026
Merged via the queue into apache:main with commit 7e5561d Sep 3, 2026
38 checks passed
@rluvaton
rluvaton deleted the release-memory-after-emit-all-in-count-distinct branch September 3, 2026 06:13
rluvaton added a commit to rluvaton/datafusion that referenced this pull request Sep 3, 2026
…ons (apache#24918)

## Which issue does this PR close?

Follow-up to apache#24888, which broke the `cargo test hash collisions` CI job
on main.

## Rationale for this change

The memory limit test added in apache#24888 fails when built with
`force_hash_collisions`. Every key hashes to the same value there, so
the hash repartition sends all 64 groups to one final stage. That single
table needs 5.3 MB against the test's 4 MB pool, and it has nothing
reserved yet, so there is nothing to spill. It fails no matter how well
the accumulator releases memory, which is what the test is actually
about.

I tried a few ways to keep it running under the feature first:

- **Bigger limit for the collision build.** Below 5.3 MB it dies on that
one state batch; at 6 MB and up nothing spills, so the unfixed
accumulator passes too and the test asserts nothing. Nothing in between.
- **Single partition, no repartition at all.** Same wall. With 64 groups
the whole distinct state lives in 64 rows, so total state and one batch
are the same 5.3 MB. Also 82s instead of 0.18s.
- **More groups, to spread the state over more batches.** With every key
in one hash bucket, interning goes quadratic: 4096 groups did not finish
in 400s.
- **More rows (800k), to make total state exceed one batch.** Fails even
with the fix.

They all hit the same thing: under forced collisions the total state and
a single batch are the same size, and the pool would have to sit above
one and below the other.

## What changes are included in this PR?

The test and its helpers move into a module gated on `not(feature =
"force_hash_collisions")`.

## What is the testing strategy for this PR?

`cargo test -p datafusion --features force_hash_collisions --test
core_integration count_distinct_releases` runs 0 tests. Without the
feature it still runs and passes.

## Are there any user-facing changes?

No.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants