Skip to content

Do not lift an arrayJoin below an ARRAY JOIN - #117918

Merged
yariks5s merged 3 commits into
masterfrom
yarik/fix-lower-array-join-cartesian-order
Sep 4, 2026
Merged

yariks5s merged 3 commits into
masterfrom
yarik/fix-lower-array-join-cartesian-order

Conversation

@yariks5s

@yariks5s yariks5s commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Related: #112241

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 into CHANGELOG.md):

Fixes cases where ArrayJoin was producing incorrect order. Example: https://fiddle.clickhouse.com/57072da3-0fd4-4fb3-bf48-b26c2a9a1e09


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

Version info

  • Merged into: 26.9.1.665 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e3c9c27]

Summary: ❌

job_name test_name status info comment
Stress test (amd_asan_ubsan) FAIL
Logical error: Cannot add ZooKeeper operation because query is executed. It's a bug. (STID: 4181-5776) FAIL cidb, issue
Stress test (arm_tsan) FAIL
Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-41a5) FAIL cidb, issue

AI Review

Summary

This PR fixes one real result-preservation bug in query_plan_lift_up_array_join: it keeps nested arrayJoin expansions from being reordered when an arrayJoin expression sits above an ARRAY JOIN clause. The net change is directionally correct, but it still leaves the same optimization free to move evaluation-count-sensitive expressions across the ArrayJoinStep, so I do not think it is safe to merge as-is.

Findings

❌ Blockers

  • [src/Interpreters/ActionsDAG.cpp:2990] The new dependency rule only treats ActionType::ARRAY_JOIN as non-movable. That still lets nodes such as rowNumberInAllBlocks() or rand() move into the pre-ARRAY JOIN half, where they are evaluated once per source row and then replicated instead of being evaluated per expanded row. This violates the optimization's result-preservation contract for queries with non-deterministic or stateful expressions above ARRAY JOIN.
    Suggested fix: keep evaluation-count-sensitive nodes on the post-ARRAY JOIN side as well, or reject the lift when the movable half contains them, and add a focused stateless regression for that case.
Final Verdict

❌ Changes required

LLVM Coverage Report

Measured on commit e3c9c27.

Metric Baseline Current Δ
Lines 88.70% 88.70% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 81.00% 81.00% +0.00%

Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 3, 2026
@yariks5s
yariks5s marked this pull request as draft September 3, 2026 17:50
Comment thread src/Interpreters/ActionsDAG.cpp Resolved
@yariks5s
yariks5s marked this pull request as ready for review September 3, 2026 20:45
@Michicosun Michicosun self-assigned this Sep 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e3c9c278e with master 2400b5ade (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of dfde23932; 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

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

Job report

@yariks5s
yariks5s enabled auto-merge September 3, 2026 21:43
@yariks5s
yariks5s added this pull request to the merge queue Sep 4, 2026
Merged via the queue into master with commit 9f66d32 Sep 4, 2026
171 of 174 checks passed
@yariks5s
yariks5s deleted the yarik/fix-lower-array-join-cartesian-order branch September 4, 2026 05:13
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants