Skip to content

Fix flaky test 01661_extract_all_groups_throw_fast under memory pressure - #111513

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-01661-extract-all-groups-memory-flake
Jul 24, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-01661-extract-all-groups-memory-flake

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

The first query materialized a ~1.3 GB haystack column (numbers(1023), each row up to 2.66 MB) only to trip the per-row regexp_max_matches_per_row (default 1000) fast-throw TOO_LARGE_ARRAY_SIZE in extractAllGroupsHorizontal. The throw fires on the first row (2600 matches); the rest of the column is wasted allocation. Under the shared parallel-runner memory budget, building it could hit MEMORY_LIMIT_EXCEEDED before the expected throw, so the test intermittently failed (0 master failures, 27 unrelated PRs in 30 days).

Replaced it with a single materialized 1001-character row, which crosses the same per-row limit at ~1 KB instead of 1.3 GB. materialize() keeps the runtime (non-const) code path the throw lives in. A low max_memory_usage on the query also makes the throw deterministic under memory pressure and guards against regressing to a large fixture. The second "shouldn't fail" query is unchanged.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110567&sha=59463dc81a15d063a99e8803ccaaa66e374133da&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Verified with a debug build: the old fixture throws MEMORY_LIMIT_EXCEEDED (241) under a 100 MB query cap, the new one throws TOO_LARGE_ARRAY_SIZE (128) even under a 20 MB cap; both queries pass 20/20 against a live server. regexp_max_matches_per_row and max_memory_usage are not in the CI random-settings pool, so the throw is deterministic.

The first query materialized a ~1.3 GB haystack column (numbers(1023), each
row up to 2.66 MB) only to trip the per-row regexp_max_matches_per_row
(default 1000) fast-throw TOO_LARGE_ARRAY_SIZE. The throw fires on the first
row (2600 matches); the rest of the column is wasted allocation. Under the
shared parallel-runner memory budget, building it could hit
MEMORY_LIMIT_EXCEEDED before the expected throw, so the test intermittently
failed (0 master failures, 27 unrelated PRs in 30 days).

Use a single materialized 1001-character row, which crosses the same per-row
limit at ~1 KB instead of 1.3 GB. materialize() keeps the runtime code path
the throw lives in. A low max_memory_usage on the query also guards against
regressing to a large fixture. The second query is unchanged.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local -q "SELECT extractAllGroupsHorizontal(materialize(repeat('a', 1001)), '(\w)') FORMAT Null;" throws TOO_LARGE_ARRAY_SIZE (128) every time. The old fixture reproduces the flake deterministically under a memory cap: ... FROM numbers(1023) ... SETTINGS max_memory_usage=100000000 -> MEMORY_LIMIT_EXCEEDED (241).
b Root cause explained? Yes. Query 1 built a ~1.3 GB haystack column (numbers(1023), rows up to 2.66 MB) only to trip the per-row regexp_max_matches_per_row (default 1000) fast-throw at extractAllGroups.h:198. The throw fires on row 1 (2600 matches); rows 2..1022 are never processed = wasted allocation. Under shared parallel-runner memory pressure the column build can hit MEMORY_LIMIT_EXCEEDED (241) before TOO_LARGE_ARRAY_SIZE (128), violating the expectation.
c Fix matches root cause? Yes. It removes the multi-GB allocation and trips the SAME per-row limit with a single 1001-char row (~1 KB). No no-random-* tag, no widened expectation, no MEMORY_LIMIT-tolerance band-aid.
d Test intent preserved / new tests added? Yes. Still asserts the TOO_LARGE_ARRAY_SIZE fast-throw for over-limit matches-per-row; the second "shouldn't fail" query is unchanged. Boundary verified: 1000 matches -> no throw; 1001 -> throw. The added max_memory_usage cap also makes a revert to a large fixture fail deterministically.
e Both directions demonstrated? Yes. OLD fixture under a 100 MB cap -> 241; NEW fixture under the same cap -> 128 (green even at 20 MB). Both file queries pass 20/20 against a live server (build 312d03c2).
f Fix is general across code paths? N/A (flaky test fixture fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test fixture fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (test-only; no setting/format/behavior change).
i Invariants and contracts preserved? N/A (test-only; server behavior untouched).

Session id: cron:clickhouse-author-slot-5:20260723-005400

@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; 3 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck). Delta re-review after fixes: 0 findings.

# Sev Finding Verdict Evidence / action
1 ❌ Worktree changes ten third-party gitlinks unrelated to the test-only change DISAGREE (harness artifact) The commit touches exactly one file (git diff-tree --name-only HEAD = the test). The 10 contrib/* entries were working-tree submodule drift from a rebase (on-disk checkouts lagging the rebased HEAD pins), never staged/committed/pushable; the gate's diff BASE -> working-tree picked them up. Terminal. Also fixed at the source: synced the tree to base pins, delta re-review DIFFSTAT = 1 file, 0 findings.
2 ⚠️ Test doesn't deterministically prove the memory fix — a revert to the old fixture could still pass AGREE — fixed Added SETTINGS max_memory_usage = 100000000 to query 1. Verified: OLD fixture under that cap -> code 241, NEW fixture -> code 128 (green to 20 MB). A revert to the large fixture now fails deterministically. Re-verified both-directions + boundary + 20/20 live-server.
3 💡 Setting name in comment not formatted as inline code AGREE — fixed Backticked `regexp_max_matches_per_row` (and `max_memory_usage`) in the comment.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE carries recorded evidence and is terminal per finding.

Session id: cron:clickhouse-author-slot-5:20260723-005400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Ergus — could you review this? Test-only: 01661 tripped the per-row regexp_max_matches_per_row fast-throw by materializing a ~1.3 GB haystack column, which could hit MEMORY_LIMIT_EXCEEDED before the expected TOO_LARGE_ARRAY_SIZE under memory pressure. Replaced it with a single 1001-char row (same throw, ~1 KB) plus a low max_memory_usage guard.

@alexey-milovidov alexey-milovidov 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 [b54dc15]

Summary: ✅


AI Review

Summary

This PR replaces the first fixture in 01661_extract_all_groups_throw_fast.sql with a one-row materialize(...) query and adds a query-local max_memory_usage cap so the test still exercises the non-constant extractAllGroupsHorizontal fast-throw without building the old multi-GB haystack column first. I did not find a correctness, coverage, or determinism regression in the updated test, and the current Praktika report for commit b54dc15c is green.

Final Verdict
  • Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — b54dc15

CI fully finished. All checks green (no failing test-level rows in CIDB; Mergeable Check and Finish Workflow both pass). No PR-caused failures, nothing to own.

Check / test Reason Owner / fixing PR
(all green) - -

Session id: cron:our-pr-ci-monitor:20260723-183000

@alexey-milovidov alexey-milovidov self-assigned this Jul 24, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 24, 2026
Merged via the queue into ClickHouse:master with commit 2762572 Jul 24, 2026
178 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 24, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-extract-all-groups-memory-flake

Fix flaky test 01661_extract_all_groups_throw_fast under memory pressure
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