Repository navigation
Fix max_bytes_in_distinct / max_bytes_in_set: count string keys stored in the arena - #110120
Merged
Merged
Conversation
…d in the arena Symptom: with string keys, the byte limits only tripped once the ~24-bytes-per-key hash buffer crossed the limit, because SetVariantsTemplate::getTotalByteCount() returned only the buffer size while the key payload lives in the string_pool arena. DISTINCT / IN could hold memory exceeding the limit by the whole payload, unbounded in the key length (measured: 139 MB retained under a 10 MB 'break' limit; a ~100 MB state under 'throw' never raised). Root cause: the declaration comment documents that the string pool must be counted, but the implementation never included it. Fix: add string_pool.allocatedBytes(), following the HashJoin::getTotalByteCount() pattern used for max_bytes_in_join. Fixed-size keys are unaffected. Verification: new stateless test fails without the fix (nothing trips) and passes with it, 5/5 runs; existing overflow-mode tests pass. Remaining risk: queries with string keys near a byte limit now trip it earlier (at the documented boundary) - intended behavior change.
Contributor
|
Workflow [PR], commit [c905bc3] Summary: ✅
AI ReviewSummaryThis PR fixes the undercount in Final Verdict✅ No blocking issues found. |
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 7/8 (87.50%) · Uncovered code |
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…ring-pool Fix max_bytes_in_distinct / max_bytes_in_set: count string keys stored in the arena
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
max_bytes_in_distinctandmax_bytes_in_set: string keys are stored in an arena that was not counted by the limit checks, so DISTINCT / IN over string keys could hold memory exceeding the byte limit by the whole key payload (unbounded in the key length). The limits now account for the arena, matching their documentation; queries with string keys close to a byte limit may now trip it earlier (correctly).Documentation entry for user-facing changes
The fixed behavior matches the existing documentation:
max_bytes_in_set— "The maximum number of bytes (of uncompressed data) used by a set in the IN clause"; thegetTotalByteCount()declaration comment also documents that the string pool must be counted. No docs changes needed.Symptom.
SetVariantsTemplate::getTotalByteCount()returns only the hash-table buffer size (data.getBufferSizeInBytes()). For string keys, every consumer —DistinctTransform,DistinctSortedTransform,DistinctSortedStreamTransform, andSet(IN) — copies the key payload into thestring_poolarena, which was not counted. The byte limits only tripped once the ~24-bytes-per-key hash buffer itself crossed the limit:Found while working on #110075 (an orthogonal defect: that PR fixes what happens when a DISTINCT limit trips; this PR fixes the byte limit not tripping for string keys). Surfaced by the AI review there.
Root cause. The declaration comment on
getTotalByteCount()documents the intended contract — "Counts the size in bytes of the Set buffer and the size of thestring_pool" — but the implementation never included the pool.Fix.
getTotalByteCount()now addsstring_pool.allocatedBytes(), following the established pattern ofHashJoin::getTotalByteCount(), which includesdata->pool.allocatedBytes()formax_bytes_in_join. Fixed-size keys are unaffected (the arena stays at its initial allocation and is dwarfed by the hash buffer).Behavior change. Queries with string keys running close to
max_bytes_in_distinct/max_bytes_in_setwill now trip the limit earlier — at the documented boundary instead of an under-counted one. With the repro above:breaknow stops at 8192 rows instead of 139264; boththrowcases now raiseSET_SIZE_LIMIT_EXCEEDEDwith honest byte counts (17.48 MiB / 69.98 MiB vs the 9.54 MiB limit).Verification.
04512_max_bytes_limits_count_string_arena: DISTINCT throw/break and IN throw over ~1 KB string keys where the hash buffer alone stays under the limit — fails without the fix (nothing trips), passes with it; plus a fixed-size-key control query pinning that numeric DISTINCT under the same limit is unaffected.sedscripting is GNU-only — both environment, covered by CI here).Version info
26.7.1.974(included in26.7and later)