Skip to content

Fix logical error with CROSS_JOIN column source in CollectSourceColumnsVisitor#98459

Merged
alexey-milovidov merged 4 commits intomasterfrom
fix-cross-join-collect-source-columns
Mar 3, 2026
Merged

Fix logical error with CROSS_JOIN column source in CollectSourceColumnsVisitor#98459
alexey-milovidov merged 4 commits intomasterfrom
fix-cross-join-collect-source-columns

Conversation

@alexey-milovidov
Copy link
Copy Markdown
Member

Summary

  • Fix a logical error exception when CROSS JOIN is combined with INNER JOIN USING: the CollectSourceColumnsVisitor handled JOIN column sources but did not handle CROSS_JOIN, causing: "Expected table, table function, array join, query or union column source. Actual CROSS JOIN ...".
  • Add early return for CROSS_JOIN column sources in CollectSourceColumnsVisitor::enterImpl, matching the existing handling of JOIN.
  • Extend the guard in QueryAnalyzer::resolveJoin that prevents assigning a JOIN node as column source for constant USING expressions to also cover CROSS_JOIN.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1aefdf9c553447757c0daa4a6d48fa875173b7ee&name_0=MasterCI&name_1=BuzzHouse%20%28amd_ubsan%29

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 logical error exception when CROSS JOIN is used together with INNER JOIN USING.

🤖 Generated with Claude Code

…lumnsVisitor`

When a `CROSS JOIN` is combined with `INNER JOIN USING`, the USING
column resolution can produce columns whose source references the
`CrossJoinNode`. The `CollectSourceColumnsVisitor` handled `JOIN` node
sources but did not handle `CROSS_JOIN`, causing a logical error
exception: "Expected table, table function, array join, query or union
column source. Actual CROSS JOIN ...".

Add early return for `CROSS_JOIN` column sources in
`CollectSourceColumnsVisitor::enterImpl`, matching the existing handling
of `JOIN`. Also extend the guard in `QueryAnalyzer::resolveJoin` that
prevents assigning a `JOIN` node as column source for constant USING
expressions to also cover `CROSS_JOIN`.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1aefdf9c553447757c0daa4a6d48fa875173b7ee&name_0=MasterCI&name_1=BuzzHouse%20%28amd_ubsan%29

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Mar 2, 2026

Workflow [PR], commit [0c839fc]

Summary:

@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 2, 2026
The bug requires `analyzer_compatibility_join_using_top_level_identifier`
to trigger the code path where a USING column gets resolved from the
SELECT projection and the `CrossJoinNode` is incorrectly assigned as
the column source.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Fgrtue Fgrtue self-assigned this Mar 2, 2026
alexey-milovidov and others added 2 commits March 2, 2026 16:33
The test queries that expect `UNKNOWN_IDENTIFIER` succeed under the old
analyzer because `analyzer_compatibility_join_using_top_level_identifier`
and `CollectSourceColumnsVisitor` are new-analyzer-only code paths.
Set `enable_analyzer = 1` so the test is not affected by old analyzer runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alexey-milovidov alexey-milovidov merged commit 6a20ad3 into master Mar 3, 2026
148 of 149 checks passed
@alexey-milovidov alexey-milovidov deleted the fix-cross-join-collect-source-columns branch March 3, 2026 17:40
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants