Skip to content

Fix exponential planning in transitive outer-to-inner JOIN conversion - #123509

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
m-selmi:fix-exponential-null-propagating-inputs
Oct 3, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
m-selmi:fix-exponential-null-propagating-inputs

Conversation

@m-selmi

@m-selmi m-selmi commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #123432

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix exponential planning time in the transitive outer-to-inner JOIN conversion when the expression DAG has shared nodes, such as a column used twice (x + x) across nested subqueries. The analysis now visits each node once instead of every path.


Workflow [PR]
Sync PR [sync-upstream/pr/123509]

Version info

  • Merged into: 26.10.1.1365-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cf9de78]

Summary: ✅


AI Review

Summary

This PR memoizes the null-propagation and null-rejection walks in convertOuterJoinToInnerJoinTransitively and adds a reproducer for the exponential planner blow-up from #123432. The implementation looks aligned with the reported root cause, but I cannot approve the regression evidence yet because the new shell test relies on default optimizer settings and can silently stop exercising the fixed transitive-rewrite path in randomized or compatibility-shaped runs.

Tests
  • ⚠️ tests/queries/0_stateless/05317_exponential_null_propagation.sh:29 only pins join_use_nulls and enable_join_runtime_filters. Nearby join-conversion tests explicitly set query_plan_convert_outer_join_to_inner_join = 1 because the runner randomizes it off in about 5% of runs, and this reproducer is also gated on query_plan_convert_outer_join_to_inner_join_transitively = 1 (and in practice on the merged-DAG shape from query_plan_merge_expressions = 1). As written, the query can still return 1 without running the code this PR fixes, so the regression proof is weaker than the bug-fix contract.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: pin the optimizer settings that make the reproducer reach convertOuterJoinToInnerJoinTransitively so the test cannot go green after the rewrite is disabled by randomized settings, compatibility, or future default changes.

LLVM Coverage Report

Measured on commit cf9de78.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.40% 79.50% +0.10%

Changed lines: Changed C/C++ lines covered: 46/46 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 2, 2026
@m-selmi m-selmi added the can be tested Allows running workflows for external contributors label Oct 2, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Oct 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing cf9de78ca with master d046101ce (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

3 object files changed (+16.14 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/convertOuterJoinToInnerJoinTransitively.… 111.89 KiB 128.04 KiB +16.15 KiB (+14.44%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

@m-selmi m-selmi assigned m-selmi and alexey-milovidov and unassigned m-selmi Oct 2, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just memoisation, nothing complex.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit bdfd200 Oct 3, 2026
149 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exponential planning: collectNullPropagatingInputs revisits shared DAG nodes

3 participants