Skip to content

Speed up 02428_parameterized_view by batching client invocations - #103687

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-02428-parameterized-view-long-tag
Jul 29, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-02428-parameterized-view-long-tag

Conversation

@groeneai

@groeneai groeneai commented Apr 29, 2026 •

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Description

02428_parameterized_view was timing out in Stateless tests (amd_asan_ubsan, flaky check) and other heavy-sanitizer lanes: each run exceeded the 180s flaky-check gate. The test is structurally slow rather than buggy - it spawned ~99 separate $CLICKHOUSE_CLIENT processes, and each connection has fixed handshake/auth/settings-parse overhead that dominates the tiny queries themselves.

CIDB (30 days) showed 41 Test runs too long (> 180s) failures across 10 unrelated PRs, 0 on master (a PR-only flaky-timing profile). Related closed issues: #102207, #88863.

An earlier revision of this PR used # Tags: long to opt into the longer flaky-check budget. As the automated review correctly pointed out, that has two side effects beyond the timeout exemption: long reduces the flaky-check repeat count to int(--test-runs * --long-test-runs-ratio) (50 -> 5), and drops the test from Fast test (which passes --no-long). That is a real coverage reduction for parameterized views, not just a timeout exemption.

This revision instead removes the root cause of the slowness: the ~99 client invocations are batched into ~14 multi-statement $CLICKHOUSE_CLIENT calls, and the long tag is removed. Statements that expect an error (piped through grep) are kept as individual invocations, because an error aborts the remaining statements of a multi-statement batch. --param_p/--param_l are converted to inline SET param_*.

The test now runs well under 180s without long, so it keeps the full 50x flaky-check repeat count and remains part of Fast test.

Measured locally (this workspace, single-process):

build before (99 spawns) after (~14 spawns)
debug, clickhouse-test 8.90s 2.29s
ASan, raw run ~45s ~10s

Under CI's 50x-parallel asan_ubsan flaky check the before-time scaled to the 232s p50 reported in CIDB; the after-time stays comfortably under the 180s gate even with the same amplification.

Test output, references, assertions, and settings are unchanged. Verified byte-identical against both .reference (new analyzer, 2.29s) and .oldanalyzer.reference (old analyzer, 2.13s), and 60/60 passes under --test-runs 30 with randomization enabled.

Version info

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

`02428_parameterized_view` issues ~99 separate `clickhouse-client`
invocations. Under sanitizer load it takes ~109s on a quiet ASan box,
and CI's amd_asan_ubsan `flaky check` (which runs each test 50x in
parallel) drives this to a p50 of 232s and a p99 of 251s — well past
the 180s flaky-check budget. The 30-day CIDB shows 41 `Test runs too
long (> 180s)` failures across 10 PRs (none of them touching this test
or randomization config), making this a pure timing flake.

`tests/clickhouse-test` only enforces the 180s flaky-check timeout for
tests without the `long` tag (see `clickhouse-test:3067-3072`). Add the
tag — the test legitimately takes longer than 180s under sanitizer +
parallel load due to its structure, not because of any logic issue.

This matches the canonical pattern for similarly client-call-heavy
tests already passing flaky check at 200-400s (`01516_drop_table_stress_long`,
`01443_merge_truncate_long`, `01049_join_low_card_bug_long`, etc.).

CIDB diagnostic:
  https://play.clickhouse.com/?user=play&query=SELECT%20test_name%2C%20count%28%29%20FROM%20default.checks%20WHERE%20test_name%3D%2702428_parameterized_view%27%20AND%20test_status%20IN%20%28%27FAIL%27%2C%27ERROR%27%29%20AND%20test_context_raw%20LIKE%20%27%25runs%20too%20long%25%27%20AND%20check_start_time%20%3E%20now%28%29%20-%20INTERVAL%2030%20DAY

Co-Authored-By: Claude Sonnet 4.5 (1M context) <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per worker TASK.md / fix-ci-failure skill):

