Skip to content

Run the ParallelReplicas test jobs in autopr mode every second time - #120438

Merged
nickitat merged 57 commits into
masterfrom
autopr-ci-job
Nov 18, 2026
Merged

nickitat merged 57 commits into
masterfrom
autopr-ci-job

Conversation

@nickitat

@nickitat nickitat commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

automatic_parallel_replicas_mode = 1 is the only mode that runs the cost model and replaces the plan with the parallel-replicas one. The settings randomizer only ever picks 0 or 2, and mode 2 collects statistics without ever switching, so the plan rewrite had no broad coverage outside its own handful of tests.

Rather than jobs of its own, the existing ParallelReplicas stateless jobs now take the automatic mode every second run. Which mode a run takes is keyed off the commit rather than the clock, so a run is reproducible: the same commit always picks the same mode, and across master's history the split is even (10122 of 20000 random SHAs select it). A run with no SHA, such as a local one, never switches.

The automatic profile replaces the plain one rather than joining it. Both set enable_parallel_replicas, max_parallel_replicas, cluster_for_parallel_replicas and parallel_replicas_for_non_replicated_merge_tree, so installing both would leave those values to whichever file users.d happens to load second. The swap is self-contained: the automatic profile points at the parallel_replicas cluster from config.d/clusters.xml, which is always installed, and nothing under tests/queries names the default_parallel_replicas cluster that goes away with the plain profile.

Because one job name now covers two configurations, the job reports which mode it ran in its result line. Without that, the CI DB history for that name would mix the two with no way to separate them.

The automatic profile also lets the cost model decide the small reads that stateless tests consist of. Two thresholds otherwise settle such a query before the cost model is consulted: automatic_parallel_replicas_min_bytes_per_replica, which the profile sets to 0, and the cap on how many threads a read can usefully occupy, which clamps both sides of the comparison to the same value so that a small read never switches. For the cap, the PR adds a test-only setting, automatic_parallel_replicas_ignore_thresholds, which the profile turns on.

Under --autopr, clickhouse-test stops randomizing automatic_parallel_replicas_mode and parallel_replicas_local_plan, because a randomized value would override the profile. It also treats tests/parallel_replicas_blacklist.txt as tolerate-only: a failure is accepted, but a pass is not reported as NOT_FAILED, because the cost model switches only the queries whose statistics favour parallel replicas, so most listed tests legitimately keep passing in that mode.

The ParallelReplicas jobs move from the release arm_binary build to amd_debug. Putting the whole suite through the optimization is only half the point; the other half is to see that no invariant breaks on the way, and only a debug build checks them: the release build compiles chassert out and throws on LOGICAL_ERROR instead of aborting. amd_debug is built in every pull request anyway, whereas arm_debug is skipped on small ones, and on master amd_debug, parallel runs the full suite in a median of 17 minutes, against 29 for arm_binary, ParallelReplicas, parallel.

On a non-release build with S3 storage, clickhouse-test normally turns settings randomization off. The ParallelReplicas jobs are now exempt from that rule, because the randomized settings, max_threads above all, are what makes the automatic mode switch a broad share of the queries: in the parallel job, 4336 plans were replaced with randomization against 3541 without it.

How it will look now:

Screenshot 2026-10-12 at 15 31 57

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

Version info

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

nickitat and others added 3 commits September 16, 2026 16:23
`automatic_parallel_replicas_mode` = 1 is the only mode that runs the cost model
and replaces the plan with the parallel-replicas one. The settings randomizer in
`clickhouse-test` picks only 0 or 2, and mode 2 collects statistics without ever
switching, so today the plan-rewriting half of the optimization is covered only
by the handful of tests written for it.

Reading the server log of `Stateless tests (amd_debug, parallel)` on a recent run
shows the shape of the gap: of 5971 probe plans built, 26 reached the cost model
and 18 switched - and all 18 came from AutoPR's own tests. Not one of the ~14000
other tests ever exercised the switch.

