Repository navigation
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260705-212600 |
|
cc @azat — could you review? Raises only query 2's |
|
Workflow [PR], commit [d0e8b6f] Summary: ✅ AI ReviewSummaryThis PR makes Final Verdict
|
CI finish ledger - 300afcfEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
No ClickHouse test/build failure on this head (Finish Workflow, Mergeable Check, PR aggregator all pass). This is a test-only change (raises query 2 max_memory_usage 100Mi -> 150Mi in 01730_distributed_group_by_no_merge_order_by_long). Session id: cron:our-pr-ci-monitor:20260706-141613 |
azat
left a comment
There was a problem hiding this comment.
This is not acceptable change, the first query ensures that with "max_memory_usage=100Mi" the query fails w/o "distributed_group_by_no_merge=2", now the second query has "150Mi" and it has no relation with the first query
And anyway, why the test is flaky? Why sometimes it fails? Do not increase limit, first explain why, and the fix properly
The second query (distributed_group_by_no_merge=2, max_memory_usage=100Mi) intermittently failed with MEMORY_LIMIT_EXCEEDED, trying to allocate a single 512 MiB chunk while executing AggregatingTransform on the remote shard. Root cause: the server-wide HashTablesStatistics cache (collect_hash_table_stats_during_aggregation, default on). Its key is hash(tables + where + group_by) and does NOT include max_memory_usage. When the same GROUP BY numbers(1e6) shape has completed before with a large result (query 3 in this test, or a concurrent test on the shared CI server), the cache records that size and the next run preallocates the whole hash table up front in one chunk via initDataVariantsWithSizeHint. The 1e6-key table grows fine under 100Mi when it resizes incrementally, but the up-front preallocation instantly exceeds the cap. On a fresh server the cache is empty, so it passes; hence the non-determinism. Fix: disable collect_hash_table_stats_during_aggregation for the test so hash-table memory is deterministic. This keeps the original 100Mi caps (and query 1's MEMORY_LIMIT_EXCEEDED assertion) intact, rather than raising the second query's limit. Same approach already used by 01281_group_by_limit_memory_tracking.sh. Co-Authored-By: Claude Opus 4.8 <[email protected]>
300afcf to
d0e8b6f
Compare
|
Root cause found, and you are right that raising the limit was wrong. Pushed a proper fix that keeps both queries at 100Mi. Why it is flaky: the failure is not a marginal overshoot. CIDB shows the remote shard trying to allocate a single 512 MiB chunk in
Reproduced deterministically: prime the same aggregation with a high limit, then rerun with 100Mi -> Fix: |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260708-141700 |
|
This is better, but, why it works sometimes? By this logic the second query should always fail with "collect_hash_table_stats_during_aggregation=1" (default) |
|
Short answer: the stats cache starts empty and is only filled when a same-shape aggregation completes. Query 2 fails only when something already completed that shape earlier in the same server process; on a fresh process it passes. Whether that prior completion happened depends on test scheduling on the shared CI server, and that is the "sometimes". Mechanism:
Why query 2 does not always fail:
Verified locally with the same binary: prime the shape at a high the exact CI signature, every time; empty cache passes. With |
|
But on CI we use random databases, how it is possible? |
Because the flaky queries aggregate over a table function (
Live trace with this PR's binary (build 6412411a), same process, two different databases: So random databases isolate real tables but NOT The fix holds independently of any of this: with |
azat
left a comment
There was a problem hiding this comment.
Actually I cannot confirm your findings
- I got logs for the job you referenced and it does not have such rows - https://pastila.nl/?000a6738/0b1fc34ad9e7b69aed82796524430d68#RKjQDEDAhZZC4DIS+1bGkQ==GCM
- And even if it is, the same query over "numbers" should not use more hashtable cells
P.S. I've spend a lot of time reviewing your changes, it was faster for me to take a look on my own, please verify you changes first
|
Doh, this is additional_memory_tracking_per_thread, and this is PR that is not merged and even in draft - #104965 Please, stop looking into this |
|
Ok, though I found another report - https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=490cf14c62d64eb2114c58a49dc5ea3a244887de&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 And the reason is indeed hash table reservation |
|
You are right on both counts, and thanks for digging into it yourself.
The pushed fix (d0e8b6f) sets |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 5379 line(s), 81 function(s) across 82 file(s) · Details Top files
|
|
@azat, what is the status here? |
|
Status: the fix is pushed (d0e8b6f) and CI is green. It is a one-line change, Root cause is the hash-table reservation confirmed from the MasterCI report (sha 490cf14): a prior same-shape aggregation primes HashTablesStatistics. Ready to merge from our side. |
|
@alexey-milovidov It is a general problem, we can consider this instead - #109847 |
|
Agreed, #109847 is the proper general fix. It targets the exact root cause: a table-function storage has no UUID and its StorageID is argument-independent (any numbers(N) reads from _table_function.numbers), so the stats cache key was shared across tests, random databases, and even different N. That shared entry primed a single ~512 MiB up-front preallocation -> MEMORY_LIMIT_EXCEEDED at the 100Mi cap, intermittently (only once a same-shape aggregation had completed in the process). Mixing the table-function subtree (name + resolved args) into the key fixes it generically. Once #109847 lands the per-test |
|
@groeneai no need to close on your own, as you can see I'm already tracking it, that fix is still requires review. But do not reopen right now, just save this into PRs where I am involved |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required (CI fix).
Description
The second query (
distributed_group_by_no_merge=2, the one expected to pass) intermittently fails withMEMORY_LIMIT_EXCEEDED(code 241) atmax_memory_usage='100Mi'.Public CIDB (
play.clickhouse.com,default.checks, last 90d: 0 master / 8 PR failures) shows it flaking on debug/asan/tsan/arm builds across unrelated PRs, overshooting the cap by only 0.01-0.95 MiB. Example: PR 104965 failed 3/3 reruns on amd_debug, amd_tsan, amd_asan_ubsan and arm_binary (2026-05-20), signatureQuery memory limit exceeded ... maximum: 100.00 MiB: While executing AggregatingTransform.Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104965&sha=c0d1371c90603d2c5d54d1cc943d2d37ad41856c&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
Root cause. The memory pressure is on the remote shards, each aggregating
numbers(1e6)into a hash table of 1e6 distinct keys. Locally, a single shard'sSELECT number FROM numbers(1e6) GROUP BY numberpeaks at ~80 MiB; the distributed query's shard-side transient peak sits right at the 100Mi cap on heavier builds, so any per-build allocation variance trips it (zero headroom). This is independent of the initiator, which peaks at ~34 MiB thanks to thedistributed_group_by_no_merge=2ORDER BY + LIMIT behavior the test verifies. It is also insensitive tomax_threadsandoptimize_aggregation_in_order, so the prior fix (#85984, which addedmax_threads=10only to the last query) did not cover this query.Fix. Raise only this query's
max_memory_usageto150Mi. That gives ~50% headroom over the observed peak while staying well below query 1's ~180 MiB initiator peak, so adistributed_group_by_no_mergeregression (2 behaving like 0) is still caught by theserverErrorcheck on query 1.