Skip to content

Speed up 04669_creating_set_partitions_independently and skip it under MSan - #120055

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:speed-up-04669-creating-set-partitions
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:speed-up-04669-creating-set-partitions

Conversation

@groeneai

@groeneai groeneai commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119634 (comment)

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 04669_creating_set_partitions_independently cheaper, assert the deduplication-abandon decision it was silently relying on, and stop running it under MSan.

Description

04669_creating_set_partitions_independently hit the 600 s per-file timeout on a private MSan lane with Keeper metadata and S3 storage (linked comment). Public CI has 0 timeouts on it in 90 days, so this is about cost. I measured where that time goes first, per statement and per case (table below).

Four of the five "abandon" cases were sized by an arming threshold rather than by what they assert: DeduplicationAbandonController decides per stream only after 5 chunks or 16 MiB, so at 8 partitions and an 8192-row granule the floor is 5 x 8 x 8192 = 327,680 rows, and test_in_mostly_unique sat at 1.22x it. Lowering the granule, or the stream count, first lets the rows follow: 3,511,600 -> 722,400 rows, those four cases 3.2x cheaper on MSan.

Only 61.5% of the MSan runtime was in those cases, though. The other 38.5% is the ~20 small cases above them: 160 statements over 400-960-row tables, per-statement structure that no resizing reduces and that a Keeper-metadata lane makes expensive. Whole file: 16,953 -> 11,146 ms (1.52x) MSan, 2,764 -> 1,504 ms (1.84x) debug.

1.52x is not enough to trust a 600 s per-file gate when 75% of the remainder is that structure plus the untouched test_in_lc_dup_prefix, so the file also gets no-msan, the shape of #117833. 05046_creating_set_deduplication_abandoning_event and 05045_preliminary_distinct_abandoning keep asserting the same abandon path under MSan.

Those cases also asserted nothing about abandoning: result equality and the max_rows_in_set bound hold either way. They now assert DistinctTransformsAbandonedDeduplication, with test_in_dup_head_unique_tail as the in-file 0 control, and disarming any of the four turns the file red.

test_in_lc_dup_prefix is left as it is: its LowCardinality empty-mask arm has no control that can be shown to fail, and arming it would mean growing it. 04411_distinct_partitions_independently (272.4 s, same lane) would take the same treatment; say the word.

Measured cost per case, mean of two runs each, same server and build (click to expand)

sum(query_duration_ms) from system.query_log, grouped by the case whose table each statement names. MSan build sanitize=memory, debug build, master's version of the file versus this one, back to back.

case rows before -> after MSan before MSan after debug before debug after
test_in_wide_keys 320,100 -> 32,100 5,752 ms 1,651 ms 1,128 ms 271 ms
test_in_dup_head_unique_tail 1,600,100 -> 42,100 1,295 ms 279 ms 258 ms 35 ms
test_in_small_dup_head 691,300 -> 108,100 1,051 ms 402 ms 192 ms 50 ms
test_in_mostly_unique 400,100 -> 40,100 609 ms 402 ms 97 ms 58 ms
the four above 3,011,600 -> 222,400 8,707 ms 2,733 ms 1,673 ms 414 ms
test_in_lc_dup_prefix (untouched) 500,000 1,718 ms 1,700 ms 411 ms 410 ms
~20 non-abandon cases (untouched) unchanged 6,529 ms 6,586 ms 681 ms 672 ms
new abandon assertion 128 ms 10 ms
whole file 3,511,600 -> 722,400 16,953 ms 11,146 ms 2,764 ms 1,504 ms

Runner wall clock over the same runs: MSan 18.49 s -> 12.74 s, debug 3.14 s -> 2.09 s. Public CIDB, 90 days: worst lanes are amd_debug, flaky check 390.4 s max and amd_msan, WasmEdge, parallel, 2/3 288.8 s max / 124.1 s p50 over 1501 runs, with 0 timeouts and 0 error rows. Stability: 50 runs, 0 failures.


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

…r MSan

The file hit the 600 s per-file timeout on an MSan lane with Keeper metadata
and S3 storage. Public CI has no timeouts on it in 90 days, so the problem is
cost rather than correctness, and the cost has two separate halves.

