Repository navigation
Move join step row estimation before check for 1 child - #97114
Merged
Merged
Conversation
Contributor
|
Workflow [PR], commit [fff94d2] Summary: ❌
|
nickitat
approved these changes
Feb 16, 2026
1 task
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Mar 20, 2026
Revert #97114 Move join step row estimation before check for 1 child"
1 task
robot-clickhouse
added a commit
that referenced
this pull request
Apr 19, 2026
…before check for 1 child"
Copilot AI
added a commit
that referenced
this pull request
Apr 19, 2026
…icts - Resolved conflict in `optimizeJoin.cpp`: keep the `JoinStepLogical` check after `aggregating_step` (as per the revert of #97114), using `column_stats = {}` since `getResultColumnStats()` was removed in the backport - Resolved conflict in `03837_subquery_ndv_propagation_join_order.reference`: deleted (both .sql and .reference deleted in backport branch) Co-authored-by: fm4v <[email protected]>
robot-clickhouse
added a commit
that referenced
this pull request
Apr 19, 2026
…before check for 1 child"
1 task
fkastrati
added a commit
that referenced
this pull request
Sep 22, 2026
A join the optimizer has already settled enters its parent's graph as a single relation, and the row count it arrived at is the only estimate that relation has. `estimateReadRowsCount` returned early for any node with two children, so the parent saw nothing and `computeJoinCost` read the missing count as one row through `value_or(1)` - the largest input in the query looked like the cheapest thing to join. Read the estimate before that check. On TPC-DS q72 the boundary is real: the non-equi predicate `inv_quantity_on_hand < cs_quantity` splits `inventory` and `catalog_sales` into their own graph, which estimates itself at 945,072,914 rows against a true 944,916,882 - 0.02% off - and the parent then planned eight relations around it as if it returned one row. With column statistics the query goes from 11.6s to 0.8s, and under `dpsub` with the CD-C conflict detector from 72.7s to 1.0s: the detector widens the search space, so a wrong estimate buys more wrong plans. Measured over the full 99-query TPC-DS suite at scale factor 1 with column statistics, no other query changes. The relation name of such a sub-join is a chain that already carries its own inputs' estimates, so it is marked composite and `EXPLAIN` no longer appends a second estimate to it. This restores #97114, reverted in #99957 for a suspected performance regression. On tables without column statistics the estimate it propagates is itself unreliable, and there the change is a wash across TPC-DS - 18 queries faster, 11 slower. #101398 proposes gating propagation on a trust flag. Related: #97114 Related: #99957 Related: #101398
cv4g
added a commit
that referenced
this pull request
Oct 22, 2026
The option kept the row estimate and column statistics of an already optimized `JoinStepLogical` from reaching its parents unless a caller opted in. It was added because moving the sub-join case into `estimateDirectRelationStats` made it reachable for the first time; before, it sat behind the single-child check and never ran, so the option preserved the state after #99957 reverted #97114. #120110 then deliberately restored that propagation for every caller of `estimateReadRowsCount`. The merge with master kept the option and only opted in for join reordering, so this branch still diverged from master for all other consumers. For example, the distributed plan shuffled the right side of a join that was a small optimized sub-join instead of broadcasting it, because its row count was unknown. Drop the option so sub-join estimates propagate as on master. The `Unsupported` (and for semi/anti joins `RowSubset`) provenance stays, so consumers that gate on `ColumnStatsProvenance` still fail closed on a sub-join's column statistics.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously
estimateReadRowsCountfor join step always returnednulloptbecause ofif (node.children.size() != 1) return;before it. It didn't seem to affect join reordering because there the row count estimation was stored in DP table.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.2.1.831