Repository navigation
fix: don't double count column join keys in SortMergeJoinExec buffered batch reservation - #27346
Open
Kristofferjoha wants to merge 2 commits into
Open
Kristofferjoha wants to merge 2 commits into
Kristofferjoha wants to merge 2 commits into
Conversation
vinycalves
reviewed
Nov 12, 2026
vinycalves
left a comment
There was a problem hiding this comment.
Two logic questions; no code suggestions.
There was a problem hiding this comment.
Does the new test cover a computed join key and the spill/read-back path, where the key array is actually unshared? When a batch spills, does the reservation still avoid double-counting buffers shared with the key arrays?
Contributor
Author
There was a problem hiding this comment.
Thanks, added a test which covers a computed key and the spill/read-back path. On spill the batch is dropped, so only the key arrays stay in memory and they’re counted once.
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
BufferedBatch::try_newreservesbatch.get_array_memory_size()plus the size of each evaluated join key array. For a column key, the key array is the batch's own column, so that column is counted twice. Joins on wide string keys reserve about twice what they hold, and spill or fail under a memory limit earlier than they should.What changes are included in this PR?
BufferedBatch::try_newonly charges key buffers the batch doesn't already hold, usingRecordBatchMemoryCounter.With the repro from the issue both queries now report 19.5 MB (was 38.8 MB and 19.7 MB).
What is the testing strategy for this PR?
Added
column_join_key_not_double_counted, which checks thatpeak_mem_usedis the same for an int key and a string key over the same data.Updated the expected
peak_mem_usedinexplain_analyze.slt(432 B -> 288 B) and the size formula in three existing spill tests.The re-evaluation on restore is not covered by a test.
Are there any user-facing changes?
No.