Skip to content

Apply -WithMemoryTracking containers to src/Processors/Merges - #124917

Merged
nickitat merged 4 commits into
masterfrom
wmt_processors_merges
Oct 11, 2026
Merged

nickitat merged 4 commits into
masterfrom
wmt_processors_merges

Conversation

@nickitat

@nickitat nickitat commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Version info

  • Merged into: 26.10.1.2131-master (included in 26.10 and later)

Replace the `std::` containers of the merge algorithms with their
`-WithMemoryTracking` counterparts and add `src/Processors/Merges` to the
style check.

These containers hold merge state that scales with the inputs: the per-source
`Sources` and row-reference chunk pool, the deferred-source and prefetch
lists, the queued row sources of the collapsing algorithms, the chunks a
replacing merge holds back for skipping `FINAL`, and the per-bucket chunks an
aggregating merge accumulates.

Three containers outside the directory are converted, because an algorithm in
this directory is what fills them:

- `ChunksToMerge::chunks` and the `GroupingAggregatedTransform` members that
  feed it. The type has two producers, `FinishAggregatingInOrderAlgorithm`
  here and the transform there, so it cannot be converted on one side only
  without a copy. The generic `Chunks` alias stays as it is; what is tracked
  is the per-bucket accumulation, which can hold a whole bucket's worth of
  aggregation state.
- The `flattened_ancestors` out-parameter of `Nested::flattenTupleRecursive`.
  The tuple-flattening summing merge is its only caller that passes one.

`Graphite.cpp` keeps its `ruleTypeMap` as `std::unordered_map`: it is a
process-wide constant built during static initialization, so a throwing
tracked allocator would charge it to whichever thread's memory tracker is
current and could throw before any tracker exists.

The local `using Row = std::vector<Field>` in `SummingSortedAlgorithm.cpp` is
removed rather than converted - it redeclares `DB::Row` from `Core/Field.h`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2042a65]

Summary: ✅


AI Review

Summary

This PR mechanically replaces merge-algorithm std:: containers with -WithMemoryTracking aliases so merge-state growth starts failing with MEMORY_LIMIT_EXCEEDED instead of silently overshooting limits. Most of the swaps stay inside query/merge-local state, but the Graphite alias change still widens the throwing-allocator surface into persistent table metadata, so I do not think this is ready as-is.

Missing context / blind spots
  • ⚠️ The full CI matrix was still pending while I reviewed (Build (amd_debug), Build (amd_asan_ubsan), Build (amd_tsan), Build (amd_msan), Build (amd_binary), Build (arm_asan_ubsan), Build (arm_binary), Build (wasm_parser), CH Inc sync, PR), so sanitizer/runtime confirmation for the final head is not available yet.
Findings

⚠️ Majors

  • [src/Processors/Merges/Algorithms/Graphite.h:119] [dismissed by author -- https://github.com/Apply -WithMemoryTracking containers to src/Processors/Merges #124917#discussion_r4230942394] Graphite::Retentions / Graphite::Patterns are no longer merge-local. MergeTreeData::MergingParams stores Graphite::Params by value (src/Storages/MergeTree/MergeTreeData.h:488), and setGraphitePatternsFromConfig fills that object on the CREATE / ATTACH / table-load path (src/Storages/MergeTree/registerStorageMergeTree.cpp:671, src/Processors/Merges/Algorithms/Graphite.cpp:456). After this typedef swap, ordinary table registration goes through the throwing allocator too, so a low query/global memory limit can now reject Graphite metadata loading even though the PR’s stated goal is to bound merge-state growth. I still think the safer split is to keep the stored config on ordinary containers and materialize a tracked copy only when building the merge-local GraphiteRollupSortedAlgorithm state (src/Processors/Merges/Algorithms/GraphiteRollupSortedAlgorithm.h:84).
Final Verdict

⚠️ Needs changes before merge: the Graphite container typedef change still alters the behavior of persistent table metadata loading, not just merge-local state.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 9, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Oct 9, 2026
@Algunenano Algunenano self-assigned this Oct 9, 2026
The exemption gave the wrong reason. `ruleTypeMap` is filled by its
initializer during static initialization, when there is no thread status:
both `std::unordered_map` and `UnorderedMapWithMemoryTracking` then charge
`total_memory_tracker` directly (or nothing, if it is not initialized yet),
and nothing can throw because no limit is set yet. With no difference
between the two, there is nothing to exempt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT

@Algunenano Algunenano 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.

All good

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-improvement Pull request with some product improvements labels Oct 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2042a653a with master 2079ed3d5 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of dca38d441; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

338 translation units recompiled, 3179 s compile time in total, 338 of them have a recent master baseline.

Job report

@nickitat
nickitat added this pull request to the merge queue Oct 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 10, 2026
@nickitat
nickitat enabled auto-merge October 11, 2026 11:28
@nickitat
nickitat added this pull request to the merge queue Oct 11, 2026
Merged via the queue into master with commit a347fef Oct 11, 2026
165 checks passed
@nickitat
nickitat deleted the wmt_processors_merges branch October 11, 2026 16:52
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-not-for-changelog This PR should not be mentioned in the changelog 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