Skip to content

Run the uniq_states_read_merge performance queries above 1 s on a quarter of the states - #131912

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-uniq-states-read-merge-quarter
Nov 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-uniq-states-read-merge-quarter

Conversation

@groeneai

@groeneai groeneai commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #129258

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

...

Description

Queries 0 and 2 of uniq_states_read_merge.xml take 1.30 / 2.29 s on MasterCI amd and 1.20 / 2.13 s on arm. Both read all 5M tiny uniq states single-threaded: query 0 copies each state before finalizing it, and query 2 merges them into 1000 sets of 320 MB in total.

No existing query number or text changes: 2 queries are disabled and 2 copies appended as 5 and 6. The copies are the same queries with WHERE k < 1250000: the first quarter of the same part, with the same mix of 2- and 9-element states, and each GROUP BY set ends at a quarter of the size with the same fill. Locally the copies' per-row time is 0.94-1.06 of their originals', and so is their per-row user time.

On the MasterCI builds before and after #111493, which CI measured 1.14x faster on amd / 1.20x on arm on query 2, the GROUP BY copy keeps 0.86-0.995 of its original's speedup. On the #129553 CI build, which CI measured 1.31x / 1.39x slower on query 0, the finalizeAggregation copy keeps 0.94 of its original's slowdown. Both hold in both seat orders, in two repetitions on different NUMA nodes, with L3 capped to one way (30 MiB) and to three (~90 MiB); CI's VMs share 105 MB on amd and 36 MB on arm.

The copies should take about 0.35 / 0.55 s on amd and 0.32 / 0.51 s on arm: about 27 s less query time per master perf job on amd and 25 s on arm. The copies restart the history of 2 queries.

Validation: perf.py on the final file runs only queries 1 and 3-6, also with CI's --max-queries 10, with no run trend.


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

Version info

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

…rter of the states

No existing query number or text changes: 2 queries are disabled and 2
copies appended as 5 and 6. The copies are queries 0 and 2 with
`WHERE k < 1250000`: the first quarter of the one part of
uniq_tiny_states (153 of 611 granules), the same mix of 2- and
9-element states; each of the 1000 GROUP BY sets ends two size degrees
smaller at the same fill.

Locally (official amd builds, perf.py, two repetitions on different NUMA
nodes, L3 capped to 1 way and to 3 ways): per-row time of the copies
0.94-1.06 of the originals', per-row user time too; the GROUP BY copy
keeps 0.86-0.995 of the effect of ClickHouse#111493 (9b9c059 -> d1a7da6,
CI x1.14 amd / x1.20 arm on query 2), the finalizeAggregation copy keeps
0.94 of the effect of the ClickHouse#129553 CI build (CI x1.31 / x1.39 on query 0).
The pair passes ran 15 runs per query and server. The copy's 80 MB of
sets sits between arm's 36 MB and amd's 105 MB shared L3, so the regime
and the effect were gated at both cache widths.

Saving: about 27 s of query time per master perf job on amd, 25 s on arm.

Related: ClickHouse#129258

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; 1 finding), plus my own review (0 blocking findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ At 0.86 retention the GROUP BY copy's #111493 speedup on arm (1.17x, -14.7%) would fall under the 0.15 report floor DISAGREE 0.86 is the 3-way (~90 MiB) amd-like stage. On arm (36 MB L3) both sets miss L3, the 1-way stage, where it keeps 0.93-0.995: -15.4% to -16.3%. On amd the original's own CI diff was -11.9%, already under the floor. Learned thresholds of queries 0-4 are 0.03-0.04, so the 0.15 floor applies to both.
2 💡 Queries 0 and 2 end their history; the copies (5 and 6) start new ones noted The disabled + append shape of the #129258 series; stated in the description.

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

Session id: cron:clickhouse-review-slot-8:20261116-055500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: perf.py on master's file, L3 capped to one way, gives query 0 1.20 s and query 2 2.23 s locally (MasterCI 1.30 / 2.29 s amd).
b Root cause explained? Input size, not an engine defect: 5M tiny states read single-threaded; query 0 copies each state before finalizing (finalizeAggregation's contract), query 2 merges them into 1000 sets of 320 MB, larger than any CI L3.
c Fix matches root cause? Yes: the copies read the first quarter of the same part on the ORDER BY key (153 of 611 granules), keeping the per-state work and the GROUP BY set fill; per-row time 0.94-1.06 of the originals' at 1 and 3 CAT ways.
d Test intent preserved / new tests added? Yes: on the builds before and after #111493 the GROUP BY copy keeps 0.86-0.995 of the original's effect, on the #129553 CI build the finalizeAggregation copy keeps 0.94. Perf-test-only change, no new test.
e Both directions demonstrated? Yes: each build pair in both seat orders, two repetitions on different NUMA nodes, at 1 and 3 CAT ways.
f Fix is general across code paths? The copies keep both merge paths (2-element states plain, 9-element batched) and the finalize copy path (ArenaAllocBytes per row 1.003-1.004 of the original's on every build).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (performance test input size); the copies read the same 2- and 9-element states, checked on all five builds.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, format or engine change; queries 0-4 keep their text and numbers, 0 and 2 are disabled.
i Invariants and contracts preserved? Yes: creates, fills and drops unchanged, every query keeps max_threads = 1, 5 enabled queries before and after (also under --max-queries 10), no run trend.

Session id: cron:clickhouse-impl-slot-4:20261116-042400

@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [99ef46e]

Summary: ✅


AI Review

Summary

PR #131912 disables queries 0 and 2 in uniq_states_read_merge.xml and appends copies that read one quarter of the states. The reported local measurements support shorter runtimes while retaining sensitivity to the previously observed uniqMerge improvement and finalizeAggregation slowdown. No actionable findings.

Missing context / blind spots
  • ⚠️ Independent CI performance validation is unavailable: arm performance shards are pending, amd shards were skipped, and the performance dashboard has no run for this PR. Runtime and sensitivity estimates rely on the author's documented local measurements; completed CI results would independently validate them. No local server benchmarks were run during this review.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@alexey-milovidov alexey-milovidov self-assigned this Nov 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit e86d939 Nov 16, 2026
384 of 386 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). 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-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). 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