Fix logical error with CROSS_JOIN column source in CollectSourceColumnsVisitor#98459
Merged
alexey-milovidov merged 4 commits intomasterfrom Mar 3, 2026
Merged
Conversation
…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>
Contributor
alexey-milovidov
commented
Mar 2, 2026
tests/queries/0_stateless/04009_cross_join_inner_join_using.sql
Outdated
Show resolved
Hide resolved
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>
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>
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.
Summary
CROSS JOINis combined withINNER JOIN USING: theCollectSourceColumnsVisitorhandledJOINcolumn sources but did not handleCROSS_JOIN, causing:"Expected table, table function, array join, query or union column source. Actual CROSS JOIN ...".CROSS_JOINcolumn sources inCollectSourceColumnsVisitor::enterImpl, matching the existing handling ofJOIN.QueryAnalyzer::resolveJointhat prevents assigning aJOINnode as column source for constant USING expressions to also coverCROSS_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):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error exception when
CROSS JOINis used together withINNER JOIN USING.🤖 Generated with Claude Code