Skip to content

Reduce peak memory of the 03742_nested_loop_join_long direct-join load test - #111644

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-03742-distributed-plan-oom-residual
Jul 26, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-03742-distributed-plan-oom-residual

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

03742_nested_loop_join_long is a residual MEMORY_LIMIT_EXCEEDED (Code 241) source on Stateless tests (amd_asan_ubsan, distributed plan, parallel) (~40 failures / 30 days across ~34 PRs + master), reported by @ alexey-milovidov on #111492.

The failure is a server-wide OvercommitTracker rejection, not a per-query limit: the aggregate RSS of the heavy tests co-scheduled on one memory-capped sanitizer server (max_server_memory_usage_to_ram_ratio cut to keep the host safe, see #110574) overruns the cap, so the tracker stops a query mid-JoiningTransform. The stopped query only needs 0.6-5.5 GiB; the server is already at its cap (~44.8 GiB). This is aggregate pressure, not a leak: the same build's distributed plan, parallel, 2/2 split variant (half the tests per server) has 0 failures, while the unsplit variant has 40.

03742 is one of the heaviest contributors. Its INNER events JOIN attributes fans a small left table (events, number % 3 + 2 over numbers(100) = 34/33 rows per key) against a large right table (attributes, 800K/300K rows per key), producing a 37.1M-row result that the direct-join path materializes as a single chunk (peak ~1.2 GiB locally; the direct join does not split the output by max_block_size or max_joined_block_size_rows). #110574 already cut this shard's concurrency to its practical floor.

Fix: shrink only the left-table row count, numbers(100) -> numbers(12) (4 rows per key). This cuts the INNER fan-out to 4.4M rows and the measured peak to ~400 MiB (~3x lower), while keeping everything the load test checks: the direct join algorithm, multi-match fan-out, the full 1.4M-row attributes right side, the Nullable key with NULL rows, and all four join strictnesses (INNER/LEFT/SEMI/ANTI). The separate large events2 x attributes2 case (1M x 1M, hash-collision keys) is left unchanged. The .reference is regenerated (per-key counts scale down: INNER key 2 27.2M -> 3.2M, key 3 9.9M -> 1.2M). Tag long kept.

Verified locally (debug, master): OLD data fails and NEW data passes under a 700 MiB per-query budget; whole test run 3x deterministic; every query stable across 50 randomized-settings runs.

03742_nested_loop_join_long is a residual MEMORY_LIMIT_EXCEEDED (Code 241)
source on Stateless tests (amd_asan_ubsan, distributed plan, parallel).

The failure is a server-wide OvercommitTracker rejection, not a per-query
limit: the aggregate RSS of the heavy tests co-scheduled on one memory-capped
sanitizer server (ratio cut in ClickHouse#110574) overruns the cap, so the tracker stops
a query mid-JoiningTransform. This test is one of the heaviest contributors:
its INNER events JOIN attributes fans a small left table (events, 34/33 rows
per key) against a large right table (attributes, 800K/300K rows per key) into
a 37.1M-row result that the direct-join path materializes as a single ~1.2 GiB
chunk. ClickHouse#110574 already cut this shard's concurrency to its practical floor, and
the direct join does not split its output by max_block_size, so reducing this
test's own peak is the remaining lever.

Shrink only the left-table row count, numbers(100) -> numbers(12) (4 rows per
key). This cuts the INNER fan-out to 4.4M rows and the peak to ~400 MiB (~3x
lower), while keeping everything the load test checks: the direct join
algorithm, multi-match fan-out, the full 1.4M-row attributes right side, the
Nullable key with NULL rows, and all four join strictnesses. The large
events2 x attributes2 case is unchanged. Regenerate the reference; keep the
long tag.
@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; 0 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).

Reviewer coverage: read both changed files in full, traced direct-join planning and execution plus sibling tests, and independently verified the exact output and the focused peak-memory reduction. No material surface uncovered; no blockers, majors, or nits raised.

# Sev Finding Verdict Evidence / action
— — No findings — Reviewer confirmed the fix and reproduced the peak-memory reduction.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-author-slot-7:20260723-112200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Under a controlled per-query budget, the INNER events⋈attributes join deterministically hits Code 241 MEMORY_LIMIT_EXCEEDED with the OLD data: clickhouse-client --max_memory_usage=$((700*1024*1024)) -q "SET join_algorithm='direct',min_joined_block_size_rows=0,min_joined_block_size_bytes=0; SELECT ... FROM events JOIN attributes ..." (events=numbers(100)) → fails (would use 912 MiB, peak ~1.2 GiB); same command with events=numbers(12) passes.
b Root cause explained? The CI error is a SERVER-WIDE OvercommitTracker rejection at the sanitizer memory cap (~44.8 GiB), not a per-query limit — the victim query only wants 0.6–5.5 GiB. --distributed-plan's parallel sanitizer shard co-schedules ~7 heavy tests on one memory-capped server; their AGGREGATE RSS overruns the cap and the OvercommitTracker stops a query mid-JoiningTransform. 03742 is one of the heaviest contributors: its INNER join over events(100 rows, 34/33 per key) × attributes(800K/300K per key) fans out to 37.1M rows, which DirectJoinMergeTreeEntity::getByKeys materializes as ONE ~1.2 GiB chunk (the direct join does not paginate output). Proof it is aggregate pressure: the same build's distributed plan, parallel, 2/2 split variant = 0 fails / 5075 OK, vs the unsplit variant = 40 fails / 4568 OK.
c Fix matches root cause? Yes. The peak is driven by the fan-out MULTIPLICITY = (left rows per key) × (right rows per key). Reducing events from numbers(100) to numbers(12) (34/33 → 4 rows per key) cuts the INNER fan-out 37.1M → 4.4M and the measured peak ~1.2 GiB → ~400 MiB (~3×), directly lowering 03742's contribution to the shard's aggregate RSS. Concurrency tuning (the alternative) is exhausted per #110574's own analysis; there is no query setting that bounds the direct-join output block (verified: max_block_size 65505 vs 1 → identical peak).
d Test intent preserved? Yes. The test is a direct-join load test (vdimir). It STILL exercises: join_algorithm='direct' over MergeTree, multi-match fan-out (still 4.4M output rows), the full 1.4M-row attributes right side (800K/300K/200K/100K per key — untouched), the Nullable key + NULL rows, and all four strictness kinds (INNER/LEFT/SEMI/ANTI). The separate large events2⋈attributes2 case (1M×1M, hash-collision keys) is entirely UNTOUCHED. Only the left-side row COUNT shrinks. long tag kept.
e Both directions demonstrated? Yes. buildId A93D4E7ADFC5C728F578FD222FBE62ACBFE143F2. Under --max_memory_usage=700Mi: OLD (numbers 100) → FAIL MEMORY_LIMIT_EXCEEDED; NEW (numbers 12) → PASS (RC=0). Correctness: whole .sql run 3× in fresh DBs → byte-identical; new .reference regenerated and matches; all 7 queries 50× each under randomized query settings → 350/350 correct.
f Fix is general across code paths? N/A (CI test-data right-sizing, not a source code bug). No production code changed.
g Fix generalizes across inputs? N/A (test-data change, not a code bug). All join strictness/type variants the test already covers remain covered; the events2 sparse/collision case is unchanged.
h Backward compatible? N/A (test-only change; no settings, formats, or behavior altered).
i Invariants and contracts preserved? N/A for source contracts (no code change). Test invariant preserved: the reference still pins exact sipHash sums + counts per key, so any correctness regression in the direct-join path is still caught — only the magnitudes shrink (INNER key2 27.2M→3.2M, key3 9.9M→1.2M), matching the reduced input deterministically.

Session id: cron:clickhouse-author-slot-7:20260723-112200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nickitat — could you review this? Test-only change: it shrinks the left table of 03742_nested_loop_join_long from numbers(100) to numbers(12), cutting the direct-join INNER fan-out from 37.1M to 4.4M rows (peak ~1.2 GiB -> ~400 MiB) so this test stops being the OvercommitTracker victim on the distributed-plan sanitizer shard, while keeping the direct-join algorithm, all four strictnesses, and the large attributes/events2 cases intact. Follow-up to #110574; requested by @ alexey-milovidov on #111492.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [21b9523]

Summary: ✅


AI Review

Summary

This PR reduces the left-side cardinality in 03742_nested_loop_join_long from numbers(100) to numbers(12) and regenerates the expected output so the direct-join load test stops exhausting the sanitizer shard's shared memory budget. The current patch keeps the same direct-join code paths, join strictness coverage, large right-side datasets, and events2 stress case, and I found no unresolved correctness, coverage, or metadata issues in the current diff.

Final Verdict

Status: ✅ Approve

@alexey-milovidov alexey-milovidov self-assigned this Jul 26, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 26, 2026
Merged via the queue into ClickHouse:master with commit 110cd5b Jul 26, 2026
178 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 26, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ted-plan-oom-residual

Reduce peak memory of the 03742_nested_loop_join_long direct-join load test
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 pr-ci 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.

4 participants