Repository navigation
Reserve the size of the spilled table for external GROUP BY, not the query memory - #130144
Conversation
…query memory A thread over `max_bytes_before_external_group_by` reserved the memory usage of the whole query for its temporary file, so with N threads the query asked for N times its memory, and a disk with room for the data refused the spill with NOT_ENOUGH_SPACE. The reservation is only a preallocation, so the table's own memory (its tracker, or `allocatedBytes` for a merging aggregator) is enough, as `Aggregator::spill` does. Adaptive aggregation (on by default) spills staged records on its own path and was not affected, which is why the issue did not reproduce with it. Closes: ClickHouse#80631 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [8dfa269] Summary: ❌
AI ReviewSummaryReviewed #130144 at PR MetadataThe changelog entry is required, present, and specific about the affected behavior. No migration guidance is needed. The category correction is listed below. Findings💡 Nits
Final Verdict✅ Approve — no blocking changes requested; only the changelog-category correction is suggested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 109 s compile time in total, 7 of them have a recent master baseline. |
6e9466a
The test asserts that every reservation of an external GROUP BY is below `max_bytes_before_external_group_by`, but with `GROUP BY number` the query memory is the sum of the per-thread tables. The spill check reads the query memory once per block, and the buckets of a two-level table grow x4 within a block or two, so a thread that gets most of the `numbers_mt` blocks can take its table from 64 MiB to 252 MiB before the check fires; since ClickHouse#130144 that table size is what gets reserved, and it is above the 128 MiB threshold. With `max_threads = 1` every reservation is 252.54 MiB. Keep the assertion and change the workload: the set of `NOT IN (SELECT number + 10000000 FROM numbers(5000000))` (pinned in memory with `max_bytes_before_external_set = 0` and `max_bytes_ratio_before_external_set = 0`) keeps the query over a 32 MiB threshold, and the key `number % toUInt64(1000)` bounds every table to 1000 keys (~1 MiB), so every block spills a small table whatever the scheduling. The key must be `UInt64`: a `UInt16` key is aggregated with `key16`, a fixed hash map that is never spilled. Measured with master CI binaries: with ClickHouse#130144 (f9e6c60) the largest reservation over 130 runs is 1.10 MiB (plain, one CPU, 24 concurrent copies, thread fuzzer); without it (b90a90b, the merge's first parent) the smallest is 135 MiB and the test fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reserve the size of the spilled table for external GROUP BY, not the query memory
A thread over
max_bytes_before_external_group_byreserved the memory usage of the whole query for its temporary file, so with N threads the query asked for N times its memory, and a disk with room for the data refused the spill with NOT_ENOUGH_SPACE. The reservation is only a preallocation, so the table's own memory (its tracker, orallocatedBytesfor a merging aggregator) is enough, asAggregator::spilldoes.Adaptive aggregation (on by default) spills staged records on its own path and was not affected, which is why the issue did not reproduce with it.
Closes: #80631
Workflow [PR]
Sync PR [sync-upstream/pr/130144]
Version info
26.11.1.1859-master(included in26.11and later)