Skip to content

Re-enable the adaptive aggregator for queries generated from PromQL - #131270

Merged
nihalzp merged 2 commits into
ClickHouse:masterfrom
groeneai:revert-128764-promql-adaptive-aggregator
Nov 13, 2026
Merged

nihalzp merged 2 commits into
ClickHouse:masterfrom
groeneai:revert-128764-promql-adaptive-aggregator

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Reverts #128764
Related: #129565

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Description

Re-enables the adaptive aggregator for the SQL generated from PromQL, as requested in #128764 (comment). #128764 turned it off as a workaround for the aggregator's staging regression on PromQL grid aggregations, which #129565 fixed. Only the enable_adaptive_aggregator override is removed: StoragePrometheusQuery::applySettingsForPrometheusQuery and its two call sites (the prometheusQuery* table functions and the Prometheus HTTP API) stay.

On the amd_release build of 414302af (the merge of #129565, still with #128764), SETTINGS enable_adaptive_aggregator = 1, which is what PromQL runs with after this change, vs = 0 takes 0.86..1.13x the time at 0.70..1.03x the peak memory for the six queries of the #128764 benchmark, on its three datasets, both samples tables and 4/16/64 threads, with the same results (sum by (job) (rate(m[5m])) up to float summation order).

On a debug build of this branch, system.query_log shows the aggregator's events (AdaptiveAggregationLocalFreezes and the others) for both prometheusQueryRange and /api/v1/query_range with no setting, SETTINGS enable_adaptive_aggregator = 0 still turns it off, and the results are unchanged. #128764 is in no release.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2261-master (included in 26.11 and later)

…ated from PromQL"

This reverts commit 4d76414 (ClickHouse#128764),
reversing changes made to 8886954.

ClickHouse#129565 fixed the staging of the adaptive aggregator that made the grid
aggregation of the SQL generated from PromQL slower, so that SQL can use
the aggregator again.

The conflict in the includes of PrometheusHTTPProtocolAPI.cpp is resolved
by keeping `Server/PrometheusMetricsWriter.h`, added later by ClickHouse#125250.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

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

Pre-publication review by an independent model (engine: codex; 2 findings; 1 full pass).

# Sev Finding Verdict Evidence / action
1 ⚠️ No test proves that the PromQL entry points engage the adaptive aggregator after the revert DISAGREE This is the literal revert that was requested; #128764 added no test either. Both directions were checked on both entry points (table function and /api/v1/query_range) with AdaptiveAggregation* ProfileEvents: 0 events before the revert, 4 freezes after it, = 0 still honoured.
2 ⚠️ The performance basis needs inspectable benchmark evidence DISAGREE Measured on the amd_release build of 414302af: 108 cells (6 queries, 3 datasets, both samples tables, 4/16/64 threads), 5 interleaved runs per side. One cell at 1.18x time (0 freezes on both sides) re-measured with 10 runs at 0.92x; split-half noise median 2.7%, p90 8.6%.

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

Session id: cron:clickhouse-review-slot-9:20261113-111301

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Debug server whose profile lowers adaptive_aggregator_freeze_threshold to 16, sum by (dc) (m) over 2000 series: before the revert the table function and /api/v1/query_range show 0 AdaptiveAggregation* events (an explicit SETTINGS enable_adaptive_aggregator = 1 shows 4 freezes, so the setup does trigger it); after it, both show 4 freezes / 188764 staged records with no setting.
b Root cause explained? StoragePrometheusQuery::applySettingsForPrometheusQuery (#128764) sets enable_adaptive_aggregator = false for the generated SQL unless the setting is changed. It worked around the staging regression that #129565 fixed, so it now only keeps PromQL off the aggregator.
c Fix matches root cause? Yes: a literal git revert -m 1 of #128764, as requested; no new mechanism.
d Test intent preserved / new tests added? No test added: #128764 added none and no PromQL test references the setting. 196 PromQL/TimeSeries stateless tests (also with adaptive_aggregator_freeze_threshold=0, 61 queries freezing) and 64 Prometheus integration tests, including evaluation against a real Prometheus, pass with the aggregator on.
e Both directions demonstrated? Yes, with the repro in (a) on both execution paths; = 0 still turns it off after the revert. Results identical between the two binaries (table-function hash equal, HTTP response byte-identical).
f Fix is general across code paths? Both callers of the helper are reverted (table functions, HTTP /api/v1/query*). /api/v1/series, /labels, /metadata, /federate never had the override.
g Fix generalizes across inputs (params/datatypes/wrappers)? Release A/B over 6 query shapes x 3 data shapes x both samples tables x 4/16/64 threads: 0.86..1.13x time, 0.70..1.03x memory, same results. enable_materialized_cte and empty_result_for_aggregation_by_empty_set are restored verbatim at both call sites.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, default or format change; returns PromQL to its behaviour before #128764, which is in no release.
i Invariants and contracts preserved? The generated SQL still runs on a copy of the context, so its settings stay isolated from the outer query; Context::createCopy keeps changed flags, so the restored changed check is equivalent. No locking or block-structure contract involved.

Session id: cron:clickhouse-impl-slot-7:20261113-100900

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [608ae3c]

Summary: ✅


AI Review

Summary

PR #131270 removes the PromQL-specific enable_adaptive_aggregator = 0 override while retaining applySettingsForPrometheusQuery and both callers. No actionable findings at 608ae3c009689c72899101ab917eb1860e567bc9. The reported validation covers both entry points, explicit opt-out, forced freezing, and result equivalence; the PR description supplies A/B timing and memory measurements.

Missing context / blind spots
  • ⚠️ CI for this head is still running. Runtime tests and benchmarks were not rerun locally; their results are author-reported.
Final Verdict

✅ Approve — no code changes requested. Pending CI should complete before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 13, 2026
@nihalzp nihalzp added the can be tested Allows running workflows for external contributors label Nov 13, 2026
@nihalzp nihalzp self-assigned this Nov 13, 2026
@nihalzp

nihalzp commented Nov 13, 2026

Copy link
Copy Markdown
Member

@vitlibar @nikitamikhaylov

@clickhouse-gh clickhouse-gh Bot added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Nov 13, 2026
@nihalzp
nihalzp added this pull request to the merge queue Nov 13, 2026
@vitlibar
vitlibar removed this pull request from the merge queue due to a manual request Nov 13, 2026
…or override

Restore the helper that ClickHouse#128764 introduced and its two call sites (the
prometheusQuery* table functions and the Prometheus HTTP API), and remove
only the part of it that disabled the adaptive aggregator, as asked in
review. The helper keeps setting `enable_materialized_cte` and
`empty_result_for_aggregation_by_empty_set` for the generated SQL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Revert "TimeSeries: Disable the adaptive aggregator for queries generated from PromQL" Re-enable the adaptive aggregator for queries generated from PromQL Nov 13, 2026
@vitlibar
vitlibar enabled auto-merge November 13, 2026 18:50
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 608ae3c00 with master 1c05c7af4 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.60, programs/clickhouse-keeper ×0.70 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.7 s 10.2 s +6.7 s (+197%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.3 s +5.3 s (+260%)
Compile time of recompiled translation units

7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master 1c05c7af4

Suite Baseline Current Delta
Prometheus compliance 100.00% 100.00% +0.00%
Extended support (upstream engine tests) 93.17% 93.17% +0.00%
Suite Passed Failed Unsupported
Prometheus compliance 539 -> 539 (+0) 0 -> 0 (+0) 0 -> 0 (+0)
Extended support (upstream engine tests) 682 -> 682 (+0) 16 -> 16 (+0) 34 -> 34 (+0)

Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream 3da2514eff5c.

Note: Prometheus compliance score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

@vitlibar
vitlibar added this pull request to the merge queue Nov 13, 2026
@fm4v
fm4v removed this pull request from the merge queue due to a manual request Nov 13, 2026
@nihalzp
nihalzp added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 2187560 Nov 13, 2026
204 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 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-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-not-for-changelog This PR should not be mentioned in the changelog 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.

4 participants