# Question Answer
a Deterministic repro? Yes — local --flaky-check --test-runs 5 -j 1 on ASan: 5/5 runs at 108-110s. Under CI's 50x-parallel asan_ubsan flaky-check load, CIDB shows p50=232s, p99=251s, exceeding the 180s gate ~10% of the time across 10 unrelated PRs in the last 30 days.
b Root cause explained? Yes — the test issues ~99 separate clickhouse-client invocations. Cumulative connection overhead × ASan instrumentation × 50-way parallel CPU contention drives total runtime past 180s. The 180s timeout in tests/clickhouse-test lines 3067-3072 fires only in flaky-check mode and only for tests without the long tag.
c Fix matches root cause? Yes — the test legitimately takes >180s on heavy sanitizer lanes due to its structure, not because of any regression or logic bug. The long tag is the runner's intended opt-in for that class of tests, same pattern as 01049_join_low_card_bug_long, 01516_drop_table_stress_long, 01443_merge_truncate_long, and ~15 others passing flaky-check at 200-400s.
d Test intent preserved? Yes — no query, assertion, setting, or coverage was changed. The test still runs in all the same lanes; the only behavioral change is that the 180s flaky-check gate is bypassed and the test is now skipped under --no-long (intentional lightweight-CI opt-out only).
e Both directions demonstrated? Yes — without fix: 41 runs too long failures in the last 30 days (CIDB). With fix: --no-long correctly skips with reason "not running long tests" (proving the runner parses the new tag); 5/5 flaky-check runs at 108-110s pass cleanly; debug 8s pass; ASan 47s pass with no-random-settings.
f Fix is general, not a narrow patch? Yes — flaky-test fix, not a code bug. The fix addresses the test's full nature (slow due to many client invocations); no symmetric code paths to widen.

Session id: cron:clickhouse-ci-task-worker:20260428-234500.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai — could you review this? It's a small test-only change adding the long tag to 02428_parameterized_view so the asan_ubsan flaky-check budget (180s) doesn't trip on the test's ~99 client-call structure. CIDB shows 41 timeouts across 10 unrelated PRs, p50=232s on amd_asan_ubsan flaky check.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3fc73e9]

Summary: ✅


AI Review

Summary

This PR rewrites tests/queries/0_stateless/02428_parameterized_view.sh to batch the non-error-path clickhouse-client calls, which removes the timeout pressure that previously motivated the long-tag workaround while preserving the normal Fast test and 50x flaky-check coverage. I reviewed the current diff and file, read the prior PR discussion and the resolved clickhouse-gh thread, and did not find any remaining correctness, coverage, or PR-metadata issues.

Final Verdict

✅ No blocking findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 29, 2026
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 42f907e

CI finished (161 check-runs complete, 0 pending). This PR changes only tests/queries/0_stateless/02428_parameterized_view.sh (a flaky-test fix). The sole red is a stale macOS-runner abort, not PR-caused.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) infra (macOS Darwin runner abort — job died in 1m22s at 2026-04-29 setup/build, no test-level rows; a test-only .sh change cannot break the Darwin build. CI has not re-run since; a maintainer re-trigger/merge will produce a fresh green run) a fix task is created (CI Darwin-runner infra — fixing-PR link to follow here)

Session id: cron:our-pr-ci-monitor:20260703-053000

