Skip to content

Reduce peak memory of test 03216_arrayWithConstant_limits - #111705

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-03216-arraywithconstant-memory
Jul 25, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-03216-arraywithconstant-memory

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

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

Reduce the peak memory usage and runtime of the test 03216_arrayWithConstant_limits to stop it flaking with MEMORY_LIMIT_EXCEEDED on loaded parallel runners.

Documentation entry for user-facing changes

The final query of the test built a single ~1.6 GiB block (100 rows, each holding a 1-million-element Array(Array(Int)) produced by arrayWithConstant). On a loaded parallel runner, when the server's RSS is close to the total memory limit, the allocation fails with MEMORY_LIMIT_EXCEEDED (the OvercommitTracker selects the query to stop).

Setting max_block_size on the final SELECT (the first attempt in this PR) does not help: the Memory engine returns its stored blocks unchanged, and CREATE TABLE ... AS SELECT ... FROM numbers(1, 100) stores a single 100-row block, so the flaky check on this PR still failed with the same single 1.49 GiB chunk allocation. Instead, the table is now populated with an explicit INSERT ... SELECT under max_block_size = 2, min_insert_block_size_rows = 2, min_insert_block_size_bytes = 1, so it stores small two-row blocks, and the final SELECT reads with max_threads = 1 to bound the number of blocks in flight.

The second attempt (100 rows in two-row blocks) then failed the flaky check with Test runs too long (> 180s) under TSan: generating 100 rows with 1-million-element arrays takes ~2.7 s in a release build, an order of magnitude more with sanitizers, and the flaky check runs the test in a loop. The table is therefore reduced to 10 rows, keeping the 1 million elements per array and the two-row stored blocks, so the same code path is exercised in ~0.13 s (release) with a peak allocation two orders of magnitude smaller than the original (verified with clickhouse-local: the old query fails under a 500 MB memory cap with the same 1.49 GiB chunk as in CI, the new one passes under a 300 MB cap).

This is a broad master-side flake: on 2026-07-23 alone it failed on five unrelated pull requests (#93111, #111502, #111570, #111241, #110833), and 24 failures were recorded on 2026-07-15.

Failure example: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111103&sha=5f9a7dc8a262eab4e2268940baf6eb4afd6b3cd8&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Related: #111103

Version info

  • Merged into: 26.8.1.127 (included in 26.8 and later)

The final query built a single ~1.6 GiB block (100 rows, each with a
1-million-element `Array(Array(Int))` from `arrayWithConstant`), which
fails with `MEMORY_LIMIT_EXCEEDED` on a loaded parallel test runner when
the server is close to its total memory limit (the OvercommitTracker
selects the query to stop). Cap `max_block_size` so the rows are
processed in small blocks: the same code path is exercised with a peak
allocation about a hundred times smaller.

Failure example: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111103&sha=5f9a7dc8a262eab4e2268940baf6eb4afd6b3cd8&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 (PR #111103)
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bc44783]

Summary: ✅


AI Review

Summary

This PR rewrites 03216_arrayWithConstant_limits so the Memory table stores small two-row blocks during INSERT and the final SELECT reads them with max_threads = 1, which removes the flaky large-allocation / timeout behavior without changing the arrayWithConstant success path the test covers. I did not find a remaining correctness, coverage, or metadata issue in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 23, 2026
The previous fix did not work: the flaky check on this PR still failed
with MEMORY_LIMIT_EXCEEDED (a single 1.49 GiB chunk allocation), because
the Memory engine returns stored blocks as-is and max_block_size cannot
split a block that was already formed. CREATE TABLE ... AS SELECT ...
FROM numbers(1, 100) stores a single 100-row block, so the query still
built the whole ~1.6 GiB column at once.

Store 2-row blocks at insert time (min_insert_block_size_rows = 2) and
read with max_threads = 1 to bound the number of blocks in flight.
Verified with clickhouse-local: the old query fails under a 500 MB
memory cap with the same 1.49 GiB chunk as in CI, the new one passes
under a 300 MB cap.

Co-Authored-By: Claude Fable 5 <[email protected]>
…time limit

The flaky check on this PR failed with "Test runs too long (> 180s)" under
TSan: the final query generated 100 rows x 1 million-element arrays
(~2.7 s in a release build, an order of magnitude slower with sanitizers,
and the flaky check runs the test in a loop). Reduce the table to 10 rows,
keeping the 1 million elements per array and the small stored blocks, so
the same code path is exercised in ~0.13 s (release) and the test still
passes under a 300 MB memory cap.

Failure report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111705&sha=bfa62a7207e507c44fa18063934a9f1257f295c9&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 25, 2026
Merged via the queue into master with commit fa854c7 Jul 25, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-03216-arraywithconstant-memory branch July 25, 2026 17:26
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 25, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ithconstant-memory

Reduce peak memory of test 03216_arrayWithConstant_limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants