Skip to content

Fix flaky automatic parallel replicas tests that read a compressible table - #125544

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-autopr-tests-compressible-read
Oct 19, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-autopr-tests-compressible-read

Conversation

@groeneai

@groeneai groeneai commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

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

Not required.

Description

Related: #120190

04034_autopr_min_rows_per_replica_reuses_index_analysis, 04034_autopr_dataflow_cache_reuse_between_different_queries, 05024_autopr_plan_based_parallel_replicas and 05059_autopr_settings_in_select_settings_clause fail with pr_used 1 -> 0 since 2026-10-12: on master (05024, 05059) and on unrelated PRs (#125475, #124023).

They share one table of periodic data and assert that the query reusing the collected statistics chooses parallel replicas. With the tests' max_threads = 4 and max_parallel_replicas = 3 the gate is input_bytes > 2 * output_bytes, and input_bytes is the compressed size of the read. On a Wide part with a ZSTD server codec the 7 MB read compresses to ~131 KB, so the outcome depends on the output estimate, which two-level aggregation makes noisy. On the settings of the #125475 job input was 131499 in every run, output 7735..76000, and every run above 65749 declined parallel replicas. Since #120190 the aggregation state estimate of this query is 30000 bytes instead of 12000; on a master build from just before it the same settings gave output up to 54636 and 0/80 failures.

The change stores WatchID with CODEC(NONE), as 05045_autopr_skip_plan_build_for_small_reads does, so the read stays large under any part format, server codec, row order or sparse serialization. No setting is pinned.

Validation, on a local ParallelReplicas-lane config: the CI settings of all four failures redden the unchanged tests (the two master ones with a ZSTD(3) server codec) and pass after the change (800/800, input >= 2.9 MB); randomized settings 600/600.

Also noticed: with two-level aggregation the key compression ratio is sampled from a few tiny per-bucket chunks, so the output estimate of one query varies up to ~10x between identical runs.


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

Version info

  • Merged into: 26.11.1.244-master (included in 26.11 and later)
  • Backported to: 26.10.3.18

… that read periodic data

`04034_autopr_min_rows_per_replica_reuses_index_analysis`,
`04034_autopr_dataflow_cache_reuse_between_different_queries`,
`05024_autopr_plan_based_parallel_replicas` and
`05059_autopr_settings_in_select_settings_clause` create the same table, insert the same
periodic data (`number % 1000 / 500 / 200`) and assert that the query reusing the collected
statistics chooses parallel replicas. With the tests' pinned `max_threads = 4` and
`max_parallel_replicas = 3` the gate in `considerEnablingParallelReplicas` reduces to
`input_bytes > 2 * output_bytes`, where `input_bytes` is the compressed size of the read.

A `Wide` part (`min_bytes_for_wide_part = 0`) with a ZSTD server codec compresses the 7 MB
read to ~131 KB, so the gate depends on the output estimate, which two-level aggregation makes
noisy: on the settings of the failing job of ClickHouse#125475 input was 131499 in every run, output took
values from 7735 to 76000, and every run with output above 65749 declined parallel replicas
(13 of 40 locally, 36 of 67 in CI). ClickHouse#120190 raised the aggregation state estimate of this query
from 12000 to 30000 bytes, which moved the high end of the output estimate up by 18000 (54636
before, 76000 after; 0 of 80 failures on a master build from before it). That is why the four
tests started failing on master and on unrelated PRs on 2026-10-12.

`CODEC(NONE)` on `WatchID` keeps the read large whatever the part format, server codec, row
order, compress block sizes or sparse serialization of a run: input is 2.4 MB or more in every
measured configuration (2942464 on the failing job's settings), at least a ~16x margin. Queries,
settings and references are unchanged, and no setting is pinned. Same approach as
`05045_autopr_skip_plan_build_for_small_reads` (e8588c7).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 13, 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; 0 findings) plus an independent cold review of the diff (0 blocker/major findings).

# Sev Finding Verdict Evidence / action
1 💡 Commit message pairs "54636 before, 76000 after" with a +18000 shift; the matching pair is 54636 -> 72636 (76000 is the maximum over all four tests) AGREE, noted-not-blocking commit message only; the PR description does not use the pair

Checked: both input-size paths (Wide column sizes, Compact sampling) take the column's own codec, so CODEC(NONE) holds under any part format or server codec; the output estimate does not depend on the storage codec; queries, settings and references are unchanged.

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

Session id: cron:clickhouse-review-slot-8:20261013-013800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Local ParallelReplicas-lane config (install.sh --parallel-rep, server codec ZSTD(1)), unchanged 04034_autopr_min_rows_per_replica_reuses_index_analysis with the #125475 job's settings (--settings-file / --merge-tree-settings-file), --test-runs 40: 13/40 FAIL with the CI diff; input bytes 131499 in every run, as in all 68 CI runs. Which run fails is predicted exactly by the measured input/output bytes (0 mismatches in ~2500 runs).
b Root cause explained? With max_threads = 4, max_parallel_replicas = 3 the gate is input_bytes > 2 * output_bytes. A Wide part with a ZSTD codec compresses the periodic 7 MB read to ~131 KB, and two-level aggregation makes the output estimate vary 7735..76000 between identical runs; above 65749 parallel replicas are declined. #120190 raised the aggregation state estimate of this query from 12000 to 30000 bytes (measured on a master build from just before it: output at most 54636, 0/80 failures).
c Fix matches root cause? Yes. The assertion needs a large compressed read; CODEC(NONE) on WatchID makes it large by construction. No setting pinned, no tag, no bound or data change. Same approach as 05045_autopr_skip_plan_build_for_small_reads.
d Test intent preserved / new tests added? Yes. Queries, settings and references unchanged; each test still asserts pr_used = 1 for its own subject. Test-only change.
e Both directions demonstrated? Yes, same binary and settings: 04034 min_rows 13/40 FAIL -> 100/100 OK; 04034 dataflow 13/40 -> 100/100; 05024 10/40 and 16/120 (its own CI settings) -> 100/100 each; 05059 10/40 -> 100/100; the two master failures' settings with a ZSTD(3) server 2/40 and 3/40 -> 50/50 each. Input after the change >= 2.9 MB.
f Fix is general across code paths? All four tests that share this table and data are changed (recursive grep of tests/queries/0_stateless). Both input estimate paths (Wide column sizes, Compact sampling with the column codec) covered: Compact 120/120.
g Fix generalizes across inputs (params/datatypes/wrappers)? Storage randomization covered: Compact, sparse serialization 0..1 (sweep), optimize_row_order, ZSTD(1) / ZSTD(3): 510/510 plus 136/136 in the sweep; fully randomized 600/600 (135 Wide / 265 Compact parts). Minimum input 2.4 MB, at least ~16x margin.
h Backward compatible? (maintainer-approved exception only) N/A (test-only change).
i Invariants and contracts preserved? N/A (test-only change); the tests' pinned settings are unchanged.

Session id: cron:clickhouse-impl-slot-4:20261013-010100

@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b7beb49]

