Repository navigation
Fix logical error in HashJoin::getNonJoinedBlocks due to overlapping columns - #98286
Merged
Merged
Conversation
…g columns
In an edge case found by AST fuzzer, a left-table column identifier
(e.g., `__table1.key`) ends up in the right plan's header. When
`HashJoin` splits the right header into keys vs non-keys, this left-side
column lands in `sample_block_with_columns_to_add`. Then `AddedColumns`
deduplicates it (skips right columns matching left column names), but
`getNonJoinedBlocks` expects the arithmetic sum of left + right key +
columns_to_add to equal `result_sample_block` columns, causing:
Unexpected number of columns in result sample block
The fix adds an `ExpressionStep` projection in `buildJoinQueryPlan` that
removes non-key right columns whose names overlap with left column names,
before the join algorithm is created.
Closes #85622
Closes #86528
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
Member
Author
|
Good. |
robot-clickhouse
added a commit
that referenced
this pull request
Feb 28, 2026
…locks due to overlapping columns
robot-clickhouse
added a commit
that referenced
this pull request
Feb 28, 2026
…Blocks due to overlapping columns
robot-clickhouse
added a commit
that referenced
this pull request
Feb 28, 2026
…locks due to overlapping columns
robot-clickhouse
added a commit
that referenced
this pull request
Feb 28, 2026
…locks due to overlapping columns
alexey-milovidov
added a commit
that referenced
this pull request
Mar 1, 2026
…s-85622 Fix logical error in HashJoin::getNonJoinedBlocks due to overlapping columns
alexey-milovidov
added a commit
that referenced
this pull request
Mar 19, 2026
…n in `HashJoin::getNonJoinedBlocks` `ActionsDAG::getRequiredColumnsNames` can return duplicate column names when the DAG has multiple input nodes with the same name. When these duplicates are passed to `TableJoin::setUsedColumns`, the same column gets pushed to `result_columns_from_left_table` multiple times. This causes a column count mismatch in `HashJoin::getNonJoinedBlocks` where the assertion expects the arithmetic sum of left + right_keys + right_added columns to equal `result_sample_block` columns (which are deduplicated). This is a follow-up to #98286 which fixed the same error via a different code path (`PlannerJoinTree`), but did not cover the `JoinStepLogical` path. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99936&sha=494ca1e7a6070de924219397dd6a93afb0c714a0&name_0=PR&name_1=AST%20fuzzer%20%28amd_msan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 task
Contributor
|
Hi @alexey-milovidov — the changelog category for this PR might need a look. Current: Why: The PR fixes a logical error in HashJoin::getNonJoinedBlocks that occurs when there are overlapping column names between left and right tables. This is a user-visible bug fix, not a CI improvement. Could you verify this is correct? Ignore if the current category is intentional. |
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
HashJoin::getNonJoinedBlockscaused by left-table column identifiers appearing in the right plan's headerAddedColumnsdeduplicates overlapping columns butgetNonJoinedBlocksexpects the arithmetic sum, causingUnexpected number of columns in result sample blockExpressionStepprojection inbuildJoinQueryPlanto remove non-key right columns overlapping with left column names before the join algorithm is createdCloses #85622
Closes #86528
Test plan
03993_join_no_overlapping_columns_85622reproducing the issueChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error exception
Unexpected number of columns in result sample blockinHashJoin::getNonJoinedBlockswhen left-table column identifiers overlap with non-key right-side columns.🤖 Generated with Claude Code