Skip to content

Run the aggregation_in_order_if_null_map performance queries in one thread - #127697

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-agg-in-order-if-null-map-one-thread
Oct 25, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-agg-in-order-if-null-map-one-thread

Conversation

@groeneai

@groeneai groeneai commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100759
Related: #118025

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):

The aggregation_in_order_if_null_map performance test runs its queries with max_threads = 1, so its timings no longer depend on how the threads of the multi-stream in-order aggregation interleave.

Description

aggregation_in_order_if_null_map is rank 8 in #100759. From 2026-10-22 to 2026-10-24 on master, #5 (corr(x, w)) was over the report floors in 33 of 110 amd runs and 0 of 112 arm runs; #0-#4 in 2-7 of 112 on amd. CI flagged it unstable in 5 of those amd jobs, e.g. amd_release 4/6 (#5 0.047 vs 0.060 s).

On amd both servers run with 8 pinned CPUs and max_threads = 8, so each query runs 8 AggregatingInOrderTransforms into FinishAggregatingInOrderTransform and 8 MergingAggregatedBucketTransforms. Every run reads the same part (1 part, 611 marks) with about the same CPU time, but the pipeline threads' off-CPU time varies per run and per server process (about +114 ms for #5 in the slow mode), so the 25-60 ms queries are bimodal and the two servers often sit in different modes.

With max_threads = 1 the pipeline is AggregatingInOrderTransform -> FinalizeAggregatedTransform. The -If/-Null adapter code this test was added for (#118025, mine) still runs in AggregatingInOrderTransform on the same 5M rows and 625000 groups; the 8-stream merge is no longer measured here. aggregation_in_order_partial_key.xml already uses this shape and is not over the floors on either arch. No product change; the queries now take 0.08-0.18 s.

Validation: two local servers with the same master release binary, set up like the amd job (8 pinned CPUs, max_threads = 8), restarted for each of 6 cycles of 7 runs per query. Old: 10 of 36 query-cycles over the floors, #5 stat_threshold median 0.243. New: 0 of 36, #5 median 0.012, max 0.016. Results are identical at 1 and 8 threads.

🤖 Generated with Claude Code


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

Version info

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

On the amd perf runners the six queries run the 8-stream in-order
pipeline (AggregatingInOrderTransform x 8 -> FinishAggregatingInOrderTransform
-> MergingAggregatedBucketTransform x 8). Its wall time is bimodal per
server process: on master (2026-10-22..24) query ClickHouse#5 (`corr(x, w)`) was over
the report floors in 33 of 110 amd runs, with the same CPU time in both
modes and about 127 ms more off-CPU time across the threads in the slow one.

With `max_threads = 1` the pipeline is AggregatingInOrderTransform ->
FinalizeAggregatedTransform: the per-group -If / -Null adapter code this
test measures still runs on the same 5M rows and 625000 groups, and the
cross-stream stage (not the subject of this test) is gone. Results are
identical at 1 and 8 threads. Same shape as
aggregation_in_order_partial_key.xml, which is not over the floors on
either arch.

Related: ClickHouse#100759

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 over 2 passes).

# Sev Finding Verdict Evidence / action
1 ⚠️ Stability of the final XML needs repeated same-binary runs across restarts, all six queries; sub-0.1 s queries are suspect DISAGREE Measured: same release binary on both servers, both restarted for each of 6 cycles, 8 pinned CPUs with max_threads = 8, final XML: all six queries 0 of 6 cycles over the floors, max stat_threshold 0.035, incl. #2/#3 at 0.08 s (0.033/0.023). tests/performance/scripts/README.md recommends a single-threaded query for too-fast ones.
2 💡 Description date range omits the year AGREE, fixed in the description 2026-10-22 to 2026-10-24

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

Session id: cron:clickhouse-review-slot-8:20261024-071700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a local A/A pair set up like the amd job, every old #5 run has 44-205 ms of pipeline off-CPU time and every new run at most 6 ms (84 of 84 each); old is over the floors in 10 of 36 query-cycles, new in 0.
b Root cause explained? With 8 pinned CPUs the queries run the 8-stream in-order pipeline, whose threads' off-CPU time varies per run and per server process at the same CPU work, so the 25-60 ms timings are bimodal.
c Fix matches root cause? Yes. max_threads = 1 removes the cross-stream stage; no product change, no widened threshold, same fixture.
d Test intent preserved / new tests added? Yes. The -If/-Null adapter code from #118025 still runs in AggregatingInOrderTransform on the same data. A perf XML change ships no extra test; the evidence is the local before/after.
e Both directions demonstrated? Yes. Old vs new on the same servers, same binary, restarted for each of 6 cycles: #5 stat_threshold median 0.243 vs 0.012.
f Fix is general across code paths? All six queries of the test get the setting; all six are stable (new max stat_threshold 0.035).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). All six aggregate shapes, incl. two Nullable arguments, are covered.
h Backward compatible? (maintainer-approved exception only) Yes, no product change. The six query texts are new, so their learned thresholds start fresh.
i Invariants and contracts preserved? Query indices, fill and OPTIMIZE unchanged; results identical at 1 and 8 threads; read_rows 5000000 on every run; slowest run 0.18 s.

Session id: cron:clickhouse-impl-slot-4:20261024-070900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @egor-click, could you review this and add the can be tested label so CI runs? The six queries ran the 8-stream in-order aggregation pipeline, whose off-CPU time varied per run and per server process at the same CPU work, so #5 (corr(x, w)) was over the floors in 33 of 110 amd runs; with max_threads = 1 they still run the -If/-Null adapter code this test was added for on the same data, like aggregation_in_order_partial_key does.

@clickhouse-gh

clickhouse-gh Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [71e9d4d]

Summary: ✅


AI Review

Summary

The PR sets max_threads = 1 on all six queries in aggregation_in_order_if_null_map, preserving the per-group -If/-Null adapter workload while removing parallel aggregation merge stages. No actionable findings. The author's repeated A/A measurements across server restarts support the stability improvement; I did not independently rerun the benchmark.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 24, 2026
@egor-click egor-click added the can be tested Allows running workflows for external contributors label Oct 24, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 24, 2026
@Algunenano Algunenano self-assigned this Oct 24, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 25, 2026
Merged via the queue into ClickHouse:master with commit 6e5517c Oct 25, 2026
352 of 353 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 25, 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). 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.

5 participants