Summary: ✅


AI Review

Summary

Stores WatchID with CODEC(NONE) in four automatic parallel replicas tests, keeping the estimated read size large enough for their existing assertions across compression settings. No actionable findings. The change remains relevant after #120190: the recorded master failure occurred at that PR's merge commit. Earlier PR CI records 50 successful runs of each changed test. Local tests were not run.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 13, 2026
@groeneai
groeneai requested a review from nickitat October 13, 2026 02:03
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 58b8532

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 flaky, not from this PR (it changes only the four AutoPR tests): Code: 60 unknown table _materialized_cte_c_* on a parallel replicas read, 1 of 145 reruns failed; the same failure occurs on master and on many unrelated PRs #123121 (ours, open)

Mergeable Check and PR are the praktika rollups of the row above. The four changed tests passed in every job that ran them on this head, including the amd_binary and amd_debug flaky checks (50/50 each).

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

@nickitat

Copy link
Copy Markdown
Member

@groeneai, pls check if it is still relevant after we merged #120190

@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes, still relevant. #120190 is what started it: its larger aggregation-state estimate (12000 -> 30000 bytes for these queries) pushes output_bytes past half of the compressed Wide read, so the gate flips.

CIDB, the four tests together:

Master examples, one per test: 04034 min_rows @ 7520cef6, 05059 @ 46787ce4, 05024 @ cac840be, 04034 dataflow @ 16add56e (today, 14:52 UTC). The only AutoPR change merged after that build, #120884, keeps the same estimates and cost formula.

@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Oct 19, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 19, 2026
Merged via the queue into ClickHouse:master with commit 0089bae Oct 19, 2026
178 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 Oct 19, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix CI

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 29, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 29, 2026
Backport #125544 to 26.10: Fix flaky automatic parallel replicas tests that read a compressible table
leshikus pushed a commit that referenced this pull request Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants