Skip to content

Pin the adaptive aggregator freeze threshold in 05234_query_plan_aggregation_having_prefilter_results - #123653

Merged
nihalzp merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-05234-having-prefilter-pin-adaptive-aggregator
Oct 3, 2026
Merged

nihalzp merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-05234-having-prefilter-pin-adaptive-aggregator

Conversation

@groeneai

@groeneai groeneai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120510

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Test-only change, no changelog entry required.

Description

The test I added in #120510 failed in Stateless tests (amd_debug, distributed plan, s3 storage, parallel) with
05234ap_on 0 instead of 20000, and on the runner's reruns with Code: 395 ... boom from the throwIf cell.
The runner's diagnosis named --index_granularity 1652:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118242&sha=4155fc96c5f98a316def85a946ff9fd6a885315d&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29

On a remote disk the concurrent-read thresholds default to 0, so the 61 marks of the 100000-row fixture are read in
8 streams. That admits the adaptive aggregator, and each thread holds about 12500 keys, under its 16384-key freeze
threshold. A table that never freezes skips the two-level conversion, so the final merge is single-level and the
HAVING pre-filter, which acts only in the two-level bucket conversion, never runs. The file's two-level pins do not
cover that gate. In the failing job's query_log, all 96 reruns at 61 marks froze no table.

The test now sets adaptive_aggregator_freeze_threshold = 0 next to the other pins. Every adaptive table then
freezes on its first block, so the pre-filter acts on the adaptive path too, whatever the read split. The reference
is unchanged.

Validation, debug build, same binary for both arms:

  • Local disk forced to 8 streams: 10/10 runs fail before, 0/30 after (8 tables frozen, 20000 groups skipped every
    run); 0/100 with 4 copies in parallel; 0/30 with the freeze threshold set out of reach on the client.
  • s3-backed server, only index_granularity = 1652, 4 copies in parallel: 14/40 fail before, 0/80 after.
  • Randomized runs pass on local disk (45/45), with the concurrent-read thresholds forced to 1 (64/64) and on s3
    (53/53); 16 of them took the adaptive path.

Workflow [PR]
Sync PR [sync-upstream/pr/123653]

Version info

  • Merged into: 26.10.1.1403-master (included in 26.10 and later)

…g_prefilter_results

The statistics cells of the test failed in `Stateless tests (amd_debug, distributed plan,
s3 storage, parallel)` with `05234ap_on 0` instead of 20000, and on reruns with
`Code: 395 ... boom` from the `throwIf` cell (client rc 139 = 395 & 0xFF), under
`--index_granularity 1652`.

On a remote disk `merge_tree_min_{rows,bytes}_for_concurrent_read_for_remote_filesystem`
default to 0, so min marks per read task is `merge_tree_min_read_task_size` = 8 and the
61 marks of `having_prefilter_wide` at that granularity are read in 8 streams. More than
one stream admits the adaptive aggregator, and each thread holds about 12500 keys, under
`adaptive_aggregator_freeze_threshold` (16384). A table in the learning phase skips the
two-level conversion, and with no freeze in the session the finish step does not convert
either, so every table ends single-level despite `group_by_two_level_threshold*` and
`max_bytes_before_external_group_by`. The HAVING pre-filter is honoured only in the
two-level bucket conversion, so nothing is skipped and the `throwIf` conjunct sees the
rejected groups. A thread that happens to cross the threshold (work stealing) freezes a
table and rescues the run, which is why it is frequent rather than certain on s3.

Pinning `enable_adaptive_aggregator = 0` removes the one unpinned gate on the path the
cells measure, so they run on the two-level conversion for any read split, multi-stream
reads included. The reference is unchanged.

Measured on a debug build, same binary for both arms: local disk forced to the remote
split (61 marks, 8 streams) 20/20 fail before and 0/20 after; with the freeze threshold
out of reach 20/20 and 0/20, and the fix without the new SET fails 20/20; an s3-backed
server with only index_granularity 1652 and 4 runs in parallel 29/40 and 0/40. Every
failing run froze no table, every passing base run froze one. 50/50 randomized runs pass
on local disk and on s3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 3, 2026
@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own review of the diff (no blocker or major finding).

# Sev Finding Verdict Evidence / action
1 💡 AggregatingStep::transformPipeline in the touched test comment is not an inline code span (05234_query_plan_aggregation_having_prefilter_results.sql:23) AGREE comment formatting only, noted, not blocking

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261003-052200

