Skip to content

Cut lazily replicated ARRAY JOIN passengers to their output block - #126160

Merged
yariks5s merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/array-join-lazy-passenger-window-cut
Oct 16, 2026
Merged

yariks5s merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/array-join-lazy-passenger-window-cut

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #126081
Related: #124727

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Lazily replicated ARRAY JOIN passenger columns hold only the rows of their output block again, so materialized views, max_result_bytes and squashing size ARRAY JOIN output correctly.

Description

Since #124727, every lazily replicated passenger column of an ARRAY JOIN output block wrapped the whole uncut input block, so each of the W output blocks of an input block reported, and copied, the whole block. A 1M-row insert through SELECT payload, x FROM src ARRAY JOIN arr AS x into MergeTree wrote 51 parts in ~6 s at 956 MiB peak instead of 9 parts, and a ~2 MB filtered result failed max_result_bytes = 10000000 with TOO_MANY_ROWS_OR_BYTES. #124727 is also in the 26.10 branch, which has no stable release yet.

ArrayJoinResultIterator::next and nextWithElementFilter now cut the passenger to the window before wrapping it, with window-local indexes, as before #124727. The rest of #124727 stays, including the referenced-rows bound that keeps filtered and sorted passengers lazy. The first_index parameter of convertOffsetsToIndexes has no caller left and is removed.

I did not fix the consumers instead: byteSize cannot count only the referenced rows without scanning the indexes and summing per-row sizes, and it runs on every port push and pull; a row-count share undercharges variable-width rows.

The price, measured on a Release build (median of 7): #124727's SELECT x, str ... FROM numbers(10000000) ARRAY JOIN arr AS x FORMAT Null goes from 0.200 s to 0.345 s, since the passenger is copied once per input block again; the other four lazy queries #124727 added are within noise. The issue's insert: 9 parts, ~0.95 s, 403 MiB (eager replication: 9 parts, 1.04 s, 505 MiB).

Validation: 05405_array_join_lazy_replication_chunk_bytes (MV part count, max_result_bytes with the filter fused into ARRAY JOIN and not) fails on master and passes 50/50 with randomized settings; reverting either hunk alone reddens it. New perf test array_join_lazy_replication_insert.xml.


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

Version info

  • Merged into: 26.11.1.82-master (included in 26.11 and later)
  • Backported to: 26.10.2.21

Since ClickHouse#124727 every lazily replicated ARRAY JOIN passenger wrapped the
whole uncut input-block column, with indexes into the current window.
All output blocks of one input block then shared that column, and every
ColumnReplicated consumer treats the nested column as the block's own
data: byteSize (Chunk::bytes, Squashing thresholds, max_result_bytes,
RESULT_BYTES) counted the whole input block per output block, and
Squashing::squash copied it per output block. A materialized view
flattening an array wrote 51 parts instead of 9 for a 1M-row insert,
and a small filtered result failed max_result_bytes.

Cut the passenger to the window before wrapping it, with window-local
indexes, in both ArrayJoinResultIterator::next and nextWithElementFilter,
as before ClickHouse#124727. Keep the rest of ClickHouse#124727, including
getReferencedRowsBound, which still keeps sparse filtered windows lazy.
The first_index parameter of convertOffsetsToIndexes has no non-zero
caller left, so it is removed.

Fixing the consumers instead was rejected: exact referenced-byte
accounting needs an O(rows) index scan plus per-row byteSizeAt inside
byteSize, which runs on every port push and pull, and a row-count share
of the nested bytes undercharges variable-width rows.

Price on a Release build (median of 7): the 10M-row lazy
`SELECT x, str ... ARRAY JOIN arr AS x FORMAT Null` query that ClickHouse#124727
added goes from 0.200 s to 0.345 s; its other four lazy queries are
within noise.

Closes ClickHouse#126081

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ 05405 would stay green if lazy passenger replication silently fell back to eager DISAGREE With eager passengers there is no nested column to oversize, so the sizing the test checks is exact (its own eager arm is that case). The defect it targets reddens it: master 50/50 FAIL, and reverting either hunk alone fails a different check. The lazy decision is pinned per query and is a type predicate (isLazyReplicationUseful), true for String; whether the lazy path is used is covered by the perf tests.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261015-234300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue's reproducer prints lazy 14 200000 on master every run (fix: lazy 1 200000); the filtered query with max_result_bytes = 10000000 raises TOO_MANY_ROWS_OR_BYTES every run, fused and unfused.
b Root cause explained? #124727 wrapped the uncut input-block column in ColumnReplicated for every ARRAY JOIN output block, so byteSize, Squashing and max_result_bytes saw, and squashing copied, the whole input block once per output block.
c Fix matches root cause? Yes. The passenger is cut to its window again at the producer, so every ColumnReplicated consumer is exact without change. Consumer-side accounting was rejected: exact needs an O(rows) scan in byteSize, a row share undercharges variable-width rows.
d Test intent preserved / new tests added? New 05405_array_join_lazy_replication_chunk_bytes (MV part count parity, max_result_bytes fused and unfused) and perf test array_join_lazy_replication_insert.xml.
e Both directions demonstrated? Master: 50/50 FAIL with randomized settings. Fix: 50/50 OK serial and 50/50 OK at -j 8. Reverting only the next hunk reddens the MV and unfused checks; reverting only the nextWithElementFilter hunk reddens the fused check.
f Fix is general across code paths? Both lazy producer branches are fixed. Eager branches already cut; the arrayJoin function form emits one block per input block.
g Fix generalizes across inputs (params/datatypes/wrappers)? 328-query matrix (String, Nullable, Array, Map, Tuple, UInt128, FixedString, LowCardinality, Const passengers; inner, LEFT, unaligned, chained ARRAY JOIN; element and row filters; lazy and fuse on/off): identical results on master and fix. The max_result_bytes check also passes for Nullable, Array, Tuple and Map passengers.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or result change.
i Invariants and contracts preserved? Window-local indexes stay below the nested size; getReferencedRowsBound still bounds the referenced rows; output block sizes are unchanged.

Session id: cron:clickhouse-impl-slot-5:20261015-224100

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [047d6d2]

Summary: ✅


AI Review

Summary

Restores window-local passenger data and indexes in both lazy ARRAY JOIN execution paths, fixing inflated byte accounting and repeated copies during squashing. No actionable findings in the current diff. The focused regression test passes in Fast test; the PR also documents before/after measurements, including the cost of restoring passenger copies.

Final Verdict

Status: ✅ Approve. No review changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @yariks5s @Avogar, could you review this? Since #124727 each lazily replicated ARRAY JOIN passenger wraps the whole uncut input block, so every output block reports and copies that block (MV inserts ~6x slower, max_result_bytes overcharged); this cuts the passenger to its window again with window-local indexes and keeps the rest of #124727.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 047d6d2

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (arm_release, master_head, 3/6, 5/6, 6/6) job timeout (7200 s), not from this PR: one of the shard's two Check CI Log cluster probes (setup_log_cluster.sh) blocked about 3645 s on the overloaded CI Logs cluster before any perf query ran, so the job was killed mid-run with no verdicts. Same on dozens of PRs and master between 01:40Z and 05:30Z #126217 (mine, open)
Mergeable Check, PR praktika rollups of the rows above #126217 (the owner of the rows above)

Session id: cron:our-pr-ci-monitor:20261016-070011

@yariks5s yariks5s self-assigned this Oct 16, 2026
@yariks5s
yariks5s added this pull request to the merge queue Oct 16, 2026
@nikitamikhaylov

Copy link
Copy Markdown
Member

@groeneai who is a "passenger"?

Merged via the queue into ClickHouse:master with commit 07f37c5 Oct 16, 2026
699 of 704 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

The columns that are not in the ARRAY JOIN list, i.e. the "other columns" whose values the docs say are duplicated for each array element. In the issue's SELECT payload, x FROM src ARRAY JOIN arr AS x, arr is the joined column and payload is one of them. In the code they are the two else branches that either replicate the column or wrap it into ColumnReplicated: ArrayJoinAction.cpp#L323-L330.

It is informal wording, not a ClickHouse term; I will write "non-joined columns" instead.

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 16, 2026
yariks5s added a commit that referenced this pull request Oct 19, 2026
Backport #126160 to 26.10: Cut lazily replicated `ARRAY JOIN` passengers to their output block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ARRAY JOIN chunks reference the whole input block: MV inserts 3x slower

6 participants