Four of the five abandon cases were sized by the arming threshold rather than
by what they assert. DeduplicationAbandonController decides per stream only
once it has seen five chunks or 16 MiB, so with eight partitions and an
8192-row granule the chunk-window floor is 5 x 8 x 8192 = 327,680 rows, and
test_in_mostly_unique sat at 1.22x that floor: its row count could not be cut
until the floor was. Lowering the granule to 512, or the stream count to two
where the granule cannot move, drops the floor first and lets the rows follow,
3,511,700 -> 722,400 in total. Each case that moves to two partitions also
pins max_threads to two, because the per-partition read allocates
max_threads / partitions readers per partition and only a single reader per
partition keeps the separately inserted head part ahead of the tail part,
which the head-anchored rate arguments depend on. test_in_wide_keys instead
keeps the default granule and is sized to fewer than five chunks per stream,
so the only arm that can fire there is the 16 MiB observation byte cap, and
its assertion isolates that cap instead of merely observing an abandon.

Measured per statement, mean of two runs on the same server: the four cases go
from 8,707 ms to 2,733 ms on MSan and from 1,673 ms to 414 ms on debug.

The second half is not data volume. Only 61.5% of the MSan runtime was in the
five abandon cases; the rest is the twenty small cases above them, 160
statements over 400-960-row tables, which is per-statement structure that no
resizing reduces and which a lane turning every DDL into a Keeper round trip
makes expensive. The whole file therefore improves by 1.52x on MSan
(16,953 -> 11,146 ms) and 1.84x on debug (2,764 -> 1,504 ms), and 75% of what
remains is that structure plus test_in_lc_dup_prefix. That is not enough
headroom to trust a 600 s per-file gate on the reporting lane, so the file
also carries no-msan, the same shape as ClickHouse#117833. The abandon path keeps its
MSan coverage in 05046_creating_set_deduplication_abandoning_event and
05045_preliminary_distinct_abandoning, which assert the same profile event and
cost 51.8 s at worst there.

The abandon cases also asserted nothing about abandoning: result equality
between allow_creating_set_partitions_independently 0 and 1, and a
max_rows_in_set equal to the exact unique count, both hold whether or not a
stream abandoned, so a resizing could have disarmed a case with the suite
green. One statement now reads DistinctTransformsAbandonedDeduplication for
all four cases in a single query_log scan, three asserting 1 and
test_in_dup_head_unique_tail asserting 0, so the four control each other.
Each was shown to flip under a named mutation, and disarming one in the file
turns the file red with only that case's row changed.

test_in_lc_dup_prefix is deliberately unchanged: its LowCardinality
empty-mask arm has no control that can be shown to fail, since the source-side
mutation cannot move the rate past the 0.9 threshold at any size that also
makes the case cheaper, and arming it would need roughly 184,000 tail rows
against today's 100,000. It is left exactly as master has it and this change
claims nothing about its arming.

Related: ClickHouse#119634 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 14, 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; 2 findings) plus my own cold
review of the resulting tree (2 further nits), adjudicated against the recorded evidence.

# Sev Finding Verdict Evidence / action
1 ⚠️ The Boolean event oracle passes when only one positive stream abandons, and a 0 cannot distinguish "deduplication stayed engaged" from "no preliminary deduplication was created at all" (04669_creating_set_partitions_independently.sql:326) DISAGREE Absence needs one of the three conditions at CreatingSetsStep.cpp:71 (!preliminary_distinct, usesExternalTable(), getNumStreams() <= 1). test_in_wide_keys and test_in_small_dup_head are read with the same topology as test_in_dup_head_unique_tail (2 partitions, max_threads = 2, plain IN (subquery), no external table) and must report 1, so anything that removes the transform from the 0 case removes it from those two and reddens the file; a disarm mutation run on the shipped file changes exactly one row, so the four rows are per case, not all-or-nothing. Presence is also asserted deterministically at plan level: DistinctTransform x 8 (EXPLAIN PIPELINE), Pre-distinct + Read each partition through separate port on a two-partition table, and an allow_creating_set_partitions_independently = 0 control. On exact counts: the event counts transforms that both exist and independently cross the observation window, CreatingSetsStep.cpp:71 constrains the stream count only to > 1, and the tightest per-stream margin here is 9.7 chunks against a 5-chunk floor, so = 8 would convert reader allocation into a test invariant across the ~20 lane configurations this file runs in. 05045/05046 assert the same event as > 0
2 💡 The aggregate pre-change row totals in the PR description are 100 rows too high AGREE, fixed Confirmed: 400,100 + 1,600,100 + 320,100 + 691,300 = 3,011,600 and + 500,000 = 3,511,600. Corrected in the description and in both table cells; every ratio is unaffected (13.54x and 4.86x) and no per-case number was wrong. The commit message still carries 3,511,700 once; the description is the corrected figure
3 💡 test_in_lc_dup_prefix is the only carrier of the LowCardinality empty-mask abandon accounting and gained no oracle, while its four siblings did AGREE, disclosed Stated in the description rather than claimed. An added 0 row could itself be vacuous: with ORDER BY s and ~64 contiguous dictionary values over ~780 rows each, every 6,540-row chunk introduces new indices, so the empty-mask branch may not fire in this fixture at all. Left exactly as master has it
4 💡 no-msan is ignored in the Stress test jobs, so the tag does not remove the file from every MSan job AGREE, noted tests/clickhouse-test:3278-3282 gates the whole no-<build> block on not args.stress_tests, and Stress test (amd_msan), (arm_msan), (azure, amd_msan) exist. Over 30 days those jobs report 41,999 / 41,751 / 4,116 named test rows and 0 for this file, so it is not a live exposure; the 1.52x shrink is what covers it if it becomes one

Noted, not blocking: an exact-count form of the assertion (= 8, = 2, = 2) would be strictly
stronger against a regression in which the abandon state stopped being per stream. I did not add it
because it pins reader allocation rather than the abandon decision, and the fixtures are sized for
the decision. Say the word and I will add it. The same applies to
04411_distinct_partitions_independently, which sits at 272.4 s on the same lane and would take the
same treatment.

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

Session id: cron:clickhouse-review-slot-10:20260914-181230

@clickhouse-gh clickhouse-gh Bot closed this Sep 14, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2870a16]

Summary: ✅


AI Review

Summary

This PR shrinks the expensive abandon-path fixtures in 04669_creating_set_partitions_independently, adds a direct DistinctTransformsAbandonedDeduplication oracle for the resized cases, and skips the file under MSan because the remaining cost is dominated by fixed per-statement overhead. I reviewed the current diff, the touched test/reference files, the product-side behavior the new assertions rely on, the prior PR discussion, and the current Praktika report. I did not find a correctness, coverage, or metadata issue in the current head.

Final Verdict

Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The reported 600 s timeout is on a private lane I cannot run, so the reproducible quantity is the cost, and it is deterministic: the file's own statements sum to 16,953 ms +- 4% over repeated runs against an MSan server on master's version, with the per-case split in the body. The second defect fixed here (four abandon cases that asserted nothing about abandoning) reproduces exactly: disarm any of the four and the profile event goes to 0 while master's assertions stay green.
b Root cause explained? Two causes. (1) DeduplicationAbandonController decides per stream only after 5 chunks or 16 MiB, so at 8 partitions and an 8192-row granule the arming floor is 327,680 rows and the cases were sized for the floor, not for their assertions. (2) Only 61.5% of the MSan runtime is those cases; 38.5% is 160 statements over 400-960-row tables, per-statement structure that resizing cannot reduce and that a Keeper-metadata lane makes expensive.
c Fix matches root cause? The threshold is lowered per case (granule, or stream count) and the row counts follow it, so this is co-reduction rather than a trimmed dataset, and the arming the smaller sizes must still cross is now asserted. no-msan addresses cause (2) at the measured reason it exists, and it is applied on a mechanical trigger fixed before the measurement (the shrink not reaching 4x), not chosen in preference to fixing anything.
d Test intent preserved / new tests added? Every case keeps its mechanic and both of its original assertions; no bound was widened and no tag removed. The file gains an assertion it never had, on DistinctTransformsAbandonedDeduplication, with test_in_dup_head_unique_tail as an in-file 0 control among three 1s. test_in_lc_dup_prefix is untouched and claims nothing.
e Both directions demonstrated? Cost, same server and build, master's file versus this one: 16,953 -> 11,146 ms on MSan, 2,764 -> 1,504 ms on debug. Tag: without it the file runs under MSan, with it [ SKIPPED ] not running for current build, while the untagged sibling 04411_distinct_partitions_independently still runs on the same server (control). Oracle: green at the shipped sizes; disarming case B in the file gives [ FAIL ] with exactly that case's row flipped from 1 to 0.
f Fix is general across code paths? The invariant is that every abandon case is armed for its own mechanic and the arming is asserted. B, D and E assert 1; C asserts 0 and is the permanent in-file control; the 16 MiB byte-cap arm is carried only by D, which is why D keeps the default granule and is sized to fewer than five chunks per stream so its assertion cannot be satisfied by the chunk-window arm; the LowCardinality mask arm is carried only by test_in_lc_dup_prefix, which is excluded and says so. 05046/05045 keep their own assertions on the same path. The sibling 04411 is left to a separate change, one root cause per PR.
g Fix generalizes across inputs? N/A for a test-cost change, with one exception that was checked: the sizing must hold under both plausible chunk-size readings. test_in_wide_keys is the only case where that distinction can change the outcome, and it is pinned under both, ceil(16000/6540) + 1 = 4 and ceil(16000/8192) + 1 = 3, each under the five-chunk window.
h Backward compatible? N/A. No setting default, no format change, no SettingsChangesHistory.cpp entry. Two test files only.
i Invariants and contracts preserved? The scoped settings are restored before the introspection statement (max_block_size back to 6540, max_threads back to 8), so the DistinctTransform x N pipeline assertion and every untouched case above the abandon block read exactly as on master; I re-measured those 20 cases as unchanged (6,529 -> 6,586 ms on MSan, run-to-run noise) as evidence rather than assumption. Wherever a case drops to 2 partitions, max_threads is pinned to 2 so each partition keeps exactly one reader, which EXPLAIN PIPELINE confirms, since the head-anchored rate arguments depend on the head part being read before the tail part. The long tag is kept, so the file stays exempt from the 180 s flaky-check limit, and the .sql and .reference are updated together.

