Repository navigation
Join on the implied equalities also at join steps that already have a condition - #122445
Conversation
… condition The join cost model counts every column equivalence class that spans a join step (`computeSelectivity`), but `cleanupJoinPredicates` added the transitive equality only to a step without a condition of its own. A step with an unrelated condition was costed with the class and executed without it. TPC-H Q02 hits this since ClickHouse#112630: the `WHERE` equality on the minimal supply cost is merged into the join, so with `dpsize` (and `dphyp,greedy`, `dpsub,greedy`) the decorrelated subquery is joined to `partsupp` on the supply cost alone, and every subquery row matches about |partsupp| / NDV(ps_supplycost) rows until the part key is applied three joins later. 26.8 joined this step on the part key. Phase 2 now runs at every inner step and adds one equality per class that spans both sides and is not connected by the step's own conditions yet. With conditions present it skips classes whose members differ in type beyond Nullable/LowCardinality (`String = FixedString` is not transitive) and steps with a prepared-storage side (`Join` engine, key-value storage), which is looked up by its declared key only (an extra key fails with `Code: 264`). The join order is unchanged, and Phase 1 still removes the later duplicate. In 03836 only Q02 changes: `partsupp` and the subquery are now shuffled by `ps_partkey` instead of broadcasting the subquery. Closes ClickHouse#122396 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Before publication, an independent model reviewed this PR (engine: codex; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck). My own review found 1 more item worth showing.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20260926-150300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260926-085800 |
|
Workflow [PR], commit [c591327] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict✅ No actionable findings. LLVM Coverage ReportMeasured on commit c591327.
Changed lines: Changed C/C++ lines covered: 50/50 (100.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only join reordering: after reordering, it adds predicates implied by chains of equal columns at inner joins, limited to columns of the same type and skipping Join-engine lookups. All flagged queries are ClickBench queries on the single hits table with no joins, so the changed code never runs for them. The three regressions (Q18 +16.5%, Q30 +23.1%, Q31 +21.8%) are downgraded to not_sure, and the five rows inside master's normal range were checked and match the diff. TPC-H, where the new predicates actually apply (Q02's plan changes in the updated test reference), shows no flagged changes. clickbenchFlagged queries (8 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
|
Closes: #122396
Related: #112630
Related: #120110
Related: #120784
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A join step that has a condition of its own now also joins on the equalities implied through other tables (for
a.x = b.x AND b.x = c.x, joiningawithcalso usesa.x = c.x), as the join order was costed with them. Withquery_plan_optimize_join_order_algorithm = 'dpsize'this makes TPC-H Q02 join its correlated subquery topartsuppon the part key instead of on the supply cost alone. Closes #122396.Description
With
dpsize(alsodphyp,greedy,dpsub,greedy), TPC-H Q02 joins the decorrelated subqueryR0(min(ps_supplycost)per part) topartsupponmin(ps_supplycost) = ps_supplycostonly. EachR0row then matches about|partsupp| / NDV(ps_supplycost)rows; the part key is applied three joins later.The cost model already counts every equivalence class that spans a join step, so that step is costed with the part key. But the transitive equalities were only added to a step without a condition of its own. Since #112630 (26.9) the supply cost equality from
WHEREis a join condition, so the part key was never added. 26.8 joins this step on the part key.Now every inner step gets one equality per class spanning its two sides that its conditions do not connect yet. A step with conditions skips classes whose members differ in type beyond
Nullable/LowCardinality(String = FixedStringis not transitive) and a prepared storage side (Joinengine, key-value), which is looked up by its own key. A step without conditions behaves as before. The join order does not change.R0has no row estimate, which is whydpsizeputs it first. #120110 (open) passes that estimate on; this PR does not change it.Validation: new test for all five algorithm settings (red on master). Of 1357 join and plan tests only
03836_tpch_join_order_plansQ02 changes: same join order, andpartsuppandR0are shuffled byps_partkeyinstead of broadcastingR0. On a synthetic SF10 subset with runtime filters off,dpsizeproduces 5.1M join rows instead of 309M (greedy: 1.6M), with identical results. TPC-H and TPC-DS SF1 results are unchanged.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122445]
Version info
26.10.1.796-master(included in26.10and later)