Repository navigation
Estimate the join inputs of the automatic parallel replicas probe from the single-node analysis - #130516
Conversation
The probe plan of automatic parallel replicas is optimized without `query_plan_optimize_primary_key`, so its reads have no index conditions and no analysis of their own. Join optimization estimates every join input with `estimateReadRowsCount`, which analyzed such a read on the spot: a second index analysis of every read under a join, and an unpruned one, so the probe also sized its joins from whole-table row counts. Pass `find_single_node_read` to `estimateReadRowsCount` from join optimization (`optimizeJoinLegacy`, `optimizeJoinLogical`, and the IEJoin statistics in `buildPhysicalJoinImpl`). A read without an analysis is estimated from the analysis of its single-node read, which is the one the probe's reads take if that plan is chosen. Nothing is stored on the probe's read. In the new test, the probe of a two-table join used to add one round of index analysis per table and check every mark against the primary key again; it now adds none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [869709a] Summary: ✅
AI ReviewSummaryReviewed #130516 at Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1531 translation units recompiled, 1907 s compile time in total, 1531 of them have a recent master baseline. |
The previous commit took the estimate of a probe read from the read that `find_single_node_read` pairs it with. That pairing goes by the name the analyzer gave the table expression, and the two plans do not agree on these names: the replicas plan's local plan is built from the tree `buildQueryTreeForShard` returns, which renumbers `__tableN`. With a three-table join written big table last, or a table read twice, the pairing finds nothing and the estimate analyzed the probe's read in full, unpruned, as before. An estimate does not need to know which read is which. The probe now also gets `find_single_node_reads_of_table`, every read of the single-node plan of the same table, and `estimateReadRowsCount` takes the largest of their analyses: the analysis itself when the table is read once or several times alike (a CTE used twice), and an upper bound when its reads are filtered differently. `find_single_node_read` stays as it is for direct read from a text index, which needs the very read. `makeDistributed`, `RuntimeFilterExchangeWiring` and the Cascades statistics also call the estimate, but only under `make_distributed_plan`, which rejects automatic parallel replicas, so they never see a probe plan. `05508` covers the two shapes, and a CTE used twice; with the previous commit the first two still added rounds of index analysis. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This is the shape of the B28 residual queries (q39-like: a CTE over a four-table join, read twice with a different filter on each copy). The plan with parallel replicas numbers the table expressions of each copy from 1, so both copies of a table share one name there and have two different names in the single-node plan. Pairing by name then finds nothing, and with only the first fix the probe doubled the index analysis (8 rounds against 16 locally, as in the replays). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A read of the probe plan of automatic parallel replicas now takes the analysis of the single-node read that `find_single_node_read` pairs it with, if that read already has one, and is left without an estimate otherwise. It is never analyzed for the estimate: not the probe's own read, which would prune nothing, and not the single-node one. This replaces the previous commit's grouping of single-node reads by table, which took the largest of their analyses when a read could not be paired. A read that cannot be paired cannot take an analysis in `transplantAnalysisToAllReads` either, so that estimate only helped a probe the transplant rejects afterwards anyway. Under a throwing read limit the single-node join estimates use `selectRangesToReadForEstimation`, which keeps no result, so the probe finds none to take. It used to analyze its reads then (6 index analysis rounds against 4 without automatic parallel replicas in the new `05508` case); now it adds none. In every `05508` case the outcome of the optimization is the same as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n `05508` With a throwing `max_rows_to_read`, the single-node join estimates use `selectRangesToReadForEstimation`, which keeps no result, so the probe of automatic parallel replicas finds no analysis to estimate from. Without column statistics (`use_statistics = 0`) its join inputs then have no row estimate at all. The single-node plan swaps a join whose small table is written first, the probe does not, and the two plans cannot be matched: `AutoParallelReplicasPlansNotComparable` is 1 and no statistics are collected. The case fails on this branch. Before the previous commit it matched, but the probe analyzed its reads again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under a throwing read limit, a single-node join estimate analyzes its read with `selectRangesToReadForEstimation`, which must not become the read's analysis, so the probe plan of automatic parallel replicas found none to estimate from. Without column statistics its join inputs then had no row estimate, it did not swap the join the single-node plan swapped, and the plans could not be matched. Keep that result on the read as well, in a field of its own that only `getAnalyzedResultForEstimation` returns, and let the probe estimate from it when the paired single-node read has no analysis. The probe now estimates from the numbers the single-node plan chose by, without analyzing anything itself; the executed read still analyzes again as before. `05508_throwing_limit_swap` passes: the plans match, and the probe adds no index analysis. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alysis-again # Conflicts: # src/Processors/QueryPlan/ReadFromMergeTree.cpp
…lysis The row store for `String` keys (#125979), merged from master, estimates the right input of a hash join for the average bytes of its columns with `estimateReadRowsCount`, without `find_single_node_read`. In the probe plan of automatic parallel replicas that analyzed the read again, which `05508_throwing_limit_swap` caught after the merge: 6 index analysis rounds against 5 without automatic parallel replicas. Pass `find_single_node_read` there as well, like the other join estimates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The comment still described the first version, where a read without an analysis was estimated from the single-node read however it got one. Now the estimate only takes an analysis that read already has, or its last estimation-only one, and otherwise gives none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alysis-again Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alysis-again Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alysis-again Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
I built cd9539f (debug) and the same tree with the six src/ files reverted to the merge base, and ran both against a local 3-replica parallel_replicas cluster with the CI users.d/limits.yaml profile.
05508matches the reference on the PR head. Withsrc/reverted, every case reports0 0in the twosame_*columns: the probe checks the marks against the primary key once more (join: 4 rounds and 248 marks against 2 and 124;throwing_limit_swap: 8 and 374 against 5 and 249).- Dropping only the
getAnalyzedResultForEstimation()fallback changes just the last row (not_comparable0 -> 1), so the swap case covers that path. - Mode 1 after a mode-2 run, with the cost-model settings of
05507: the same queries are adopted as before the change (the join, the table read twice, the join under a throwing limit; the big-table-last and swap shapes are evaluated and not adopted on both builds), the results equal those withenable_parallel_replicas = 0, and the index analysis rounds now equal the single-node run's in every case (2 or 3 more before). getAnalyzedResultForEstimation()has a single reader, and the transplant still hands overgetOrCreateAnalyzedResult(). The callers that do not passfind_single_node_read(makeDistributed.cpp,RuntimeFilterExchangeWiring.cpp,Cascades/Statistics.cpp) run only undermake_distributed_plan, whichQueryPlanOptimizationSettingsrejects together with parallel replicas.
One nit: two comments in 05508 still describe the behaviour before a5723c3. Lines 16-17 ("there is no analysis for the probe to take") and 79-80 ("the probe finds none to take, and its reads are left without an estimate") no longer hold: under a throwing limit the probe now estimates from the single-node read's selectRangesToReadForEstimation result, as the second point shows.
…alysis-again Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alysis-again # Conflicts: # src/Processors/QueryPlan/Optimizations/RelationStatisticsEstimator.cpp # src/Processors/QueryPlan/Optimizations/RelationStatisticsEstimator.h # src/Processors/QueryPlan/ReadFromMergeTree.cpp
Since ClickHouse#130516, join optimization passes `find_single_node_read` to `estimateReadRowsCount`, so a read of the probe plan of automatic parallel replicas takes the analysis of its single-node read instead of being analyzed again. The key path walk of the JOIN runtime filter guard estimated its inputs without it, so when it ran in the probe plan, it analyzed the reads a second time, unpruned. `05508_autopr_probe_join_estimate_reuses_index_analysis` caught this in Fast test on this PR: index analysis rounds and marks checked differed with and without automatic parallel replicas for six of its queries. Pass the same option in the walk, so it estimates the same rows as join optimization does. Locally (debug), 05508 fails 5/5 without this change and passes 20/20 with it; 04201 passes 20/20. The preceding merge of master brings in ClickHouse#130516, whose option this needs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #130516 to 26.10: Estimate the join inputs of the automatic parallel replicas probe from the single-node analysis
…parallel replicas probe from the single-node analysis
Backport #130516 to 26.10: Estimate the join inputs of the automatic parallel replicas probe from the single-node analysis
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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Automatic parallel replicas no longer repeats the index analysis of a join's tables when it builds the plan with parallel replicas to decide whether to use them.
Related: #129339
Related: #125687
Automatic parallel replicas builds and optimizes a probe plan with
query_plan_optimize_primary_keyoff: if the probe plan is chosen, its reads take the index analysis of the single-node plan. But join optimization estimates every join input withestimateReadRowsCount, and for a read without an analysis that ran a full index analysis. Every read of the probe plan has none, so each probe of a query with a join analyzed the join's reads a second time. The analysis also pruned nothing, since the probe's reads have no index conditions, so the probe sized its joins from whole-table row counts.Now
estimateReadRowsCounttakesfind_single_node_readfrom join optimization (optimizeJoinLegacy,optimizeJoinLogical, and the IEJoin statistics inbuildPhysicalJoinImpl). A read of the probe plan is estimated from an analysis its single-node read already has, and is never analyzed for the estimate:selectRangesToReadForEstimation, which the single-node join estimate uses under a throwing read limit. It must not become the read's analysis, soReadFromMergeTreenow also keeps it in a separate field, returned only bygetAnalyzedResultForEstimation. The probe then estimates from the numbers the single-node plan chose its join order by, and makes the same choice.transplantAnalysisToAllReadseither, so such a probe is rejected anyway.The new test
05508compares index analysis rounds and marks checked against the primary key with and without automatic parallel replicas, for a join, tables written in an order the probe numbers differently, a table read twice, a CTE used twice, a CTE over a join used twice, and a throwing read limit. The probe used to add one round per read of a join and check every mark again; now it adds nothing. It also covers a join the single-node plan swaps under a throwing read limit without column statistics: with no estimate, the probe would not swap it and the plans would not match.Workflow [PR]
Sync PR [sync-upstream/pr/130516]
Version info
26.11.1.2892-master(included in26.11and later)26.10.9.10