@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The unmodified test run with --index_granularity 1652 --merge_tree_min_rows_for_concurrent_read 1 --merge_tree_min_bytes_for_concurrent_read 1 --max_threads 8 (the remote-disk stream split on a local disk) fails 20/20, and 20/20 with the adaptive freeze threshold raised out of reach. On an s3-backed server with only index_granularity = 1652, 4 runs in parallel: 29/40.
b Root cause explained? Remote-disk concurrent-read thresholds are 0, so 61 marks are read in 8 streams; the adaptive aggregator is admitted and no thread reaches its 16384-key freeze threshold; an unfrozen table skips the two-level conversion, so the merge is single-level and the HAVING pre-filter (two-level bucket conversion only) never acts: skip count 0, or throwIf evaluated on rejected groups (Code: 395). Every failing run has 0 freezes, every passing one has 1.
c Fix matches root cause? Yes. It pins the one unpinned gate on the two-level path the cells measure (enable_adaptive_aggregator = 0), next to the existing two-level pins. No bound widened, no tag, no data reduced.
d Test intent preserved / new tests added? Yes. All cells keep their values and the reference is unchanged; they now run on the two-level path under multi-stream reads as well (61 marks, 10 to 23 threads). Test-only change, so no new test is owed.
e Both directions demonstrated? Yes, same binary: local forced split 20/20 fail before, 0/20 after; freeze out of reach 20/20 and 0/20; fix minus the new SET 20/20 fail; s3 parallel 29/40 and 0/40.
f Fix is general across code paths? N/A (test-only). Every cell of the file checked: String-key cells fixed, LowCardinality cells already safe (adaptive rejects them), *_off cells expect 0 either way. 05218_query_plan_aggregation_having_prefilter needs no change and passes.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). 50/50 randomized runs pass on local disk and on s3, covering max_threads 1/2/3/32 and 2 to 142 marks.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, default or behaviour changes outside the test.
i Invariants and contracts preserved? Yes. The file's premise, that the statistics cells run on the two-level bucket conversion, now holds for every read split; the results-only pairs are unaffected.

Session id: cron:clickhouse-impl-slot-40:20261003-045600

@clickhouse-gh

clickhouse-gh Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b4444e7]

Summary: ✅


AI Review

Summary

This PR updates tests/queries/0_stateless/05234_query_plan_aggregation_having_prefilter_results.sql to pin adaptive_aggregator_freeze_threshold = 0 instead of disabling enable_adaptive_aggregator, which keeps coverage of the adaptive GROUP BY path while making the remote-disk multi-stream case deterministic. The current code matches the stated root cause, the setting semantics explicitly guarantee an immediate freeze at 0, and I did not find any remaining correctness, coverage, or metadata issues in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 3, 2026
@groeneai
groeneai requested a review from nihalzp October 3, 2026 05:39
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 3, 2026
@nihalzp nihalzp self-assigned this Oct 3, 2026
Disabling `enable_adaptive_aggregator` for the file kept the statistics cells stable, but it also
took the HAVING pre-filter off the adaptive `GROUP BY` path, which multi-stream reads of the
fixtures (remote disks, small `index_granularity`) are the only cells to reach.

`adaptive_aggregator_freeze_threshold = 0` keeps that path and makes it deterministic: every
adaptive table freezes on its first block, so the session converts to two-level at the finish
and the pre-filter acts, exactly as when a table crosses the threshold on its own.

Measured on the same debug build: local disk forced to 8 streams, 0/30 fail with 8 tables frozen
and 20000 groups skipped on every run, 0/100 with 4 copies in parallel, 0/30 with the freeze
threshold set out of reach on the client; the pre-fix file fails 10/10 there. s3-backed server
with `index_granularity = 1652`, 4 copies in parallel: 14/40 fail before, 0/80 after, 7 tables
frozen per run. Randomized runs pass on local disk (45/45), with the concurrent-read thresholds
forced to 1 (64/64, 6 on the adaptive path) and on s3 (53/53, 10 on the adaptive path). With the
freeze pin, the result cells on a multi-stream read now also compare answers with the pre-filter
skipping groups on the adaptive path, where they previously compared two runs that skipped none.

Also wrap `AggregatingStep::transformPipeline` in the comment above as inline code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Pin the adaptive aggregator off in 05234_query_plan_aggregation_having_prefilter_results Pin the adaptive aggregator freeze threshold in 05234_query_plan_aggregation_having_prefilter_results Oct 3, 2026
@nihalzp
nihalzp enabled auto-merge October 3, 2026 07:51
@nihalzp
nihalzp added this pull request to the merge queue Oct 3, 2026
Merged via the queue into ClickHouse:master with commit d96121c Oct 3, 2026
160 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
@clickhouse-gh clickhouse-gh Bot added comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants