Skip to content

Do not derive conjuncts in outer JOIN ON - #124233

Merged
fm4v merged 2 commits into
masterfrom
yarik/compare-chain-outer-join-on
Oct 11, 2026
Merged

fm4v merged 2 commits into
masterfrom
yarik/compare-chain-outer-join-on

Conversation

@yariks5s

@yariks5s yariks5s commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Closes: #124078
Related: #123796

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 NOT_IMPLEMENTED for an outer JOIN with join_algorithm = 'full_sorting_merge' when optimize_and_compare_chain derived a condition on the preserved side of the join from the ON clause.


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

Version info

  • Merged into: 26.10.1.2159-master (included in 26.10 and later)
  • Backported to: 26.9.17.4, 26.8.25.7

@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3a47fa4]

Summary: ✅


AI Review

Summary

This PR fixes #124078 by tracking the preserved side while LogicalExpressionOptimizerVisitor walks a JOIN ON expression and by suppressing compare-chain-derived conjuncts that would otherwise become unsupported single-side filters on an outer join's preserved input. I did not find a remaining contract violation in the current code: the guard is scoped to ON traversal, still permits derivations on non-preserved sides, and the new stateless coverage exercises left/right/full outer joins, nested joins, ARRAY JOIN, and the DateTime64 regression path. The PR metadata matches the change, and the current CI report for #124233 is all green.

Final Verdict
  • Status: ✅ Approve
  • No additional changes required.

LLVM Coverage Report

Measured on commit 3a47fa4.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 91.80% -0.30%
Branches 79.70% 79.70% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). labels Oct 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3a47fa439 with master e703172c0 (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.

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

@fm4v
fm4v added this pull request to the merge queue Oct 11, 2026
Merged via the queue into master with commit abdb9d2 Oct 11, 2026
293 of 295 checks passed
@fm4v
fm4v deleted the yarik/compare-chain-outer-join-on branch October 11, 2026 21:40
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 11, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 11, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 11, 2026
Backport #124233 to 26.9: Do not derive conjuncts in outer JOIN ON
clickhouse-gh Bot added a commit that referenced this pull request Oct 11, 2026
Backport #124233 to 26.8: Do not derive conjuncts in outer JOIN ON
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 12, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 17, 2026
…e keys

With `optimize_and_compare_chain`, the chain derives `expr op const` from
`expr = y AND y < 2` and appends it to the `AND`. In an outer join `ON` a
conjunct over the preserved side cannot be pushed down, so it stays in `ON`
and `full_sorting_merge` rejects the join with `NOT_IMPLEMENTED`.

ClickHouse#124233 guarded this with `getExpressionSource(expr).first`, which is
`nullptr` for an expression over several table expressions, so the guard
missed `a.number + b.number` over an inner join, the `firstNonDefault` key
of `FULL JOIN ... USING`, and an `ARRAY JOIN` alias mixed with a column.
Test every column's source against the preserved tables instead.

The `ALWAYS_FALSE` branch also appended a preserved-side contradiction
unguarded. A bound the guard skipped was still recorded, so a later bound
on the same expression conflicted with it (`l.number < 2` skipped, then
`l.number > 5` appended), and a type-impossible bound (`UInt8 > 300`) was
appended on its own; with `optimize_redundant_comparisons = 0` nothing
folds them and the join is rejected. Derive a preserved-side bound only
when the user already wrote a conjunct on that expression: the derivation
then still exposes a contradiction the next pass folds to `false`, and
that `ON` already holds a preserved-side conjunct of the user's.

Closes ClickHouse#125291

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compare chain makes outer JOIN ON unrunnable with full_sorting_merge

5 participants