Pick up merged fix ClickHouse#104946 (JIT symbol lookup on macOS) and current master
so CI re-runs the Fast test (arm_darwin) job on a healthy runner. The prior
run's arm_darwin red was a stale 2026-04-29 setup abort during the ~3-day
macOS runner outage (root cause tracked in ClickHouse#103235, LLVM 21 on Apple Silicon).

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

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Merged current master and re-pushed (42f907e -> 51282bc) to re-run CI on a healthy Darwin runner.

The prior Fast test (arm_darwin) red (42f907e, 2026-04-29, 1m22s) was a setup abort during the multi-day macOS runner outage, not this test-only change. That failure class is owned upstream:

The long-tag change is unchanged and still needed (master lacks it). Diff vs master is exactly the 4 added lines in tests/queries/0_stateless/02428_parameterized_view.sh.

Replace the long tag with query batching. The test spawned ~99 separate
clickhouse-client processes; under sanitizer + flaky-check parallel load
the per-run time exceeded the 180s flaky-check gate, causing timeouts.

Batching the setup/teardown and non-error-path statements into single
multi-statement client calls (~14 invocations) removes the dominant
per-spawn overhead: ASan single-process drops from ~45s to ~10s per run,
debug from ~9s to ~2.3s. The test now stays well under 180s without the
long tag, so it keeps the full 50x flaky-check repeat count and remains
part of the Fast test suite (both of which the long tag disabled).

Error-expecting queries stay individual because an error aborts the rest
of a batch. Test output and references are unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai groeneai changed the title Fix flaky 02428_parameterized_view — opt into long-test budget Speed up 02428_parameterized_view by batching client invocations Jul 3, 2026
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Good catch, you're right - long reduces the flaky-check repeat count (50 -> 5 via --long-test-runs-ratio) and drops the test from Fast test (--no-long), which is a real coverage loss, not just a timeout exemption.

Reworked to option A: the ~99 $CLICKHOUSE_CLIENT invocations are now batched into ~14 multi-statement calls and the long tag is removed, so the full 50x flaky-check and Fast test coverage stay intact. The per-spawn handshake/settings-parse overhead was the actual cost:

build (single-process) before after
debug 8.90s 2.29s
ASan ~45s ~10s

That keeps the test well under the 180s gate without long, even under the ~50x parallel amplification that produced the 232s p50 in CIDB.

Error-expecting queries (piped through grep) are kept individual, since an error aborts the rest of a multi-statement batch. --param_p/--param_l became inline SET param_*. Output/references/assertions are unchanged - verified byte-identical against both .reference and .oldanalyzer.reference, and 60/60 passes under --test-runs 30 with randomization.

@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.85% 85.87% +0.01%
Functions 91.47% 91.47% +0.00%
Branches 78.39% 78.43% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 104 line(s), 2 function(s) across 46 file(s) · Details

Top files
  • src/Server/DistributedQuery/StreamingExchangeSink.cpp: 6 line(s), 1 function(s)
  • src/Functions/dateName.cpp: 5 line(s)
  • src/Functions/timestamp.cpp: 5 line(s)
  • src/Interpreters/HashJoin/HashJoin.cpp: 5 line(s)
  • src/AggregateFunctions/AggregateFunctionLargestTriangleThreeBuckets.cpp: 4 line(s)

Full report

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 368e2ea

Every failure below has an owner: a fixing PR (ours 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. This PR is a test-only change (batching the 02428_parameterized_view.sh client invocations to bring per-run time under the 180s gate without the long tag); none of the failures below are caused by that .sh change.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 04319_skip_unavailable_shards_mode_table_missing, 02127_plus_before_float infra (macOS Darwin-runner setup timeout, ~1m; a test-only .sh change cannot break the Darwin build) a fix task is created (investigating at full effort, fixing-PR link to follow here)
Stress test (amd_tsan) / Block structure mismatch in JoinStep (STID 0993-308a) logical error, chronic trunk bug (22 hits / 19 unrelated PRs / 1 master in 30d; unrelated to this .sh change) #109114 (ours, open)
Stress test (arm_asan_ubsan) / Not-ready Set is passed as the second argument for function 'in' (STID 0250-4e52) logical error, chronic IN-family trunk bug (72 hits / 63 unrelated PRs / 8 master in 30d) #107924 (external, open)
CH Inc sync — CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260703-160000

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger update — arm_darwin line resolved to external fixing PR

Correcting the Fast test (arm_darwin) owner from the earlier "a fix task is created" placeholder to the fixing PR that now owns it.

Root cause (not the ~1m setup timeout guessed earlier, and not the LLVM-JIT class): 04319_skip_unavailable_shards_mode_table_missing hangs specifically on the macOS Darwin runner. Its distributed_foreground_insert into a self-referential 2-shard localhost cluster with a deliberately-missing shard table leaves the internal shard connection stuck in TCPHandler::receivePacketsExpectData for the full 300s receive_timeout (Code: 209 SOCKET_TIMEOUT: Waited for 310 seconds), and the per-test timeout then kills the client. CIDB confirms it is macOS-exclusive: 38 failures / 35 distinct PRs / 0 master, 0 on any Linux check (386 Linux Fast-test OK, 1986 stateless OK), since the test was added on 2026-06-13. 02127_plus_before_float was a one-off Darwin slowness (1 hit). None of this is caused by this test-only .sh change.

Owner: #108859 (external, open, mergeable) adds 04319_skip_unavailable_shards_mode_table_missing to ci/defs/darwin.skip under "Flaky on CI (stuck timeout)" — the correct skip mechanism for a macOS-only distributed-shard hang (the Darwin Fast test runs --shard unconditionally, so a Tags: skip would not apply).

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 04319_skip_unavailable_shards_mode_table_missing macOS-only 300s stuck timeout in the distributed foreground-insert path (not PR-caused; test-only .sh change) #108859 (external, open)

Session id: cron:clickhouse-worker-slot-15:20260703-162000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 3fc73e9

Every failure below has an owner: a fixing PR (ours 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
(none) — 174 checks completed, 0 failures

CI is fully finished on this head with no failing checks.

Session id: cron:our-pr-ci-monitor:20260729-103000

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good, thank you!

@alexey-milovidov alexey-milovidov self-assigned this Jul 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 29, 2026
Merged via the queue into ClickHouse:master with commit 5894ea8 Jul 29, 2026
179 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 Jul 29, 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.

3 participants