Repository navigation
Fix exception when arrayJoin in WHERE is pushed below JOIN - #97239
Merged
alexey-milovidov merged 3 commits intoFeb 18, 2026
Merged
Conversation
The `tryToExtractPartialPredicate` function (used for disjunction-based filter pushdown over JOINs) clones the full filter DAG, extracts a partial predicate, and calls `removeUnusedActions`. However, `removeUnusedActions` unconditionally keeps all `ARRAY_JOIN` nodes as roots (because they change the row count). This pulls in INPUT nodes from the other side of the JOIN that are not available in the target stream, causing a LOGICAL_ERROR: "In Filter cannot be more inputs in the DAG than columns in the input header" The fix adds a check after `removeUnusedActions`: if the resulting DAG contains any `ARRAY_JOIN` nodes, don't push it down. This is safe because `extractPartialPredicate` already correctly rejects predicates depending on `ARRAY_JOIN` (via `onlyDependsOnAvailableColumns`), so any surviving `ARRAY_JOIN` is an artifact of `removeUnusedActions`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e4cb181acf13e2961a7d6a4d5aa215947a6c8ccf&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_tsan%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
|
Workflow [PR], commit [37991ff] Summary: ❌
|
Co-Authored-By: Claude Opus 4.6 <[email protected]>
yariks5s
approved these changes
Feb 17, 2026
alexey-milovidov
deleted the
fix-array-join-filter-push-down-cross-join
branch
February 18, 2026 07:31
This was referenced Feb 18, 2026
Closed
Closed
This was referenced Feb 18, 2026
This was referenced Feb 18, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Feb 18, 2026
Backport #97239 to 25.11: Fix exception when arrayJoin in WHERE is pushed below JOIN
alexey-milovidov
added a commit
that referenced
this pull request
Mar 17, 2026
Backport #97239 to 26.1: Fix exception when arrayJoin in WHERE is pushed below JOIN
alexey-milovidov
added a commit
that referenced
this pull request
Mar 17, 2026
Backport #97239 to 25.12: Fix exception when arrayJoin in WHERE is pushed below JOIN
1 task done
tiandiwonder
added a commit
to tiandiwonder/ClickHouse
that referenced
this pull request
May 13, 2026
…step When the WHERE filter is pushed below a `JoinStepLogical` whose ON clause contains `arrayJoin`, `fix_predicate_for_join_logical_step` merged an `ARRAY_JOIN` node from the per-side join expression DAG into the pushed-down filter. `removeUnusedActions` preserved that `ARRAY_JOIN` unconditionally because it changes the number of rows. The same `ARRAY_JOIN` is recomputed later in the per-side "Pre Join Actions" `ExpressionStep`, multiplying row count by the array length twice -- so on an array of size 300 the expected 60 000 result rows balloon to 18 000 000. Snapshot the `ARRAY_JOIN` nodes contributed by `pre_filter_dag` by pointer identity before the merge (`mergeInplace` splices second's nodes into first's `nodes` list, preserving addresses) and drop them after the merge via the new narrow API `ActionsDAG::removeNodes(unordered_set<const Node *>)`. Safety: - `splitActionsForJOINFilterPushDown` rejects `ARRAY_JOIN` from `allowed_nodes`, so `filter_dag` arriving at this helper is guaranteed not to contain any `ARRAY_JOIN` of its own; every `ARRAY_JOIN` we see after the merge must have come from `pre_filter_dag`. - `JoinStepLogical::buildPhysicalJoinImpl` independently clones the same JOIN-side expression DAG into the per-side "Pre Join Actions" `ExpressionStep`, so the dropped expression is recomputed above this filter and the result remains correct. Related fixes for the same root cause (`removeUnusedActions` row-changing carve-out interacting with merge/clone of `ARRAY_JOIN`-bearing DAGs): prevention path in PR ClickHouse#96989, bail-out path in PR ClickHouse#97239. This PR addresses the remaining cleanup path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Merged
1 task done
pull Bot
pushed a commit
to erickirt/ClickHouse
that referenced
this pull request
Aug 19, 2026
… `arrayJoin` JOIN key When `tryConvertJoinToIn` rewrote `INNER JOIN ON arrayJoin(L.col) = R.col` and the SELECT (or any post-JOIN expression) referenced the source array column `L.col` or `arrayJoin(L.col)` again, the cloned post-JOIN expression DAG referenced an INPUT (`__table1.tags`) that the rewritten plan no longer exposed. `left_pre_join_actions` only forwards the JOIN key expressions, so the downstream `cloneSubDAGWithHeader` left a dangling INPUT, which threw `Code: 10 ... Not found column __table1.tags in block ... (NOT_FOUND_COLUMN_IN_BLOCK)` at execution. Decline the conversion in `tryConvertJoinToIn` whenever an input of the `join_output_actions` sub-DAG is not present in the outputs that `left_pre_join_actions` forwards. The bail-out happens before any plan mutation. The query then runs through the regular JOIN path and produces the correct result. Same root-cause family as PR ClickHouse#96989, PR ClickHouse#97239 and PR ClickHouse#104785: a plan-transformation pass merges or clones an ARRAY_JOIN-bearing DAG into a context whose stream header does not provide the required INPUT. Each prior fix took a call-site bail-out or post-merge cleanup; this PR follows the bail-out pattern (matching PR ClickHouse#97239). A more invasive follow-up could forward the missing left-side columns through `left_pre_join_actions` so the optimization stays on; left for a separate PR once we have data on how often the bail-out fires. The setting `query_plan_convert_join_to_in` is off by default, so the bug is reachable only when explicitly enabled. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
LOGICAL_ERRORexception ("In Filter cannot be more inputs in the DAG than columns in the input header") that occurs when aWHEREclause containsarrayJoinreferencing columns from both sides of a JOINtryToExtractPartialPredicatefunction clones the full filter DAG and callsremoveUnusedActions, which unconditionally keepsARRAY_JOINnodes as roots (they change row count). This pulls inINPUTnodes from the other side of the JOIN that are not available in the target streamARRAY_JOINnodes afterremoveUnusedActions, skip the pushdown entirelyRelated PRs:
arrayJoinproducing duplicate rows with JOIN and WHERE (addedARRAY_JOINrejection inonlyDependsOnAvailableColumns, but didn't handle theremoveUnusedActionsartifact)FilterStepthat catches this)tryToExtractPartialPredicate)CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e4cb181acf13e2961a7d6a4d5aa215947a6c8ccf&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_tsan%29
Test plan
03832_array_join_filter_push_down_cross_joinwith 15 query variations covering: cross join, inner join, left join, three-way join, legacy join step, subqueries, and the original fuzzer-found queryclickhouse-localthat the fix resolves the exceptionEXPLAIN PLANthat filters are no longer incorrectly pushed below the JOINChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
LOGICAL_ERRORexception whenarrayJoininWHEREclause references columns from both sides of aJOIN.🤖 Generated with Claude Code
Version info
26.2.1.87626.1.5.30,25.12.9.35,25.11.10.4