Repository navigation
Fix arrayJoin producing duplicate rows with JOIN and WHERE - #96989
Merged
alexey-milovidov merged 1 commit intoFeb 15, 2026
Merged
Conversation
The `onlyDependsOnAvailableColumns` function in the partial predicate push-down for JOINs did not check for `ARRAY_JOIN` nodes. This caused predicates containing `arrayJoin` to be incorrectly pushed down below a JOIN as a partial (speculative) filter, while the original filter above the JOIN was kept. The `arrayJoin` therefore executed twice -- once in the pushed-down filter and once in the original filter -- producing duplicate rows. The fix rejects any subgraph containing `ARRAY_JOIN` from being considered for partial predicate push-down. The bug was introduced in #84735 and exposed when the optimization was enabled by default in #89313. Closes #96398 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
alexey-milovidov
deleted the
fix-arrayjoin-duplicate-rows-with-join-where
branch
February 15, 2026 15:04
clickhouse-gh Bot
added a commit
that referenced
this pull request
Feb 15, 2026
Backport #96989 to 26.1: Fix arrayJoin producing duplicate rows with JOIN and WHERE
3 tasks done
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
arrayJoin()function in SELECT with INNER JOIN and WHERE clause produced duplicate rowsuse_join_disjunctions_push_down) did not check forARRAY_JOINnodes, causingarrayJointo execute both before and after the JOINuse_join_disjunctions_push_downby default #89313Closes #96398
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
arrayJoinfunction producing duplicate rows when used with INNER JOIN and WHERE clause, caused by the partial predicate push-down optimization incorrectly pushing filters containingarrayJoinbelow a JOIN.Documentation entry for user-facing changes
No documentation changes needed.
🤖 Generated with Claude Code
Version info
26.2.1.74426.1.3.40