Skip to content

Stabilize 03381_lazy_materialization_limit_offset under MSan + WasmEdge - #104162

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-03381-lazy-materialization-granularity
May 18, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-03381-lazy-materialization-granularity

Conversation

@groeneai

@groeneai groeneai commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Test 03381_lazy_materialization_limit_offset has been timing out (300s client timeout, return code 159) on Stateless tests (amd_msan, WasmEdge, parallel, 1/2) runs across 3 unrelated builds in the last 30 days:

When PR sha randomized index_granularity
2026-04-10 master 76e37f19 28
2026-04-12 #100947 72cdeb9c 18
2026-05-05 #100375 831dab35 27

In all three runs the test runner's --diagnose-random-settings minimization pinpointed the MergeTree settings — and in all three runs the randomized index_granularity is in {18, 27, 28}. With 200K rows that produces ~7400 granules. Each granule contributes per-mark overhead in ALTER TABLE test MODIFY COLUMN json JSON SETTINGS mutations_sync=1, which compounds with MSan + WasmEdge slowdown plus parallel CI contention.

The test was originally derived from 03246_alter_from_string_to_json.gen.sql, which already pins index_granularity=(100, 60000); index_granularity_bytes=(10000, None). The derived test silently dropped both lower bounds, leaving the runner free to pick index_granularity from [1, 65536] and index_granularity_bytes from [1024, 30 MiB].

What

Mirror the bounds used by the source test: clamp index_granularity to [100, 60000] and index_granularity_bytes to [10000, None]. No SQL changes — only the Random settings limits comment.

Local validation (debug build, 200K rows)

index_granularity index_granularity_bytes granules ALTER MODIFY time
8192 (default) 10485760 24 0.21s
27 (failing) 16315845 7408 1.62s
8192 1024 (pathological bytes) 7408 1.62s
100 (new floor) 10000 (new floor) 2001 0.59s

The 7.6× slowdown at granularity 27 in a fast debug build maps to the 300s timeout under MSan (10–20× slowdown) + WasmEdge + parallel CI load.

The runner-side clamp simulation (using apply_random_settings_limits from tests/clickhouse-test) confirms all three failing combinations from CIDB are clamped up to safe values.

CI report links

Sent as a separate PR per @alexey-milovidov's request on #100375 (comment).

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):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.771

…ex_granularity

Random settings limit only had an upper bound on `index_granularity` and no
limits on `index_granularity_bytes`. With no lower bound, the test runner
randomized `index_granularity` down to 27 (and `index_granularity_bytes` can
be as low as 1024), producing 7400+ granules over the 200K-row table.

The 300s client timeout fired while `ALTER TABLE test MODIFY COLUMN json JSON
SETTINGS mutations_sync=1` rewrote all parts. Each granule contributes
per-mark overhead that compounds with MSan + WasmEdge slowdown plus parallel
CI contention.

CIDB shows the same failure across 3 unrelated runs in 30 days (PR ClickHouse#100947,
master 76e37f1, PR ClickHouse#100375), all in
`Stateless tests (amd_msan, WasmEdge, parallel, 1/2)`, all with
`index_granularity` in {27, 18, 28}.

Locally measured (debug build, 200K rows, JSON `ALTER MODIFY`):
- default `index_granularity=8192`           24 granules, 0.21s
- failing  `index_granularity=27`           7408 granules, 1.62s
- pathological `index_granularity_bytes=1024` 7408 granules, 1.62s
- proposed floor `index_granularity=100, bytes=10000` 2001 granules, 0.59s

Mirrors the limits already used by the source test
`03246_alter_from_string_to_json.gen.sql` from which 03381 was derived.

Per @alexey-milovidov's request on
ClickHouse#100375 (comment)...
@groeneai

groeneai commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

Session: cron:clickhouse-ci-task-worker:20260505-234500

(a) Deterministic repro? Yes — local debug build, 200K rows, index_granularity=27: ALTER TABLE ... MODIFY COLUMN json JSON SETTINGS mutations_sync=1 produces 7408 granules and runs in 1.62s vs 0.21s with default granularity (7.6× slower). Under MSan (10–20× slowdown) + WasmEdge + parallel CI load this exceeds 300s.

(b) Root cause explained? Yes — the test was derived from 03246_alter_from_string_to_json.gen.sql but silently dropped its index_granularity lower bound (100) and the index_granularity_bytes clamp entirely. With unbounded lower limits the runner can pick index_granularity from [1, 65536] and index_granularity_bytes from [1024, 30 MiB]. Either knob alone (rows-per-granule too small OR bytes-per-granule too small) inflates granule count to 7400+ over the 200K-row table, and per-granule mutation overhead then explodes under MSan + WasmEdge.

(c) Fix matches root cause? Yes — clamping index_granularity to [100, 60000] and index_granularity_bytes to [10000, None] exactly matches the source test's bounds. The clamp simulation (using tests/clickhouse-test's own parser/clamp logic) maps all three CIDB-observed bad cases ({27, 18, 28} for rows; 1024 for bytes) up to safe values.

(d) Test intent preserved? Yes — only the runner-side clamp comment changes. SQL, row count (200K), LIMIT 10 OFFSET 120000, JSON subcolumn list, and remaining randomization are untouched. The test still verifies lazy materialization with LIMIT/OFFSET across the JSON shared-data range boundary.

(e) Both directions demonstrated? Yes — without the fix, randomization hits index_granularity ∈ {18, 27, 28} in three CIDB runs and times out; locally, that scenario reproduces the 7408-granule mutation that's 7.6× slower in debug. With the fix, runner clamp pushes those values to ≥ 100 and the mutation stays at ~0.59s on 2001 granules.

(f) Fix is general, not narrow patch? Yes — this is a test-only Random settings limits change applying the proven configuration of the source test from which 03381 was derived. No defensive code added.

@groeneai

groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov — could you review this? Per your request on #100375 (issue 4383496162). Test-only Random settings limits clamp; no SQL/code changes.

@Algunenano Algunenano added the can be tested Allows running workflows for external contributors label May 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d8374c5]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
01710_projection_additional_filters FAIL cidb

AI Review

Summary

This PR updates tests/queries/0_stateless/03381_lazy_materialization_limit_offset.sql to clamp randomized MergeTree settings via Random settings limits by adding lower bounds for index_granularity and index_granularity_bytes. The change is consistent with the source test it was derived from, directly addresses the timeout mechanism described in the PR, and does not alter SQL test semantics beyond runner-side randomization constraints. I did not find correctness, safety, or maintainability issues in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 6, 2026
@alexey-milovidov alexey-milovidov self-assigned this May 6, 2026
@alexey-milovidov
alexey-milovidov merged commit c4be119 into ClickHouse:master May 18, 2026
164 of 167 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 May 18, 2026
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