Skip to content

Keep an ARRAY JOIN filter out of a Merge child query - #119307

Merged
alexey-milovidov merged 5 commits into
masterfrom
fix-merge-array-join-filter-115274
Oct 4, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
fix-merge-array-join-filter-115274

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix Column `__array_join_exp_1` not found in table for ARRAY JOIN with a filter on the array-joined column over a Merge table whose child is a Distributed table.

Documentation entry for user-facing changes

...

SELECT count() FROM mrg ARRAY JOIN data WHERE data IN ('aaa'), where mrg is a Merge table over a Distributed table, threw Column `__array_join_exp_1` not found in table .... The same query over the local table, over the Distributed table, or over a Merge table whose child is a plain MergeTree returned the rows.

replaceTableExpressionAndRemoveJoin builds the child query by replacing the outer query's join tree with the child table expression, and cloneAndReplace rewires every column sourced from the replaced node onto the replacement. With ARRAY JOIN as the join tree, that node is the ARRAY JOIN itself, so its result column ended up claiming to come from the child table: the filter over it then looked like a filter over the child's own columns and survived the cleanup that follows, and the child was asked to read __array_join_exp_1. Only a Distributed child noticed, because it is the one that re-analyzes the child query.

Drop such a filter before the join tree is replaced, while its columns still point at the ARRAY JOIN node, so that hasUnknownColumn recognizes them. StorageMerge reads its children with FetchColumns when the query has an ARRAY JOIN, so the array join and this filter are performed on the initiator either way. A filter over the table's own columns is unaffected — the replacement above has already rewired it onto the child table expression — and a conjunction of both kinds keeps the part that belongs to the child.

New test: 05197_merge_over_distributed_array_join_filter. Verified in both directions, and a differential run of the merge_table/array_join/storage_merge/distributed/view stateless tests shows no new failures.

Closes: #115274


Workflow [PR]
Sync PR [sync-upstream/pr/119307]

Version info

  • Merged into: 26.10.1.1519-master (included in 26.10 and later)

`SELECT count() FROM mrg ARRAY JOIN data WHERE data IN ('aaa')`, where `mrg` is a `Merge` table over a
`Distributed` table, threw ``Column `__array_join_exp_1` not found in table ...``. The same query over
the local table, over the `Distributed` table, or over a `Merge` table whose child is a plain
`MergeTree` returned the rows.

`replaceTableExpressionAndRemoveJoin` builds the child query by replacing the outer query's join tree
with the child table expression, and `cloneAndReplace` rewires every column sourced from the replaced
node onto the replacement. With `ARRAY JOIN` as the join tree, that node is the `ARRAY JOIN` itself, so
its result column ended up claiming to come from the child table: the filter over it then looked like a
filter over the child's own columns and survived the cleanup that follows, and the child was asked to
read `__array_join_exp_1`. Only a `Distributed` child noticed, because it is the one that re-analyzes
the child query.

Drop such a filter before the join tree is replaced, while its columns still point at the `ARRAY JOIN`
node, so that `hasUnknownColumn` recognizes them. `StorageMerge` reads its children with
`FetchColumns` when the query has an `ARRAY JOIN`, so the array join and this filter are performed on
the initiator either way. A filter over the table's own columns is unaffected - the replacement above
has already rewired it onto the child table expression - and a conjunction of both kinds keeps the part
that belongs to the child.

Closes: #115274
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [eee90d1]

Summary: ✅


AI Review

Summary

This PR fixes the analyzer-path bug where StorageMerge rewrites a WHERE filter on an ARRAY JOIN result into its child query and makes a Merge over Distributed ask the child for the synthetic __array_join_exp_1 column. The change removes ARRAY JOIN-dependent WHERE / PREWHERE conjuncts before the join tree is replaced, which matches the intended execution model (ARRAY JOIN stays on the initiator), and the added stateless coverage exercises the previously failing Distributed case plus mixed child-column and ARRAY JOIN filters. I did not find any new actionable correctness, compatibility, or performance issues in the current diff.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit eee90d1.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 8/10 (80.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-storage-merge Merge table engine (logical union over tables) and related mechanics. labels Sep 10, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Both red checks are unrelated to this change.

Stateless tests (amd_debug, parallel) and (arm_binary, parallery): 05141_time_series_select_join_settings fails with join_algorithm = 'grace_hash' is external from the first block and needs a spill threshold, but neither max_bytes_before_external_join nor max_bytes_ratio_before_external_join resolved to a non-zero value — the test sets both of those to 0 deliberately. That check came from the spilling-hash-join unification, which is already reverted on master (`12981f21057 Revert "Merge pull request #117356 from ClickHouse/yarik/unify-spilling-hash-join""), so it only affected the merge commit this run was built from.

AST fuzzer (amd_debug, targeted, old_compatibility): Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-4e52) is the signature tracked in the issue below; this change only drops a filter conjunct over an ARRAY JOIN column from a Merge child query and does not build or consume sets.

Related: #118722

@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing eee90d11e with master 2493c465d (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 21 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failures and provide a fix in a separate PR. If the fix is already in progress, link it here.

Neither one is related to this PR, which only changes StorageMerge. I merged master into the branch to start a fresh CI run.

@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Both failures are from the 2026-09-24 run (head 7c75fcd7), and both already have fixes, so there is no new PR from me.

The fresh run on 2eee930b has not reached either job yet.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119307&sha=2eee930ba6e9b831a47021daccc00e45007287dd&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The job hit its 9000 s timeout at test 14250 of 15130 with no failed tests; the same error status of this job shows up on other PRs every day during 2026-09-28 to 2026-10-04 (CIDB checks), so it is not related to this change. I merged master into the branch to retrigger CI.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

The fix is in progress and it is mine: #116209. It splits this job and its ParallelReplicas twin, the only two coverage stateless parallel jobs that still run the whole suite in one job, into 2 batches each. It is mergeable and waiting for review (requested from you on 2026-10-01). Its own CI skips the coverage jobs because it only changes CI config, so I verified the 4 new jobs by enumerating JobConfigs and the regenerated workflows.

The run on 2eee930b is that capacity limit, not a hang: after 22 minutes of setup, tests ran at a steady ~1000 per 8 to 11 minutes until the cut at 17:38 UTC, only one test took more than 300 s, and the tests right before the cut finished in seconds. The suite in this job grew from 13154 tests (your #114417 report, 2026-08-24) to 15130. At-cap kills of the pair: 31 in August, 77 in September, 26 on 2026-10-01 to 10-04. Over 2026-09-28 to 10-04 that is 15 of 1980 AsyncInsert runs and 16 of 1980 ParallelReplicas runs (5 of them on master), and the p99 of finishing AsyncInsert runs is 8317 s.

If the PR coverage opt-in (#122853, reverted in #123789) comes back, master still runs this job on every commit, so the split is still needed there; the batched names keep matching its "llvm_coverage" in job_name skip.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
Merged via the queue into master with commit a96b460 Oct 4, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-merge-array-join-filter-115274 branch October 4, 2026 18:51
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-storage-merge Merge table engine (logical union over tables) and related mechanics. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ARRAY JOIN + WHERE on the joined column over a Merge table wrapping a Distributed table throws NOT_FOUND_COLUMN_IN_BLOCK for __array_join_exp_1

3 participants