Fix ARRAY_JOIN row count mismatch in partial evaluation during outer-to-inner join optimization#98464
Merged
alexey-milovidov merged 2 commits intomasterfrom Mar 2, 2026
Conversation
…r-to-inner join optimization `arrayJoin` in a filter expression changes the number of rows (e.g., a constant array of 5 elements expands 1 row into 5 rows). When `filterResultForNotMatchedRows` evaluates the filter with `input_rows_count=1`, the `ARRAY_JOIN` case in `executeActionForPartialResult` would produce a column with more rows than expected. Downstream functions then received arguments with mismatched sizes (5 vs 1), triggering a LOGICAL_ERROR exception: "Expected the argument to have 1 rows, but it has 5". This is distinct from the null-column segfault fixed in #98147 - here the input column IS present but expanding it breaks the row count invariant. Skip `ARRAY_JOIN` expansion when `input_rows_count > 0` (partial evaluation for optimization). The result propagates as "unknown", which is safe. The header evaluation path (`input_rows_count=0`) is unaffected. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a1e0dff89e0b4aa8c21455db0bda2ca751f3387e&name_0=MasterCI&name_1=AST%20fuzzer%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/03836_array_join_in_filter_partial_evaluation.sql
Show resolved
Hide resolved
The bug is specifically in tryConvertAnyOuterJoinToInnerJoin which only runs for ANY strictness joins. A regular LEFT JOIN (ALL strictness) goes through a different code path that is not affected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Mar 13, 2026
robot-clickhouse-ci-1
added a commit
that referenced
this pull request
Mar 13, 2026
Cherry pick #98464 to 25.8: Fix ARRAY_JOIN row count mismatch in partial evaluation during outer-to-inner join optimization
robot-clickhouse
added a commit
that referenced
this pull request
Mar 13, 2026
… evaluation during outer-to-inner join optimization
robot-clickhouse-ci-1
added a commit
that referenced
this pull request
Mar 13, 2026
Cherry pick #98464 to 25.12: Fix ARRAY_JOIN row count mismatch in partial evaluation during outer-to-inner join optimization
robot-clickhouse
added a commit
that referenced
this pull request
Mar 13, 2026
…l evaluation during outer-to-inner join optimization
robot-clickhouse-ci-1
added a commit
that referenced
this pull request
Mar 13, 2026
Cherry pick #98464 to 26.1: Fix ARRAY_JOIN row count mismatch in partial evaluation during outer-to-inner join optimization
robot-clickhouse
added a commit
that referenced
this pull request
Mar 13, 2026
… evaluation during outer-to-inner join optimization
This was referenced Mar 13, 2026
robot-clickhouse-ci-1
added a commit
that referenced
this pull request
Mar 13, 2026
Cherry pick #98464 to 26.2: Fix ARRAY_JOIN row count mismatch in partial evaluation during outer-to-inner join optimization
robot-clickhouse
added a commit
that referenced
this pull request
Mar 13, 2026
… evaluation during outer-to-inner join optimization
robot-ch-test-poll
added a commit
that referenced
this pull request
Mar 13, 2026
Cherry pick #98464 to 25.3: Fix ARRAY_JOIN row count mismatch in partial evaluation during outer-to-inner join optimization
robot-clickhouse
added a commit
that referenced
this pull request
Mar 13, 2026
… evaluation during outer-to-inner join optimization
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
arrayJoinin a WHERE clause causes row count mismatch during partial evaluation in theconvertOuterJoinToInnerJoinoptimizationarrayJoinexpands a single-row constant array into multiple rows, breaking the invariant that all columns haveinput_rows_countrowsARRAY_JOINexpansion during partial evaluation (input_rows_count > 0), propagating "unknown" instead — the header evaluation path (input_rows_count=0) is unaffectedCI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a1e0dff89e0b4aa8c21455db0bda2ca751f3387e&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_ubsan%29
Test plan
03836_array_join_in_filter_partial_evaluationreproducing the exceptionChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix LOGICAL_ERROR exception when
arrayJoinis used in a filter expression with OUTER JOIN andjoin_use_nullsenabled.🤖 Generated with Claude Code