Skip to content

Fix OneSideHashJoiner memory size accounting - #24744

Merged
jayzhan211 merged 3 commits into
apache:mainfrom
kosiew:memcalc-04-23393
Aug 29, 2026
Merged

Fix OneSideHashJoiner memory size accounting#24744
jayzhan211 merged 3 commits into
apache:mainfrom
kosiew:memcalc-04-23393

Conversation

@kosiew

@kosiew kosiew commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

OneSideHashJoiner::size() can overcount memory by adding inline fields that are already included in the joiner descriptor, while its previous HashSet<usize> estimate only accounted for element payload capacity and omitted hashbrown control/metadata allocation.

This change defines the component-level accounting contract more explicitly so the joiner descriptor is counted once and directly owned container allocations are included using their actual allocation-aware helpers where available.

What changes are included in this PR?

  • Document the OneSideHashJoiner::size() contract as including the joiner descriptor, directly owned container allocations, and input arrays, while excluding allocations referenced by shared on expressions.
  • Remove double counting of inline fields already covered by size_of_val(self).
  • Account for the on vector's owned backing allocation using its capacity.
  • Adjust PruningJoinHashMap accounting so its descriptor is not counted twice.
  • Replace the visited_rows payload-only capacity calculation with allocation_size(), which accounts for the hashbrown allocation layout, including control bytes.
  • Add regression coverage for empty and grown visited_rows states and for the owned on, hash map, and hashes-buffer allocations.
  • No transformer composition or shared-record-batch accounting is changed.

Are these changes tested?

Yes. This PR adds the focused unit test:

one_side_hash_joiner_size_counts_descriptor_and_hash_set_allocation_once

The test checks the explicit expected size formula for an empty joiner, verifies visited_rows allocation accounting across capacity growth, and verifies that owned container allocation changes are reflected without double-counting descriptors.

Are there any user-facing changes?

No public API or query-result behavior changes are introduced.

This changes internal memory-size accounting for OneSideHashJoiner, making its reported size more consistent with the documented ownership contract.

LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed.

kosiew added 2 commits August 28, 2026 12:11
…uble counting

- Updated `OneSideHashJoiner::size()` to be self‑inclusive, eliminating inline double counts.
- Refined counting logic to be based on `Vec` capacity.
- Utilized `hashbrown::HashSet::allocation_size()` which includes control bytes.
- Added tests covering empty and grown `visited_rows` scenarios.
- No transformer changes.
- The test incrementally inserts elements into `hashes_buffer` via the hashmap to verify that the map expands correctly as it fills.
- It asserts that the internal capacities increase as expected and checks the exact size delta after each insertion to ensure no gaps or overruns.
- The test accounts for a preexisting zero‑capacity map estimate baseline, guaranteeing correct behavior even when the map starts with no allocated capacity.
@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Aug 28, 2026
@codecov-commenter

codecov-commenter commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.47%. Comparing base (d1fc4b3) to head (ae68419).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24744   +/-   ##
=======================================
  Coverage   81.47%   81.47%           
=======================================
  Files        1122     1122           
  Lines      403582   403675   +93     
  Branches   403582   403675   +93     
=======================================
+ Hits       328821   328905   +84     
  Misses      55512    55512           
- Partials    19249    19258    +9     

☔ 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.

@kosiew
kosiew marked this pull request as ready for review August 28, 2026 07:14
@kosiew
kosiew requested a review from comphead August 28, 2026 07:14

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

Thanks @kosiew LGTM

@jayzhan211
jayzhan211 added this pull request to the merge queue Aug 29, 2026
Merged via the queue into apache:main with commit dd77ffc Aug 29, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants