Skip to content

Merge the insert_statistics_uniq_v2 statistics tables into one part before measuring - #126505

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-perf-insert-statistics-uniq-v2-one-part
Oct 19, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-perf-insert-statistics-uniq-v2-one-part

Conversation

@groeneai

@groeneai groeneai commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122231

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 insert_statistics_uniq_v2 performance test now merges each t_materialize_uniq_v2_* table into one part before measuring MATERIALIZE STATISTICS, so both compared servers mutate the same layout.

Description

Performance Comparison (arm_release, master_head, 6/6) failed on #126296 (a CI-scripts-only diff) with insert_statistics_uniq_v2 #4 as its red reason: report, 0.1445 -> 0.1933 s, confirmed_regression after the restart. #109455 and #114577 went red the same way on 2026-10-17, and about 19 PRs that day had #4/#5 slower or unstable.

Before #122231, SYSTEM STOP MERGES on the two tables under ALTER ... CLEAR STATISTICS ALL, MATERIALIZE STATISTICS ALL also blocked the measured mutations, so #4/#5 never completed in CI. Since #122231 background merges run while the fill inserts its 20 parts, and each server ends with its own layout (CI server logs: 8 servers, 8 layouts, from [6,6,6,1,1] to [20] million rows). The ALTER runs one mutation task per part, so its time follows the largest part, and the layout lasts the whole job, which is why the restart reproduces the gap.

The fill now runs OPTIMIZE TABLE ... FINAL SETTINGS optimize_throw_if_noop = 1 on both tables and a throwIf fails the job unless each has one active part, the shape of and_compare_chain_derived.xml. projection_materialize.xml measures a mutation over one part the same way and is stable on arm (0 of 5642 runs off by more than 10%). The queries are unchanged; this pins the first layout #4/#5 are measured on rather than restoring an old one.

Validated on the official master release binary with perf.py on two servers: before, #4 right/left was 1.249, 0.892 and 0.841 in 3 of 5 fills (different layouts); after, every ratio of #4/#5 was within 5% in 5 of 5, with one 20M-row part per table. Replacing one OPTIMIZE with SELECT 1 makes the throwIf fail the fill. #4/#5 settle at about 0.24 s locally (amd), and the fill takes about 0.9 s longer.

🤖 Generated with Claude Code


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

Version info

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

…efore measuring

Since 2f07f3f (ClickHouse#122231) `t_materialize_uniq_v2_{i64,f64}` no longer stop
merges, so background merges run while the fill commits its 20 1M-row parts
and keep running during queries #0-ClickHouse#3. Each compared server ends up with its
own layout (CI server logs: 8 servers, 8 layouts, from [6,6,6,1,1] to [20]
million rows). The measured `ALTER ... CLEAR STATISTICS ALL, MATERIALIZE
STATISTICS ALL` runs one single-threaded mutation task per part, so its time
follows the largest part, and the layout lasts the whole job, so the dashboard
confirmation restart reproduces the gap (`confirmed_regression` on unrelated
PRs, e.g. ClickHouse#126296: ClickHouse#4 0.1445 -> 0.1933 s).

Merge both tables into one part in the fill with `OPTIMIZE TABLE ... FINAL
SETTINGS optimize_throw_if_noop = 1` and assert one active part per table with
`throwIf`, as `and_compare_chain_derived.xml` does. Without
`optimize_throw_if_noop` a failed merge assignment only logs and returns
success, leaving a random layout. A table that background merges already
collapsed to one part is still rewritten under FINAL, so the pin never throws
on it. `projection_materialize.xml` measures a mutation over one merged part
the same way and is stable on the same harness.

Validated on the official master release build (26.11.1.120): before, 10
fills gave 5 i64 layouts and a 1.92x spread of ClickHouse#4, and perf.py on two servers
gave right/left 1.249, 0.892, 0.841 in 3 of 5 fills; after, one 20M-row part
per table in 10 of 10 fills, ClickHouse#4/ClickHouse#5 spread 1.029/1.041, and perf.py right/left
within 5% in 5 of 5. Replacing one OPTIMIZE with `SELECT 1` fails the fill.

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

# Sev Finding Verdict Evidence / action
1 💡 The throwIf counts the active parts of both tables together, so a 2/0 split would pass (insert_statistics_uniq_v2.xml:96-100) DISAGREE Each table gets 20M rows from its fill INSERT, so each has at least one active part; a total of 2 then means exactly one per table.

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

Session id: cron:clickhouse-review-slot-8:20261017-165100

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @naushniki, could you review this? Since 2f07f3f3008b the t_materialize_uniq_v2_* tables merge during the fill, so each server measures #4/#5 over its own part layout; the fill now runs OPTIMIZE ... FINAL and asserts one active part per table, keeping merges enabled.

@clickhouse-gh

clickhouse-gh Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f03df96]

Summary: ✅


AI Review

Summary

The PR stabilizes insert_statistics_uniq_v2 by merging both statistics-materialization tables into one part before measurement and rejecting an unexpected part count. No actionable findings remain after reviewing the diff, current code, benchmark lifecycle, and all prior discussion.

Missing context / blind spots
  • ⚠️ The PR reports local before/after measurements, but its own ARM performance comparison has not produced results: Build (arm_release) remains queued. A completed PR CI run would independently confirm stability in the affected environment. No local performance run was performed during this review.
Final Verdict

Status: ✅ Approve. No code changes requested; normal CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 17, 2026
@naushniki naushniki added the can be tested Allows running workflows for external contributors label Oct 17, 2026
@naushniki
naushniki self-requested a review October 17, 2026 20:00

@naushniki naushniki 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.

LGTM once this PR's own perf run is green; I'll approve then.

#122231 caused this: the SYSTEM STOP MERGES it removed also blocked the measured mutations (StorageMergeTree::scheduleDataProcessingJob returns before selecting mutations while merges are blocked), so #4 and #5 never ran in CI before, and after the removal the layout was left to background merges. The NightlyExtendedPerformance runs show the same: in all four so far #4/#5 differ by 19–62 % with opposite signs in one run (2026-10-17: #4 −50 %, #5 +58 %), which only a per-server layout explains. Besides #109455 and #114577, #126296 and #122069 went red on it.

OPTIMIZE ... FINAL waits for running merges and rewrites an already merged part (optimize_skip_merged_partitions = 0), so the pin is deterministic.

Optional:

  • With optimize_throw_if_noop = 1 each OPTIMIZE ... FINAL leaves one part in the only partition or throws, so the throwIf is redundant. Keeping it as an explicit guard, as in and_compare_chain_derived.xml, is also fine.
  • The description could say that #4/#5 never completed in CI before #122231, so this pins their first layout rather than restoring an old one.

This PR's own Performance Comparison (arm_release, master_head, …) run uses the new XML on both servers, so it checks #4/#5 on arm directly.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks. I added that sentence to the description. I am keeping the throwIf as the explicit guard, since dropping it now would mean a push that restarts the perf run already in progress.

@alexey-milovidov alexey-milovidov self-assigned this Oct 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 18, 2026
Merged via the queue into ClickHouse:master with commit 400b1d9 Oct 19, 2026
526 of 528 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 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-statistics Column statistics: statistics kept per part on a column (tdigest, uniq, count-min sketch, minmax)... 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-statistics Column statistics: statistics kept per part on a column (tdigest, uniq, count-min sketch, minmax)... 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.

4 participants