Repository navigation
Skip rebuilding the automatic parallel replicas probe plan when its last build was undecided - #130565
Conversation
…decided When automatic parallel replicas built the plan with parallel replicas and the outcome left no decision (`AutoParallelReplicasPlansNotComparable`, `AutoParallelReplicasPlanWithoutParallelReplicas`, or a step that cannot collect statistics), nothing was remembered, so every later execution built that plan again, index analysis included, and threw it away. On short queries this cost became the result: on TPC-H sf=1 automatic mode was 5.5% slower than one node, all of it from ten such queries. Remember the outcome under the same key as the boundary (the single-node plan's root hash and the boundary settings). It is not a verdict: - Executions take turns on the entry: one in every `automatic_parallel_replicas_undecided_retry_after_executions + 1` (default 10) builds the plan again, so concurrent executions never all rebuild at once. 0 turns it off. - What join reordering read from `HashTablesStatistics<HashJoinEntry>` (`RuntimeHashStatisticsContext::getCachedHint`), in both plans, misses included, is kept with the entry. The plan is built again at once when one of them appears, disappears or changes by more than twice; a smaller change waits for the next turn, since a growing table replaces its stored size on every run. - A `CollectorUnsupported` entry keeps the statistics entry it saw when its collection started, and no longer holds once a later collection has replaced it, whatever order the two finished in. A skipped execution counts `AutoParallelReplicasRetryDeferred` beside the event of the remembered outcome. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [6ab11e5] Summary: ✅
AI ReviewSummaryThe PR adds a bounded cache for automatic parallel-replica planning attempts that end without a decision, with one immediate retry followed by configurable execution-based retries. The earlier bot findings and the reported warm-cache test regression are addressed in the current code. No outstanding actionable findings. Using the CI binary for head Final VerdictStatus: ✅ Approve |
…tatistics Keeping a snapshot of what join reordering read, and comparing it with a tolerance of our own, was a lot of machinery for one case: the first execution of a join measures the hash tables that join reordering takes row counts from, so the build after it often orders both plans alike. Cover that case directly: after the first undecided outcome for a key, the turn of the next execution comes at once, and from the second outcome on the regular quota applies. Later changes of the statistics wait for the next turn, as changes within the tolerance did before. This removes the reads recorded in `getCachedHint`, their plumbing through the optimization settings and the plan with parallel replicas, the snapshot in the entry, and `HashTablesStatistics::findEntry`. #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `automatic_parallel_replicas_undecided_retry_after_executions` at its largest value the period cannot have one added, and the offset that gave the first execution after an entry's first outcome its turn wrapped into a skip: the immediate retry never came. Admit that execution explicitly, and count the turns from the one after it. The descriptions of `automatic_parallel_replicas_remember_boundary` and of the new setting both promised that turning one of them off builds the plan with parallel replicas on every execution. The two caches are independent, so a benchmark of that cost has to turn off both. #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
An undecided entry can be recorded after another execution of the same plan matched and collected statistics, when the two raced. Executions that decline at the remembered boundary never read the entry, but one whose statistics favour parallel replicas needs the replicas plan, and the stale entry made it skip building it. Such statistics are evidence that the plans match now, so the entry is forgotten and the plan is built. That covers what the snapshot of the statistics in a `CollectorUnsupported` entry was for, apart from a failed and a successful collection finishing at the same moment, after which a drifted boundary is recollected at the next turn. Remove the snapshot, its check, and the unit tests of that race. #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Statistics that favour parallel replicas do not prove the plan with them can be adopted: when adopting it fails after the cost model, for example when a set of the plan has no counterpart (`moveSetsFromLocalPlanToReplicasPlan`), the entry is recorded with exactly those statistics in place, and the previous commit deleted it on every execution, which built the plan every time. Remove that override. The race it was for, an outcome recorded just after another execution matched, only defers the switch until the next turn. The test now covers that case, after `05401_autopr_set_transplant_unpaired_sets`: once the immediate retry has failed to adopt the plan as well, the next executions skip it. #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ordinary join that keeps receiving inserts tested the tolerance of the removed join-statistics tracking, and repeated the cycle the `LIMIT` case already covers; the fifth execution of the adoption case repeated the fourth. Remove both. Turning the deferral off needs a third execution to tell it from the immediate retry, which builds the second one either way. The two unit tests of a failed collection are one sequence: remembered, then forgotten by a collection that succeeds. #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Nothing branches on the reason any more: a skipped execution only counts the event its outcome was counted in. Store that event, and remove the enum and the function that mapped it. #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes52 object files changed (+80.92 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units185 translation units recompiled, 1446 s compile time in total, 185 of them have a recent master baseline. |
When a collection of runtime statistics measured zero input and zero output bytes, `RuntimeDataflowStatisticsBlock` dropped it and recorded nothing else, so every later execution found no statistics and built the plan with parallel replicas again. This happens, for example, when an inner join has an empty build side and never reads its probe side, which holds the coordinated read (TPC-DS q46-like queries filtered to an empty dimension: a 11-21 ms build on every run of a 22-167 ms query). The zeros are still not stored as statistics: the statistics key ignores the values of string constants, so a query that differs only in such a constant and does read data would decide from them. Instead the plan is marked undecided, like a collection a step cannot take part in, so it is deferred by `automatic_parallel_replicas_undecided_retry_after_executions` and keeps collecting on its turns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The four early returns of `decideAtBoundary` (the boundary is the read itself, no index analysis, a read served from a projection, no selected rows) counted `AutoParallelReplicasPlansNotComparable` but remembered nothing. With `automatic_parallel_replicas_remember_boundary = 0` they are found only after building the plan with parallel replicas, so such a plan was built on every execution, contrary to the promised independence of the two settings. They now record the plan as undecided when the plan with parallel replicas was built for this execution. From a remembered boundary the same outcome is reached without building it, so nothing needs remembering there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Undecided` -> `UndecidedQuery`, `UndecidedCache` -> `UndecidedQueryCache`, `undecided_cache` -> `undecided_query_cache`, `undecided_key` -> `undecided_query_key`. Also assert that an outcome recorded after building the plan with parallel replicas has that plan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…othing `LIMIT` without `ORDER BY` makes the plans incomparable only because of a bug that is to be fixed, and a correlated subquery is to be ruled out before building the plan with parallel replicas (#129544). Either change would have broken the cases built on them. An inner join with an empty build side, whose collection measures nothing, is deferred by design, so the turn-taking, the disabled setting and the largest value are checked with it instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Common/ProfileEvents.cpp # src/Processors/QueryPlan/Optimizations/considerEnablingParallelReplicas.cpp
A read that selects no rows has nothing to decide; `AutoParallelReplicasPlansNotComparable` is only the event it is counted in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the merge with master, a plan that builds a set is rejected while matching the two plans ("The plan builds a set,
its root must be preserved"), before statistics are collected, so the case no longer reaches the cost model and
checks nothing the other not-comparable cases do not. The random settings limits were only for its table.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`modernize-use-nodiscard` is enabled on master now, which the merge brought in. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130565&sha=latest&name_0=PR PR: #130565 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the adoption case of `05617` gone, nothing checked that statistics which favour parallel replicas do not make an execution build the plan again after it failed to be adopted. The ambiguous reads of `05628` are declined after the cost model favoured replicas, so two more runs of that shape cover it: the immediate retry builds the plan and declines the same way, and the next run skips the build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
I built this PR merged into current master (5ac4d89f, debug) and ran it against a local server with the 3-replica localhost cluster.
05617_autopr_undecided_retry fails on current master, 3 of 3 runs, only in the undecided_warm rows:
-undecided_warm_1 1 0 0 1 0 0
-undecided_warm_2 1 0 0 0 1 0
+undecided_warm_1 1 0 0 0 1 0
+undecided_warm_2 0 0 0 0 0 1The first run already matches the two plans and collects statistics, and the second decides from them without building. With #130516 reverted locally on the same tree, the test passes 3 of 3. That PR merged on 2026-11-19, after this PR's CI ran on 2026-11-17: the probe now takes its join estimates from the single-node analysis, so the "no row estimates for the filtered read" premise of this case no longer holds. The immediate retry is still exercised by the undecided_empty_* and undecided_no_rows_* rows and by 05628, but this was its only cold-to-warm example. Does the immediate retry still have a case of its own after #130516? If not, UndecidedQuery::first and the execution - 1 arithmetic could go.
Minor: master is at 26.12 now (it was 26.11 at this branch's merge base), and the new setting's history row still says 26.11.
Checked, no issue found:
RuntimeDataflowStatisticsUndecided.FailedCollectionIsRememberedUntilOneSucceedspasses, and05628passes 3 of 3.- Turn-taking: 120 executions of the empty-build-side query with
automatic_parallel_replicas_undecided_retry_after_executions = 3built the probe 31 times one at a time (the first build, the immediate retry, then one in four) and 21 times at concurrency 8. So concurrent executions do not all rebuild. EXPLAINof a joined query builds no probe and leaves no entry: theSELECTafter twoEXPLAINs builds and collects like a fresh key.
… in the `26.12` history Master is at `26.12` now. Related: #130565 (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #130516 the probe takes its join estimates from the single-node analysis, so the old three-table join already matches on its first run. Identical subqueries reading the same table cannot be paired with the single-node reads, so they still have no estimates on a cold run, and the immediate retry is what lets the second run match. Related: #130565 (review) Related: #130516 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: No queries show a performance change caused by this PR. The only flagged query, clickbench Q10, is +20.7% slower (111 ms against 92 ms). That is still inside master's current range of 83–115 ms, and this query's timings have been noisy on master. The PR only changes how automatic parallel replicas decides whether to rebuild its parallel-replicas probe plan after an undecided outcome. At most that skips work, so it cannot plausibly slow down a single-table GROUP BY with COUNT(DISTINCT), and the decision to suppress this row stands. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Backport #130565 to 26.11: Skip rebuilding the automatic parallel replicas probe plan when its last build was undecided
Backport #130565 to 26.10: Skip rebuilding the automatic parallel replicas probe plan when its last build was undecided
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Automatic parallel replicas (
automatic_parallel_replicas_mode = 1) no longer builds the plan with parallel replicas on every execution of a query whose last build ended without a decision: the execution after the first such build builds it again at once, and from then on one in everyautomatic_parallel_replicas_undecided_retry_after_executions + 1executions (default 10) does.Related: #129544
Automatic parallel replicas decides by building the plan with parallel replicas (the probe) and matching it against the single-node plan. When that ends without a decision, nothing was remembered, so every later execution of the query built the probe again, index analysis included, and threw it away. The outcomes that leave no decision are:
AutoParallelReplicasPlansNotComparable);AutoParallelReplicasPlanWithoutParallelReplicas);On short queries this cost is the result. On TPC-H sf=1 (staging, 3 replicas) automatic mode was 5.5% slower than one node, all of it from ten such queries at +4–28 ms per run. A replay of 112 join queries built the probe on every warm run: median 1.08x, up to 148 ms of build.
Approach
The outcome is remembered under the same key as the boundary: the single-node plan's root hash plus the boundary settings. It is a bounded negative cache, not a verdict:
automatic_parallel_replicas_undecided_retry_after_executions + 1(default 10) builds the probe again. The others skip it and countAutoParallelReplicasRetryDeferredbeside the remembered outcome's event. Concurrent executions cannot all rebuild at once, and a hit never extends the wait. 0 turns it off.automatic_parallel_replicas_remember_boundary = 0no longer makes every execution build the probe on its own: undecided plans are still skipped. To benchmark the cost of the probe, also setautomatic_parallel_replicas_undecided_retry_after_executions = 0.Workflow [PR]
Sync PR [sync-upstream/pr/130565]
Version info
26.12.1.131-master(included in26.12and later)26.11.1.2920,26.10.10.3