Skip to content

Measure exact query memory in 04072_columns_cache_memory_usage - #123949

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-04072-columns-cache-exact-query-memory
Nov 2, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-04072-columns-cache-exact-query-memory

Conversation

@groeneai

@groeneai groeneai commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #96844

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

04072_columns_cache_memory_usage fails in Part 2 with FAIL: query memory grew with the cached data (cache growth: 6.00, memory ratio: 135.35). It was seen on ClickHouse's internal CI (sanitizer builds, about 1% of runs); public CI has no failure of it yet. The test was added by #96844.

The two measured scans are identical cache hits whose only big allocation is the copy of the cached rows into the result block (~640 KB). That is below the 1 MiB max_untracked_memory of the test profile (tests/config/users.d/memory_profiler.xml), so whether the copy reaches the query's memory tracker depends on when the thread's batch or the per-CPU untracked budget (max_per_cpu_untracked_memory, shared with the other threads on that CPU) forces a flush, not on the query. The failing numbers decompose exactly so: small scan 4768 B (copy not seen), large scan 645344 B, and 645344 - 4768 = 640576 is the copy.

The five measured queries now run with --max_untracked_memory=0, as 01526_max_untracked_memory.sh does, so memory_usage is the real peak. Only the test changes.

Validation on the MasterCI amd_asan_ubsan binary of the base commit, with the CI test config:

  • Part 2 of the test with the per-CPU budget switched off before the small scan and set to flush every allocation before the large one (SYSTEM RELOAD CONFIG): without this change 7/7 FAIL, ratio 136.28 (small 4768 B, large 649792 B); with it 30/30 PASS, ratio 1.00, in three switch orders.
  • The changed test: 50/50 OK on ASan, 20/20 on debug. Every measured value was identical across the 50 ASan runs.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1077-master (included in 26.11 and later)

Part 2 of the test compares the `memory_usage` peaks of two identical
cache-served scans and failed with "memory ratio: 135.35" (small scan
4768 B, large scan 645344 B). The only big allocation of such a scan is
the copy of the cached rows into the result block (~640 KB, in
`MergeTreeReaderWide::serveRowsFromColumnsCache`), which is below the
1 MiB `max_untracked_memory` of the test profile. Whether the copy
reaches the query's memory tracker then depends on when the per-thread
batch or the per-CPU untracked budget (shared with other threads)
forces a flush, not on the query: 645344 - 4768 = 640576 is the copy.

With `max_untracked_memory = 0` every allocation is accounted
immediately, so `memory_usage` is the real peak. The flag goes on the
client command line, so it is applied to the query context before the
TCP thread attaches. Part 1 reads the same peak and gets the same
flag. Precedent: 01526_max_untracked_memory.sh.

Forcing the flush schedule with `max_per_cpu_untracked_memory` on a
server reload (budget off before the small scan, every allocation
flushed before the large one) reproduces the failure deterministically
without this change (ratio 136.28, 7/7) and passes with it (ratio 1.00,
30/30 over three orders).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Oct 5, 2026
@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review of the diff (0 blocker/major findings). Nothing to adjudicate.

Severity: ❌ blocker / ⚠️ major / 💡 nit. No findings in any category.

@clickhouse-gh

clickhouse-gh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aee381e]

Summary: ✅


AI Review

Summary

PR #123949, reviewed at aee381eecd26b15ea67f052cf465b037cca85a79, sets max_untracked_memory=0 on the five measured queries in 04072_columns_cache_memory_usage. This removes deferred allocation accounting from the memory comparisons while preserving the cache-hit and cache-growth assertions. No actionable findings.

Missing context / blind spots
  • ⚠️ The stateless test was not rerun locally because no ClickHouse binary or build was available. Runtime evidence relies on the PR's documented deterministic reproduction and repeated passing ASan/debug runs; a test result on the reviewed head would provide independent confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 5, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 8, 2026
…off parallel replicas

04070, 04072, 05029, 05055, 05155 and 05210 assert `ColumnsCacheHits`/`ColumnsCacheMisses` from
the initiator's `system.query_log` row, the same oracle as the nine tests fixed in the previous
commit. They have not failed in the `ParallelReplicas` lane yet, but they carry the same
precondition: when a remote replica reads all marks of a measured read, the initiator row has
no cache events. With `parallel_replicas_local_plan = 0` on a local `ParallelReplicas` rig the
unmodified tests fail 18/18 with exactly that shape, and pass 55/55 with the pin. The pinned
runs have no secondary replica query for any measured read. In all six tests the measured reads
depend on the cache state left by the reads before them, so the pin covers the whole test: a
session `SET`, and for the shell test 04072 the client option, which keeps it apart from the
lines changed by ClickHouse#123949.

Also quote the setting and table names in the comments of the pins, as the in-tree style asks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim

Copy link
Copy Markdown
Member

@alexey-milovidov you should quickly review this PR to fix CI

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 2, 2026
Merged via the queue into ClickHouse:master with commit cd3eb17 Nov 2, 2026
179 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Nov 2, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 2, 2026
Backport #123949 to 26.10: Measure exact query memory in `04072_columns_cache_memory_usage`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants