Skip to content

Fix flaky test 04780_json_subcolumn_index_match_not_quadratic - #132825

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04780-peak-memory-oracle
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04780-peak-memory-oracle

Conversation

@groeneai

@groeneai groeneai commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113003

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

Make the test 04780_json_subcolumn_index_match_not_quadratic measure the peak memory of its queries, so neighbouring load no longer makes it fail.

Description

Since 2026-11-15 the 150% bound fires on jemalloc builds (2 master runs, 2 PR runs, reports below), each time with the no-dots control 34-37% below the dotted query (on amd_debug and amd_release ~11.4 MB against the dotted query's normal ~17.9 MB). Reruns pass.

ProfileEvents['MemoryAllocatedWithoutCheckBytes'] counts a thread's deferred allocations when they are flushed, and only when the allocation that triggers the flush skips the limit check. With max_untracked_memory = 1Mi (the test configuration) a thread also flushes when the per-CPU untracked budget, shared by every thread on that CPU, runs out. So the reading of the same query depends on its neighbours: on a debug build with the CI test configuration, the control read 17,937,304 bytes when idle and 13,198,360 bytes with 16 client loops on the server's two CPUs. min() over the three runs keeps a low control reading.

The test now reads memory_usage (the query's peak) with --max_untracked_memory 0, as 04072_columns_cache_memory_usage does: every allocation and free reaches the query's tracker at once, so the peak depends on the query only. The three runs, the 150% bound and the four tables are unchanged.

Validated on master debug and ASAN builds with the CI test configuration: ratio 1.0000 on every table when idle, with max_per_cpu_untracked_memory = 1, and under load (30/30 runs under load on each build, 50/50 randomized runs). With the pre-#113289 matcher restored, the dotted query peaks at 2.61x-2.74x the control on every table and the test fails.

Reports:

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/132825]

ProfileEvents['MemoryAllocatedWithoutCheckBytes'] counts a thread's deferred
allocations when they are flushed, and only for flushes triggered by an
allocation that skips the limit check. With max_untracked_memory = 1Mi a thread
also flushes when the per-CPU untracked budget (max_per_cpu_untracked_memory,
shared by every thread on that CPU) runs out, so which allocation triggers a
flush, and therefore the reading of an identical query, depends on the
neighbours. Measured on a debug build with the CI test configuration: the
no-dots query reads 17937304 bytes when idle and 13198360 bytes with 16 client
loops on the server's two CPUs. Every CI failure since 2026-11-15 shows the
dotted query at ~17.9 MB and the control at ~11.4 MB; min() over three runs
keeps the low control reading.

Read system.query_log.memory_usage with --max_untracked_memory 0 instead, the
idiom of 04072_columns_cache_memory_usage: every allocation and free then
reaches the query's tracker at once, so the peak depends on the query alone.
Post-fix ratio 1.0000 on debug and ASAN when idle, with
max_per_cpu_untracked_memory = 1 and under load. With the pre-ClickHouse#113289 matcher
restored the dotted query peaks at 2.61x-2.74x the control on every table.

CI reports:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=b92770f43d1a3ca2d4878eb819158dac9d9f6300&name_0=MasterCI
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=2f06a797f107f1ed0ce1b38819d86c4a72329e86&name_0=MasterCI
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129081&sha=eee40ead1c9a9ad89b2b213819ee4e40ee84730c&name_0=PR
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131814&sha=22109b852152744c53fb91a21bb401b4654c1f50&name_0=PR

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 1 finding), plus one nit from my own review.

# Sev Finding Verdict Evidence / action
1 ❌ The peak cannot see a matcher that formats and discards one key per dot (quadratic allocation volume, linear peak); keep MemoryAllocatedWithoutCheckBytes with --max_untracked_memory 0 instead DISAGREE The current counter does not see that churn either: on the restored pre-#113289 matcher (142.5 GB allocated per dotted query, debug build) it reads 2.49x the control, which is the retained split vector, the same thing the peak catches (2.61x-2.74x, the test fails). With --max_untracked_memory 0 the counter reads 0 on ASAN, so the -gt 0 guard would fail every sanitizer run.
2 💡 The description applied the amd numbers (~17.9 MB / ~11.4 MB) to the arm_binary failure (23.4 / 15.5 MB) AGREE, fixed in the description none

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261118-213300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A verbatim copy of the test's measuring function, run with max_per_cpu_untracked_memory = 1 only while the dotted query runs, reads 5.89x-7.12x on every table with the old oracle, every time. Real load (16 client loops on the server's 2 CPUs) moves the old control reading 17,937,304 -> 13,198,360 bytes, the direction seen in CI.
b Root cause explained? MemoryAllocatedWithoutCheckBytes sums flushed batches whose triggering allocation skips the limit check. The per-CPU untracked budget, shared with neighbour threads, moves the batch boundaries, so identical queries read 13.2-18.0 MB, and min() over three runs keeps a low control reading.
c Fix matches root cause? Yes. The oracle is the query's peak with deferral disabled (--max_untracked_memory 0), which has no flush-timing input: byte-identical readings under the forced budget and under load. Bound, runs and tables are unchanged.
d Test intent preserved / new tests added? Yes. With the pre-#113289 matcher restored, the new oracle reads 2.61x-2.74x on all four tables and the test fails 3/3.
e Both directions demonstrated? Old oracle 5.89x-7.12x vs new 1.0000x under the same forced budget; under load the old reading moves (0.74x-1.36x), the new one does not.
f Fix is general across code paths? The function changed is the only measuring site; the 5th table in the open #119641 goes through the same function.
g Fix generalizes across inputs (params/datatypes/wrappers)? All four tables, randomized and non-randomized settings (75 runs on the HEAD build), debug and ASAN; max_untracked_memory is not randomized by the runner.
h Backward compatible? (maintainer-approved exception only) Test-only change.
i Invariants and contracts preserved? The min-of-3 rationale, HAVING count() = 3 and the -gt 0 guard are unchanged; memory_usage > 0 on both builds.

Session id: cron:clickhouse-impl-slot-5:20261118-200001

@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5647133]

Summary: ✅


AI Review

Summary

This PR stabilizes 04780_json_subcolumn_index_match_not_quadratic by measuring query peak memory with max_untracked_memory = 0, eliminating the allocation counter’s dependence on shared per-CPU flush timing. The existing threshold and four-table coverage are preserved. The documented debug/ASan load runs and restored-matcher negative controls support the change. No actionable findings.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary was available, so the test was not rerun during this review. The inspected focused CI reports contained no result for this test; runtime evidence comes from the PR’s recorded validation. A CI result for this test would provide independent confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Nov 18, 2026
@tiandiwonder tiandiwonder self-assigned this Nov 18, 2026
@tiandiwonder tiandiwonder added the can be tested Allows running workflows for external contributors label Nov 18, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-key-condition Analysis of a filter against a key. KeyCondition turns a WHERE condition into ranges over the pri... and removed comp-testing Test content only (no production code). labels Nov 20, 2026

This branch has not been deployed

No deployments
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 comp-key-condition Analysis of a filter against a key. KeyCondition turns a WHERE condition into ranges over the pri... pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants