Skip to content

Make test 02516_projections_with_rollup faster - #125496

Merged
fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-02516-smaller-projection-fixture
Nov 19, 2026
Merged

fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-02516-smaller-projection-fixture

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #109052

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

Make the test 02516_projections_with_rollup faster by inserting 10x fewer rows.

Description

02516_projections_with_rollup took 196 s, over the 180 s limit, in Stateless tests (amd_tsan, s3 storage, targeted) on #109052. In that run the two MATERIALIZE PROJECTION mutations over the 1,728,000-row fixture took 185 s (random min_bytes_for_full_part_storage made each one rewrite the whole part), while the checked query took 0.2 s.

The checked query (ROLLUP + TOTALS + LEFT JOIN over the aggregate projection, the #42772 case) reads only about 100 rows of p_agg (one per hour and domain), so this inserts 172,800 rows instead. The queries, projections and reference are unchanged, and p_agg is still used in every run with projections enabled (144/144 under TSan, 35/35 in debug).

Validation with the TSan binary of that CI run, pinned to 16 CPUs, --flaky-check -j 9, 50 runs: p50 17.9 s -> 3.0 s, max 42.2 s -> 6.0 s. With the failing run's exact settings: 38.9 s -> 4.8 s per run.


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

Version info

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

The test inserted 1,728,000 random rows and then ran two
MATERIALIZE PROJECTION mutations with mutations_sync = 1. Their cost is
linear in the row count, and with random MergeTree settings such as
min_bytes_for_full_part_storage (whole-part rewrite on mutation) and a
small merge_max_block_size they took 185 s of a 196 s run in
Stateless tests (amd_tsan, s3 storage, targeted), over the 180 s limit.

The checked query (ROLLUP + TOTALS + LEFT JOIN over the aggregate
projection, the ClickHouse#42772 case) is plan-level and reads ~200 rows of p_agg,
so 172,800 rows are enough: p_agg is still selected, and the queries,
projections and reference are unchanged.

02371_select_projection_normal_agg shares the fixture but is left as is:
a row cut there lets part pruning drop its normal projection, and it has
no gated failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-human PR origin: human review feedback on a groeneai PR labels Oct 12, 2026
@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;
bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ The FORMAT Null oracle does not enforce that p_agg is used after the row cut; suggests pinning optimize_use_projections = 1 and force_optimize_projection_name = 'p_agg' DISAGREE The row count cannot flip selection: optimizeUseAggregateProjection.cpp:1425 rejects a projection only when it needs more marks than the table, the query has no WHERE, and p_agg has at most 100 rows (1 mark) per part while every table part has at least 1 mark. Measured: p_agg used in 144/144 TSan and 35/35 debug runs with projections enabled; the other runs drew optimize_use_projections = 0, the same before and after. The no-exception oracle is the test's original design (added in 593675a with a fix that disabled projections under ROLLUP/TOTALS), so forcing p_agg would be a new contract, not a speed-up.

Also noticed: 02371_select_projection_normal_agg shares the fixture; a row cut there drops its normal projection via part pruning, and it has no gated failures, so it is unchanged.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-9:20261012-200500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the cost: the failing run's exact settings on that CI run's TSan binary give 38.9 s per run for the old file (3/3), with the two MATERIALIZE PROJECTION mutations taking 35 s of it, as in CI. The 180 s verdict itself needs CI's S3 disk and runner size, so the local oracle is old vs new at matched concurrency.
b Root cause explained? Each MATERIALIZE PROJECTION rewrites every row of the 1,728,000-row fixture. Random MergeTree settings (min_bytes_for_full_part_storage forces a whole-part rewrite, small merge_max_block_size) and TSan on S3 multiply that linear cost; the flaky check runs 9 copies at once, so one run passed 180 s.
c Fix matches root cause? Yes: the fixture size is the cost driver and the checked query does not depend on it (plan-level ROLLUP + TOTALS over p_agg, about 110 rows read). No tags, no bounds, no pinned settings.
d Test intent preserved / new tests added? Preserved: p_agg is used in 144/144 TSan and 35/35 debug runs with projections enabled, and at default settings; EXPLAIN is identical except row counts. Test-only change, so no new test.
e Both directions demonstrated? Old vs new, TSan, 16 CPUs, --flaky-check -j 9, 50 runs each: p50 17.9 -> 3.0 s, max 42.2 -> 6.0 s. Failing-run settings: 38.9 -> 4.8 s.
f Fix is general across code paths? 02371_select_projection_normal_agg shares the fixture but is unchanged: a row cut there lets part pruning drop its normal projection, and it has no gated failures. 02483_merge_projections already uses 50,000 rows.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). 160 randomized runs (20 debug, 140 TSan) passed.
h Backward compatible? (maintainer-approved exception only) N/A (test-only).
i Invariants and contracts preserved? Statements, projections, table settings and the empty reference are unchanged; the table is still multi-part and spans one hour, so the ROLLUP shape is the same.

Session id: cron:clickhouse-impl-slot-6:20261012-194800

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f2ba24b]

Summary: ✅


AI Review

Summary

This PR reduces the fixture in 02516_projections_with_rollup from 1,728,000 to 172,800 rows to reduce projection materialization time. The change preserves the ROLLUP / TOTALS regression query and its exception oracle. No actionable findings. The supplied before/after measurements support the speedup; the head's targeted TSan run and TSan flaky check each show 50/50 passes for this test.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f2ba24b

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore not from this PR (it only shrinks the fixture of 02516_projections_with_rollup): UNKNOWN_TABLE for the reused MATERIALIZED CTE _materialized_cte_c_* on a parallel replica; 130 of 130 reruns with the same settings passed #123121 (mine, open)
Mergeable Check, PR praktika rollups of the row above #123121 (mine, open)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261013-023009

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai is this pr still needed?

@PedroTadim PedroTadim reopened this Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Not for the reason I opened it. The slow tail of this test disappeared from master around 2026-10-20 (CIDB):

I have not identified which master change removed the tail. The PR is still correct, but nothing needs it now, so I think it can be closed.

@PedroTadim PedroTadim closed this Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Correction to my answer above: I only checked the MSan and TSan durations, and the slow path is still reachable. 02371_select_projection_normal_agg, which inserts the same 1.7M-row video_log fixture, failed with 231 s on 2026-11-06 in Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) (report). That run drew merge_max_block_size = 1: the 1,063,188-row part is materialized as two temporary projection parts, and merging them 1 row per block made the two MATERIALIZE PROJECTION statements take 109 s and 113 s. This test's 196 s run on #109052 merged the temporary projection parts of its 1,050,000-row part with merge_max_block_size = 20.

#129676 clamps merge_max_block_size for 02371 only. Should I add the same one-line clamp to 02516_projections_with_rollup.sql there, or leave this test as is?

@PedroTadim PedroTadim reopened this Nov 6, 2026
@fm4v
fm4v added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ClickHouse:master with commit 3faf20b Nov 19, 2026
403 of 413 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-projections Projections: precomputed layouts for accelerating queries (projection parts, maintenance). 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-projections Projections: precomputed layouts for accelerating queries (projection parts, maintenance). groeneai-origin-review-human PR origin: human review feedback on a groeneai PR 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