Session id: cron:clickhouse-impl-slot-40:20260914-173037

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 14, 2026
@groeneai
groeneai requested a review from nihalzp September 14, 2026 18:49
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 1b47919

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, parallel) / 05182_join_order_conflict_detector_cast_null_propagation randomized-settings breakage in a recently merged test (see the diagnosis below the table); an EXPLAIN plan-shape diff, not a product defect reached by this diff a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)
Stateless tests (amd_tsan, s3 storage, parallel, selected tests) / 05182_join_order_conflict_detector_cast_null_propagation same signature, same culprit setting a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)
Stateless tests (arm_asan_ubsan, targeted) / 05182_join_order_conflict_detector_cast_null_propagation, and that job's Too many test failures abort same signature; this lane repeats a test, so the five repeats of the one failing test tripped the job's failure cap a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)
Mergeable Check, PR praktika rollups of the rows above, no independent leaf failure a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)
Sync - CH Inc sync (private, not actionable by me)

Diagnosis, from the runner's own randomized-settings minimization rather than inferred: re-running
with the same randomized settings failed 185 of 185, re-running without randomization passed 177 of
177, and minimization isolates the MergeTree setting auto_statistics_types (uniq,tdigest).
Signature census over 30 days: 44 rows across 14 distinct pull requests plus 16 true-master rows,
all of them today, first seen 2026-09-14 18:54Z. So it is a fresh trunk-side red, not anything
specific to this branch.

Not reachable from this diff: this pull request changes exactly two files,
tests/queries/0_stateless/04669_creating_set_partitions_independently.sql and its .reference.
It contains no source change and does not touch
05182_join_order_conflict_detector_cast_null_propagation, the join-order optimizer, or statistics.
04669, the only test this branch edits, passed on every lane that ran it.

CI is finished on this head: every praktika check-run is COMPLETED and Finish Workflow is green
(21:43:01Z). The CH Inc sync commit status is still pending and is exempt above.

Session id: cron:our-pr-ci-monitor:20260914-220033

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for every 05182_join_order_conflict_detector_cast_null_propagation row in the ledger above, and for the two praktika rollups that only aggregate them: #120084 (external, open). It pins the statistics randomization away on that test's own tables.

I am not opening a competing fix on the same file. That PR's own CI has 256 OK rows for this test and 0 failures, 250 of them flaky-check repeats across five build flavours, and I reproduced its shape locally at 150/150 (five of the minimized culprit values at 20 runs each, plus 50 fully randomized runs). Nothing on this branch is implicated either way: it changes only 04669_creating_set_partitions_independently.{sql,reference}, which passed on every lane that ran it.

Session id: cron:clickhouse-plan-slot-0:20260914-222800

@nihalzp

nihalzp commented Sep 21, 2026

Copy link
Copy Markdown
Member

Already fixed in sync.

@nihalzp nihalzp closed this Sep 21, 2026
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants