Repository navigation
Ignore parallel_replicas_min_number_of_rows_per_replica when automatic parallel replicas builds its plan - #126815
Conversation
|
Workflow [PR], commit [2c17568] Summary: ✅
AI ReviewSummaryThis PR removes redundant index analysis for Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested. Latest-head CI remains pending. |
…plica` In mode 1, `automatic_parallel_replicas_min_bytes_per_replica` skips small reads before the plan with parallel replicas is built. With randomized MergeTree settings the test's reads fell under the gate in 1 of 50 runs of the TSan flaky check, so the mode-1 queries built no such plan. Set the gate to 0, as the sibling tests do, and count the build with `AutomaticParallelReplicasProbePlansBuilt`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126815&sha=13945e069464204e772d096ba7f8a9f4710939af&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 PR: #126815 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 Compile time of recompiled translation units1323 translation units recompiled, 8530 s compile time in total, 1322 of them have a recent master baseline. Translation units without a recent master baseline:
|
…matic mode's plan build To decide, `automatic_parallel_replicas_mode` builds a plan with parallel replicas. That build turns the automatic mode off in its own context, so with `parallel_replicas_min_number_of_rows_per_replica > 0` the planner ran the row estimate there: a full primary-key and skip-index analysis of the read, on every run that builds the plan. The automatic mode decides with its own cost model, so the estimate adds nothing. In a replay it cost up to 29 s per query (p99 1.4 s). Zero the setting in the build's context, and drop it from the query's top-level `SETTINGS` clause, which the nested interpreter would otherwise re-apply. The main planning already skips the estimate while the automatic mode is on. Local repro (two-table join, 937K marks): with min rows 50M and the automatic mode, 5 -> 4 index analysis rounds, probe build 184 -> 5 ms, query 398 -> 228 ms, now the same as without the setting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…obe's nested query contexts Zeroing the setting only in the root context missed a subquery's own `SETTINGS` clause: the planner reads the setting from each query node's context, where that clause is applied. With `(SELECT * FROM sales SETTINGS parallel_replicas_min_number_of_rows_per_replica = 50000000)` as a join input, the probe build still ran the estimate (one more index analysis round) and the threshold kept the candidate local (`AutoParallelReplicasPlanWithoutParallelReplicas` 0 -> 1). Walk the probe's query tree before planning and zero the setting in every query and union node's context. The clauses stay in the tree, since they are part of the hash that pairs nodes with the single-node plan. The root override stays too: the outer planner collects filters for the estimate as soon as it is constructed. `05399_autopr_plan_without_parallel_replicas` used the min-rows threshold as its planner-side rejection, which no longer happens in the probe build. Use `parallel_replicas_allow_in_with_subquery = 0` instead, which keeps the original counter values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iding the setting Overriding `parallel_replicas_min_number_of_rows_per_replica` in the query tree's contexts still missed views analyzed later by their own interpreter (`analyzer_inline_views = 0`, `StorageView::read`) and the `view` table function: their body's `SETTINGS` clause restores the threshold after the override. With the threshold in such a body, the probe build ran one more index analysis round and the threshold kept the candidate local (`AutoParallelReplicasPlanWithoutParallelReplicas` 0 -> 1). No setting can hold against a later `SETTINGS` clause, so mark the probe build with a context field instead, like `join_analyze_mode`: every context copied from the probe's inherits it, including the one `getSQLSecurityOverriddenContext` builds from the global context. The planner skips the estimate, and the filter collection for it, in marked contexts. The stored `SETTINGS` clauses are untouched, so tree hashes do not change. This replaces the root override and the tree walk. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…plica` In mode 1, `automatic_parallel_replicas_min_bytes_per_replica` skips small reads before the plan with parallel replicas is built. With randomized MergeTree settings the test's reads fell under the gate in 1 of 50 runs of the TSan flaky check, so the mode-1 queries built no such plan. Set the gate to 0, as the sibling tests do, and count the build with `AutomaticParallelReplicasProbePlansBuilt`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126815&sha=13945e069464204e772d096ba7f8a9f4710939af&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 PR: #126815 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…robe_ignores_min_rows_per_replica` Mode 1 builds the plan with parallel replicas on every run only while it cannot match it with the single-node plan, which is the case today for `LIMIT` without `ORDER BY` only because `tryPushDownLimit` adds a `Limit` to each branch of the `Union`. Once the plans match, the first run remembers the boundary and later runs of the same plan decide without building it, so the threshold queries would stop exercising the fix. Mode 2 builds it on every run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2eed64b to
2c17568
Compare
Backport #126815 to 26.10: Ignore `parallel_replicas_min_number_of_rows_per_replica` when automatic parallel replicas builds its plan
… estimate
`indexHint` keeps its arguments in a DAG of its own (`FunctionIndexHint::getActions`),
so `dagContainsNonReadySet` scanning only the outer nodes missed an unbuilt `IN` set
there. Index analysis still descends into that DAG, so the estimate built a throwaway
copy of the set: `WHERE indexHint(k GLOBAL IN (SELECT n FROM input('n UInt64')))` with
`parallel_replicas_min_number_of_rows_per_replica = 1` still failed with
`INVALID_USAGE_OF_INPUT`, and `indexHint(k IN (SELECT ...))` ran its subquery twice.
Collect the filter's sets with `appendSetsFromActionsDAG`, which already recurses into
(nested) hints, and decline when any of them is not built. `dagContainsNonReadySet` is
left as is: its other callers evaluate the filter, and `indexHint` evaluates to 1
without its arguments.
The test gains an `indexHint` case. It bounds the inserted rows, because the hint passes
every row of the granules it selects, so only that bound shows the read still pruned by
the set. The automatic-mode case is dropped: since ClickHouse#126815 the automatic mode's probe
plan never runs the estimate, so the case passed with this PR's change reverted.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
parallel_replicas_min_number_of_rows_per_replicais ignored whileautomatic_parallel_replicas_modebuilds its plan with parallel replicas, including in subqueries and views. Previously the row estimate for it ran a full extra index analysis on every such build, and its threshold could keep that plan from using replicas.To decide whether to use parallel replicas,
automatic_parallel_replicas_modebuilds a plan with parallel replicas and costs it against the single-node plan. That build turns the automatic mode off in its own context, so withparallel_replicas_min_number_of_rows_per_replica > 0the planner ran its row estimate there: a full primary-key and skip-index analysis of the read, repeated on every run that builds the plan. On large primary indexes this took seconds per query. The automatic mode decides with its own cost model, so the estimate added nothing, and when its threshold was not met it also disabled parallel replicas in the plan being costed (AutoParallelReplicasPlanWithoutParallelReplicas).The build is now marked with a context field,
is_automatic_parallel_replicas_probe, likejoin_analyze_mode. Every context copied from it inherits it, including the contexts of views analyzed later by their own interpreters, theviewtable function, and the contextgetSQLSecurityOverriddenContextbuilds from the global one. The planner skips the estimate, and the filter collection for it, in marked contexts. A settings override would not hold here: a subquery's or a view body's ownSETTINGSclause re-applies the threshold, and those clauses cannot be removed because they are part of the tree hash that pairs nodes with the single-node plan. The main planning already skips the estimate while the automatic mode is on.Local repro (two-table join with
LIMITand noORDER BY, 937K marks, threshold 50M, automatic mode on): 5 → 4 index analysis rounds, plan build 184 → 5 ms, query 398 → 228 ms. These now match the same query without the threshold.05399_autopr_plan_without_parallel_replicasused the min-rows threshold as its planner-side rejection. It now usesparallel_replicas_allow_in_with_subquery = 0and keeps its original counter values.Stacked on #126792 (the fix for
max_partitions_to_readwith read-time skip indexes); this PR targets its branchqcc-pruningand should be merged after it, then retargeted tomaster. Today the estimate run during this build is what fills the query condition cache with skip-index results, so queries on tables withmax_partitions_to_readthat rely on a skip index to stay under the limit recover after their first cold-cache run. Without the estimate, they would fail withTOO_MANY_PARTITIONSon every run unless skip indexes are applied during index analysis for such tables, which #126792 does.Checked on the combined branches with the #126792 repro (31 partitions,
max_partitions_to_read = 10, bloom-filter skip index, threshold 50M): with automatic mode 1 and 2, table-level and query-levelmax_partitions_to_read, every query passes from the first cold-cache run on.Related: #126792
Workflow [PR]
Sync PR [sync-upstream/pr/126815]
Version info
26.11.1.494-master(included in26.11and later)26.10.2.74