Add `Stateless tests (amd_debug, AutoParallelReplicas, parallel)` and its
sequential counterpart, which install a profile pinning mode 1. The profile also
sets `automatic_parallel_replicas_min_bytes_per_replica` to 0: stateless test
tables read far less than the 1 MiB per replica the setting defaults to, so
keeping the default would make the cheap pre-check reject every plan before the
probe is built and the jobs would pass without exercising anything.

`clickhouse-test` gains `--autopr`, which stops the randomizer from sending a
per-query `automatic_parallel_replicas_mode` that would override the profile the
job just installed.

The jobs reuse `parallel_replicas_blacklist.txt`, but tolerate-only: a listed
test may fail without failing the job, and - unlike the forced parallel-replicas
job - a listed test that passes is not turned into `NOT_FAILED`. AutoPR switches
a query only when its statistics say it pays off, so most blacklisted tests
legitimately keep passing, and the usual inversion would report all of them as
needing removal from the list.

Log analyzed:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118657&sha=latest&name_0=PR&name_1=Stateless+tests+(amd_debug%2C+parallel)
Related: #118657

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…file

It was copied from the randomized mode-2 path in `clickhouse-test`, where it is
turned off because it pushed the suite over the memory limit of the sanitizer
builds. These two jobs run on `amd_debug`, which is not a sanitizer build, so the
reason does not apply - and leaving the setting off would needlessly drop
parallel distributed `INSERT SELECT` from what the jobs cover.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Every replica of the `parallel_replicas` cluster is a loopback address of the one
server running the suite. Left unpinned the setting defaults to 1000 and is
clamped to the cluster's node count, so the cost model divided the read by 11 and
judged parallel replicas roughly 11x better than they are on a real cluster.
Pin a replica count the decisions can be read against.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [93900c8]

Summary: ✅


AI Review

Summary

Reviewed PR head 93900c857551aa85ec726f21bf4606565e8a5294, the diff, and all prior discussion. The PR selects automatic mode deterministically for half of the existing ParallelReplicas jobs, runs them on amd_debug, and adds a testing setting that bypasses the reading-thread cap while preserving production defaults. No actionable findings remain; previous findings are addressed or covered by the author's supported tradeoffs.

Missing context / blind spots
  • ⚠️ Full ParallelReplicas jobs at the current head are still pending in the CI report. Both 05259_autopr_ignore_thresholds_flips_small_read and 05257_autopr_rejected_by_cost_model pass in the current head's fast tests. The earlier full automatic-mode run isolated its sole failure to max_threads=1 in 05257; the current code pins it to 4. Completion of the current jobs will confirm the full-suite result.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 16, 2026
nickitat and others added 2 commits September 16, 2026 16:47
`Check Workflows` in the `Config Workflow` job re-runs the generator and fails if
the checked-in YAML differs, so adding job parameter sets requires committing the
regenerated files:

    PYTHONPATH=ci python3 -m praktika yaml

The diff is the two new job blocks plus the two `needs:` lists of the summary
jobs, which now include them.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=latest&name_0=PR&name_1=Config%20Workflow
Related: #120438

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The only conflict was `.github/workflows/pull_request.yml`, which is generated.
Resolved by taking master's copy and re-running the generator on the merged
source of truth rather than hand-resolving it:

    PYTHONPATH=ci python3 -m praktika yaml

Re-running the generator afterwards produces no diff, which is what the
`Check Workflows` step asserts.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread tests/clickhouse-test Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 16, 2026
`automatic_parallel_replicas_mode` = 1 needs `parallel_replicas_local_plan` = 1:
with 0, `InterpreterSelectQueryAnalyzer::buildQueryPlanWithParallelReplicas`
returns no plan and the optimization logs `Cannot build a plan with parallel
replicas. Skipping optimization`. The randomizer picks that setting 0-or-1, and a
randomized value is sent with every query and overrides the server profile, so
about half of the new jobs' queries would have covered nothing.

Measured against a server loading the profile, repeating one query shape:

    parallel_replicas_local_plan = 1 -> ParallelReplicasUsedCount = 3
    parallel_replicas_local_plan = 0 -> ParallelReplicasUsedCount = 0

Drop both colliding settings instead of just the mode. These two are the whole
intersection of the profile with `SettingsRandomizer.settings` today; the other
five settings the profile pins are not randomized.

Reported by the AI review bot on the pull request.
Related: #120438

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread tests/clickhouse-test Resolved
@nickitat

nickitat commented Sep 16, 2026 •

Copy link
Copy Markdown
Member Author
┌─────────────────────────────┬─────────────────────────────┬───────────────────┐
│                             │ mode-2 baseline (PR 118657) │  new mode-1 job   │
├─────────────────────────────┼─────────────────────────────┼───────────────────┤
│ probe plans built           │ 5,971                       │ 25,520            │
├─────────────────────────────┼─────────────────────────────┼───────────────────┤
│ cost-model evaluations      │ 26                          │ 7,366 (283×)      │
├─────────────────────────────┼─────────────────────────────┼───────────────────┤
│ plan switches               │ 18                          │ 76                │
├─────────────────────────────┼─────────────────────────────┼───────────────────┤
│ tests contributing switches │ AutoPR's own tests, all 18  │ ~12 organic tests │
└─────────────────────────────┴─────────────────────────────┴───────────────────┘
┌────────────────────────────────────────────┬─────────────┬──────────┐
│                                            │ evaluations │ switched │
├────────────────────────────────────────────┼─────────────┼──────────┤
│ clamp bound (both reading terms identical) │ 7,280       │ 0        │
├────────────────────────────────────────────┼─────────────┼──────────┤
│ clamp not bound                            │ 86          │ 76 (88%) │
└────────────────────────────────────────────┴─────────────┴──────────┘

We need to defuse this bytes threshold as well.

nickitat and others added 2 commits September 16, 2026 19:50
The cost model divides the read by `min(max_threads [* replicas], input_bytes /
merge_tree_min_bytes_per_task_for_remote_reading + 1)`. At the 2 MiB default that
second term clamps BOTH sides to the same value for any read below a few MiB, the
comparison collapses to `0 > output_bytes / replicas`, and the answer is "no"
before the cost model looks at anything.

The first run of these jobs measured it: of 7366 cost model evaluations, 7280
(98.8%) had both reading terms identical and not one of them switched, while the
86 that escaped the clamp switched 88% of the time. So 25434 of the 25520 probe
plans built were decided in advance, and the lane was exercising the probe rather
than the rewrite.

Lower the setting to 16 KiB in the profile so the decision is made by the cost
model on the table sizes stateless tests actually use. Verified locally against a
server loading this profile - a 400 KB read goes from

    400341 / 1 ? (400341 / 1 + ...)   both terms equal, decided in advance
to
    400341 / 1 ? (400341 / 3 + 89 / 3)   -> switches

and six query shapes (aggregation, uniqExact, sort, top-N, join, filtered
subquery) return byte-identical results with the plan rewritten.

It is not randomized by `clickhouse-test`, so unlike the other pinned settings it
needs no exclusion from the per-query overrides.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The previous commit said the change makes the cost model decide "on the table
sizes stateless tests actually use", and picked 16 KiB without deriving it. Both
overstate it. Measuring the read sizes of the 7366 cost model evaluations in the
first run of these jobs:

    p50            201 B
    p75          2,394 B
    p90        411,356 B
    p99      8,595,211 B

The median read is 201 bytes. Nothing un-clamps reads that small, and nothing
should - they must not be parallelized. So the clamp still decides about 85% of
evaluations, and it is right to.

What the threshold moves is the band above that. Genuinely-decided evaluations,
under the `max_threads` mix `clickhouse-test` actually generates (1-3 at 97%,
32 at 3%):

    2 MiB (default)    183   2.5%   1.0x
    256 KiB            577   7.8%   3.2x
    64 KiB             885  12.0%   4.8x
    16 KiB            1087  14.8%   5.9x
    4 KiB             1351  18.3%   7.4x
    1 KiB             1959  26.6%  10.7x

16 KiB sits on a flat part of that curve, so it keeps most of the available reach
while leaving the read task size plausible for the tests that read from object
storage. Keeping the value; only the claim was wrong.

No behaviour change - comment only.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread ci/jobs/functional_tests.py Resolved
The first run with the floor at 16 KiB measured the effect: genuinely-decided
evaluations went 86 -> 248 and plan switches 76 -> 236, against 7366 and 7746
cost model evaluations respectively. That is a real 3x, but well short of the
~1087 the offline estimate in the previous commit projected - it assumed the
profile's value applies uniformly across the suite and drew `max_threads` from
the randomizer rather than from what queries actually ran with. Go to 1 KiB, the
floor of what is worth setting before the read task size stops being plausible
for the tests that read from object storage.

That run also showed the cost is not confined to the cost model: the setting
governs real read-task sizing, and `03581_parallel_replicas_task_size` asserts
`ParallelReplicasNumRequests <= 15` on a `s3_cache` table - the request count
this floor directly controls. It was the only failure in 14242 tests. It already
pins `max_threads` and `merge_tree_min_read_task_size` and is tagged
`no-random-settings`, but that tag only covers the per-query randomizer and gives
no protection against a server profile, so pin this setting there too.

Nothing else regressed at 236 rewrites: no `NOT_FAILED`, and none of the
optimization's own LOGICAL_ERROR invariants fired.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=latest&name_0=PR&name_1=Stateless+tests+%28amd_debug%2C+AutoParallelReplicas%2C+parallel%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
0 is not "a smaller threshold", it is a distinct code path:
`considerEnablingParallelReplicas` reads the setting as
`value ? input_bytes / value + 1 : SIZE_MAX`, so zero makes the clamp
structurally unreachable and every evaluation is decided by the cost model. Any
non-zero value leaves a residue - at 1 the clamp still binds for reads of a
couple of bytes.

Progression measured across runs of these jobs:

    2 MiB (default)     86 of 7366 evaluations escaped the clamp,  76 switched
    16 KiB             248 of 7746 evaluations escaped the clamp, 236 switched
    1 KiB              600 of 7568 evaluations escaped the clamp, 561 switched
    0                  every evaluation

Zero is also the quieter choice for real reading. `MergeTreeReadPoolBase` raises
`min_marks_per_task` only when `min_bytes_per_task / avg_mark_bytes` exceeds it,
so zero skips that heuristic and leaves task sizing on its default path, instead
of shrinking tasks the way a small non-zero value does - which is what broke
`03581_parallel_replicas_task_size` at 16 KiB. That test keeps its pin anyway: it
asserts on coordinator request counts and `no-random-settings` gives it no
protection against a server profile.

Verified against a server loading this profile. The denominators are now exactly
`max_threads` and `max_threads * replicas` with no clamping, and a 50 byte read -
which 1 KiB would still have clamped - gets a real evaluation and is correctly
declined because shipping the output costs more than the reading saves:

    50 / 3 ? (50 / 9 + 40 / 3)  ->  16 ? 18, declined

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nickitat

Copy link
Copy Markdown
Member Author

Thanks - the first finding was right and is fixed in 3ad5c39: --autopr now also drops parallel_replicas_local_plan from the randomized settings. It was a real hole. Verified against a server loading the profile, repeating one query shape:

parallel_replicas_local_plan = 1  ->  ParallelReplicasUsedCount = 3
parallel_replicas_local_plan = 0  ->  ParallelReplicasUsedCount = 0
                                      "optimizeTree: Cannot build a plan with parallel replicas"

At a 50/50 randomization that would have left about half the lane covering nothing. I also checked the rest of the intersection rather than just this one setting: the profile pins seven settings, exactly two are randomized, and both are now excluded.

On parallel_distributed_insert_select, I'm proposing to leave it enabled, with measurements rather than a counter-argument.

The two tests cited both already pass --parallel_distributed_insert_select=0 themselves, so neither can fail:

01889_sqlite_read_write.sh:124   ${CLICKHOUSE_CLIENT} --parallel_distributed_insert_select=0 --query=...
02895_npy_output_format.sh:13    ${CLICKHOUSE_CLIENT} --parallel_distributed_insert_select=0 -q ...

24 stateless tests carry that opt-out and are likewise self-protecting. The real exposure would be a test doing INSERT ... SELECT into a shared external resource without the opt-out, so the question is empirical. Two runs of the new jobs, at increasing rewrite volume:

plan rewrites failures
76 0
236 1 - 03581_parallel_replicas_task_size, unrelated (asserts on coordinator request counts, which the profile's read-task floor governs; fixed by pinning the setting in the test)
561 0

No INSERT ... SELECT failure at any volume, and NOT_FAILED was 0 throughout. A third run with the read-task clamp fully disabled is in flight; if it turns up an INSERT ... SELECT failure I'll restore the guard rather than argue with it.

The reason I'd rather not disable it pre-emptively: the ordinary randomizer sets parallel_distributed_insert_select = 0 for a stated reason that does not apply here - "seem to throw us over the memory limit in flaky checks with sanitizers" - and these jobs run on amd_debug, which is not a sanitizer build. Turning it off would drop parallel distributed INSERT ... SELECT from what the lane covers for a reason that isn't true of it.

nickitat and others added 5 commits September 17, 2026 08:44
Reuse `--no-zookeeper --no-shard` from the `ParallelReplicas` jobs, so the lane
stays on ordinary `MergeTree` reads instead of also running the whole multi-node
surface under the AutoPR profile.

Measured on the previous run of these jobs before making the change: of the 41
tests that produced a plan rewrite, exactly one - `03008_local_plain_rewritable` -
is skipped by these two flags. The rewrites come overwhelmingly from ordinary
reads (`02235_remote_fs_cache_stress`,
`04401_packed_skip_indices_concurrent_read_long`, `02941_variant_type_3`,
`01304_direct_io_long`, the `03036`/`03037`/`03038` dynamic subcolumn family). So
the multi-node tests buy close to no AutoPR coverage while widening what can fail
for reasons that have nothing to do with the optimization.

Reported by the AI review bot on the pull request.
Related: #120438 (comment)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`filesystem_prefetch_min_bytes_for_single_read_task` is an alias of
`merge_tree_min_bytes_per_task_for_remote_reading` (`DECLARE_WITH_ALIAS`,
Settings.cpp:7275), and the randomizer sets it to 1Mi, 8Mi or 16Mi. That value is
sent with every query and overrides the 0 the profile pins, putting the per-task
byte floor back - which clamps both terms of the cost model to the same value and
decides the query before the cost model is consulted.

It shows up plainly in the last run: of 7343 cost model evaluations, 6203 (84%)
still had identical reading terms despite the profile pinning the floor to 0. The
1140 that did not are the tests where randomization is off or whose read exceeded
the drawn value.

The previous commit claimed these two settings "are the whole intersection of the
profile with `SettingsRandomizer.settings`". That was wrong: the check compared
canonical names only, so a setting pinned under one name and randomized under its
alias did not match. Comparing by alias finds three collisions, not two. Both
names are dropped here so it does not matter which one the profile uses.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two thresholds decide a query before the automatic parallel replicas cost model
is consulted: `automatic_parallel_replicas_min_bytes_per_replica`, and the cap on
how many threads a read can usefully occupy, which makes a read too small to
occupy `max_threads` compare equal on both sides so that the comparison collapses
to `0 > output_bytes / replicas`. Both are right in production - there is a test,
`04035_autopr_no_parallel_replicas_for_small_reads`, asserting the second - but
they leave these jobs exercising the probe rather than the rewrite. At the
defaults only 86 of 7366 cost model evaluations got past them, and 76 switched.

`automatic_parallel_replicas_ignore_thresholds` ignores both, so the cost model
comparison decides every query. It deliberately does not touch read task sizing,
and it does not suppress recollection of drifted statistics - a decision made on
stale statistics is not a decision made by the cost model.

This replaces forcing the same effect through
`merge_tree_min_bytes_per_task_for_remote_reading` = 0, which reached the cost
model only because that setting is also the per-task byte floor for real reads.
That worked - ties went to 0 and switches to 4464 of 7555 evaluations - but it
shrank real read tasks too, and broke four tests asserting on S3 request counts
and query-condition-cache profile events. Those tests are untouched now, and the
two workarounds it needed are reverted: the pin in
`03581_parallel_replicas_task_size` and the exclusion of
`filesystem_prefetch_min_bytes_for_single_read_task` from the randomizer.

`04035_autopr_no_parallel_replicas_for_small_reads` sets the new setting to 0: it
asserts the guard, so it has to run with the guard on, and `no-random-settings`
gives it no protection against a server profile.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`Style check` requires a new setting to be recorded under the current version's
`addSettingsChanges` block. I added the entry under "26.9", which was the newest
block when the commit was written; merging master brought a "26.10" block above
it, so the entry was one release behind and the check failed with:

    Session setting 'automatic_parallel_replicas_ignore_thresholds'
    must be recorded in the '26.10' block

Move it, leaving the values and reason text unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 93900c857 with master 204d73c05 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

162 translation units recompiled, 1936 s compile time in total, 162 of them have a recent master baseline.

Job report

The dedicated setting did what it was meant to: the four tests that the previous
approach broke by shrinking real read tasks - on S3 request counts and
query-condition-cache profile events - all pass again, and
`04035_autopr_no_parallel_replicas_for_small_reads` passes with its pin.

What is left is the same case as `04035`: two more tests whose subject IS a
threshold gate, so they cannot run in a profile that disables them.
`05045_autopr_skip_plan_build_for_small_reads` asserts that the cheap pre-check
skips building the parallel-replicas plan below
`automatic_parallel_replicas_min_bytes_per_replica`, and `05100_autopr_gate_lazy_read`
asserts which read the gate sizes the plan by under lazy materialization. Both
now set `automatic_parallel_replicas_ignore_thresholds` to 0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nickitat

Copy link
Copy Markdown
Member Author

Expression-over-a-plain-projection is 71% of Expression failures and 50% of all failures — and that is precisely what autopr-wrappers-min fixes.

It talks about failures to match local and PR plans. We need #118657 to significantly improve coverage.

The sequential lane fails four query-condition-cache tests. They are not artifacts
of the lane's configuration: a plan rewritten by automatic parallel replicas never
populates the query condition cache, so the next query over the same condition
misses it. `system.query_condition_cache` holds one entry after a single-node run
and none after a rewritten one. This is the same root cause as
#115153 - the rewritten plan's reads
carry ranges but not conditions - and has been handed to that PR with a repro.

They cannot go in `parallel_replicas_blacklist.txt`. Two of them,
`03229_query_condition_cache_profile_events` and
`05099_query_condition_cache_formatdatetime_settings`, PASS in
`Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, sequential)`,
where parallel replicas is forced on; they fail only when the optimization does
the rewrite. That list inverts its verdict, so listing them there would report
them as needing removal and turn the forced job red.

Add `tests/autopr_blacklist.txt`, read only under `--autopr` and tolerate-only:
a listed test may fail without failing the job, and a listed test that passes is
not flagged. A pass carries no information here anyway, since the optimization
only switches a query when its statistics say it pays off.

Remove the entries once #115153 lands - the file documents what it is waiting on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
nickitat and others added 2 commits November 12, 2026 15:15
…jobs

The pin worked around #123061:
with parallel replicas, `optimize_aggregation_in_order` rejected every projection,
including `_minmax_count_projection`. It was added on 2026-09-30, one day before
the fix #123098 was merged, and is
obsolete now, so the setting is randomized again in both halves of the jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat

Copy link
Copy Markdown
Member Author

@nickitat maybe randomization in one of the existing jobs will be enough?

@alexey-milovidov are you fine with this approach: we take hash(commit sha) % 2 and decide whether to run the existing ParallelReplicas job with autopr enabled or not?

nickitat and others added 2 commits November 15, 2026 16:39
…gs limit

The test asserts that parallel replicas are used, and failed in the autopr half of
the `ParallelReplicas` job: a random settings limit only constrains the randomizer,
so the server profile's `automatic_parallel_replicas_mode` = 1 left the decision to
the cost model, which did not switch these queries. Same fix as for 04731.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=bad7415bcf0cb0cfc6ff9e671ae5b821289e4e88&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
#120438

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every second run these jobs put the whole suite through the automatic parallel
replicas optimization, and the point of that is to see that no invariant breaks
on the way. The release `arm_binary` build compiles `chassert` out and only
throws on `LOGICAL_ERROR`; a debug build checks both.

`amd_debug` rather than `arm_debug`: pull requests build `amd_debug` anyway, while
`Build (arm_debug)` is skipped on small PRs together with the `arm_debug` stress
test. On master `Stateless tests (amd_debug, parallel)` runs the full suite in a
median of 17 minutes, against 29 for `arm_binary, ParallelReplicas, parallel`.

The workflow YAML is regenerated with `PYTHONPATH=ci python3 -m praktika yaml`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread ci/jobs/functional_tests.py Resolved
nickitat and others added 2 commits November 15, 2026 18:23
…s_autopr`

Without a CI environment, `_Environment.from_env` sets the SHA to "TEST", which
passed the empty check and raised `ValueError` in `int(sha[:8], 16)`, so a direct
run of a `ParallelReplicas` functional-test job failed before setup.

Review: #120438 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two queries of `02911_analyzer_order_by_read_in_order_query_plan` order by
`sin(a / b)` alone, which is the same value for every row with `a = b`, so most of
their rows tie. The reference holds the order of a read-in-order merge on one
replica; parallel replicas return the tied rows in another order, which failed the
`ParallelReplicas` job reproducibly (71 of 71 reruns). The plan checks of the test
already run without parallel replicas, and now these two result checks do too.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=1fa703283f86bc02de4daeb0f21a5260280162af&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
PR: #120438

Co-Authored-By: Claude Opus 5.5 <[email protected]>
JingYanchao pushed a commit to JingYanchao/ClickHouse that referenced this pull request Nov 16, 2026
The test asserts that a repeated INSERT ... SELECT with the same
insert_deduplication_token is deduplicated. The dedup block id depends on
how the source read is chunked, so both inserts must produce the same
chunks; the test pins the query-level read shape but not parallel
replicas, which the ParallelReplicas jobs enable server-side.

With a small randomized index_granularity (15 on ClickHouse#94017) the 20000-row
source has 1333 marks. On s3-backed parts the replicas read it in 13 or 14
requests depending on timing, and when the two inserts make a different
number of requests the chunks differ and the repeat is appended (40000
instead of 20000). Measured locally: 21 of 21 failing pairs had different
request counts, 16 of 16 deduplicated pairs had equal ones; a different
mark split alone does not break deduplication (local disk: 173 requests
per insert, 0 of 400 runs failing). In the automatic parallel replicas
runs of ClickHouse#120438 the first insert runs single-node and the second on
parallel replicas, so those draws fail every rerun.

CI: ClickHouse#94017 arm_binary ParallelReplicas s3 (22/53 reruns), ClickHouse#120438
amd_debug and arm_binary ParallelReplicas s3 (94/94, 50/50), ClickHouse#124526
arm_binary ParallelReplicas s3 (38/38). No master failure.

Same fix as 05080_dedup_hash_lazy_replicated_column in ClickHouse#123943: skipped
in the ParallelReplicas jobs, enable_parallel_replicas = 0 elsewhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… build

`clickhouse-test` turns settings randomization off for `--s3-storage` on any
non-release build, so moving the `ParallelReplicas` jobs to `amd_debug` silently
ran both modes without it: 95% of the initial queries of the autopr run on
49045f3 carried no randomized settings, against 15% on the `arm_binary` run of
bad7415. The plan rewrite then met no randomized settings at all, and with
`max_threads` left at its default the cost model switched 3541 queries instead
of 5227 (the randomizer's `max_threads` of 1 to 3 is where it switches nearly all
it evaluates).

The rule now spares runs with `--no-parallel-replicas`, which only these jobs
pass. Whether the jobs still fit their timeout this way is for CI to show.

PR: #120438

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

nickitat and others added 3 commits November 16, 2026 22:09
`05257_autopr_rejected_by_cost_model` meant every row to leave the replicas as a
1000-byte string, but `repeat('x', 1000)` is a constant and is not shipped: the
collector at the `Sorting` boundary recorded output bytes equal to the input,
the 8-byte key alone. Outside of the autopr job the read cap still declined the
query; under its `automatic_parallel_replicas_ignore_thresholds` the formula
`190610 / 1 ? (190610 / 3 + 190610 / 3)` applied parallel replicas whenever the
randomizer picked `max_threads` 1, reproducibly (186 of 186 reruns).

The string is now built per row from hashes of the key, so it is not a constant
and does not compress away in the compressed pricing of the output.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=fca3992f88acd038ddc65edbcd752607a863a114&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
PR: #120438

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The string built with `arrayMap` kept the query out of the cost model in Fast
test: the top node of the replicas plan, an `Expression`, found no step with a
matching hash in the single-node plan, so all five counters stayed 0. Four
`cityHash64`s of the key concatenated give a 64-byte string per row without a
lambda; `SHA512` would need a build with SSL, which Fast test is not. The output,
about 6.4 MB, stays well above the 2 * 190610 bytes at which the cost model
declines the query with `max_threads` 1.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=69c8a798c431edeb2400e38e88abfc44f912f2fb&name_0=PR&name_1=Fast%20test
PR: #120438

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both computed strings kept the query out of the cost model: a projection
computed from the key tops the replicas plan with an `Expression` above the
`Sorting`, and its hash matched no step of the single-node plan, so all five
counters stayed 0 in Fast test. The lambda was not the cause; the shape is.

Back to the constant string, which is not shipped, so output and input are both
the 190610 bytes of the key. With `automatic_parallel_replicas_ignore_thresholds`
the cost model then declines from 3 threads on (with 2 it applies, 95305 against
95304), so `max_threads` is pinned to 4. Without the setting the read cap declines
the query anyway, as before.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120438&sha=3c0cb203ce53183a71eca08c003135675b51260b&name_0=PR&name_1=Fast%20test
PR: #120438

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat
nickitat added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit a879c46 Nov 18, 2026
378 of 380 checks passed
@nickitat
nickitat deleted the autopr-ci-job branch November 18, 2026 00:02
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 2026
@hanfei1991

hanfei1991 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

cursor Bot pushed a commit to ylw510/ClickHouse that referenced this pull request Nov 18, 2026
Since ClickHouse#120438 the autopr ParallelReplicas runs set
`automatic_parallel_replicas_ignore_thresholds = 1`, so the read cap no
longer declines this small read and the verdict rests on the cost formula:
at `max_threads = 4` and 3 replicas it applies when the shipped bytes are
less than half the read bytes.

The shipped keys are priced with the factory default codec ZSTD(3), the
read with the part's codec, which tests/config/install.sh randomizes across
LZ4, ZSTD(1) and ZSTD(3). On a ZSTD(3) part both sides are 188256 bytes
(47064 < 78440, declined); on an LZ4 part the read is 400341 bytes
(100085 > 96113, applied), which is what the failing coverage job logged.

Pin `default_compression_codec = 'ZSTD(3)'` on the table, as install.sh
documents for codec-sensitive tests and as 03634 and 04100 already do.

Validation (debug build, server default codec LZ4, ignore_thresholds = 1):
unchanged test 6/6 FAIL with the CI diff and formula line; pinned test 3/3
OK, 50/50 randomized with and without the setting, 6/6 each under ZSTD(1)
and ZSTD(3); all 87 runnable autopr tests pass under LZ4 with the autopr
profile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat

Copy link
Copy Markdown
Member Author

@groeneai

Copy link
Copy Markdown
Collaborator

Yes, #132570 is my fix: the test's verdict depended on the default codec that CI randomizes per job, and autopr-mode runs that drew LZ4 made the cost model apply parallel replicas. The PR pins ZSTD(3) on the test table and merged at 11:11Z; the 3 master failures (e8cb3beb, 5b561b4d, ad64f1e7) all predate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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.

6 participants