Skip to content

Apply -WithMemoryTracking containers to src/Processors/QueryPlan - #129617

Merged
nickitat merged 11 commits into
masterfrom
wmt_processors_query_plan
Nov 13, 2026
Merged

nickitat merged 11 commits into
masterfrom
wmt_processors_query_plan

Conversation

@nickitat

@nickitat nickitat commented Nov 5, 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/129617]

Version info

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

Converts the standard containers in `src/Processors/QueryPlan` and adds the directory to the
style check. Starts from the `QueryPlan` part of the earlier whole-`src/Processors` branch, with
master's newer code converted the same way.

Types are propagated to their owners where they cross the directory boundary:
`ActionsDAG`, `ExpressionActions`, `JoinOperator`, `JoinExpressionActions`,
`MergeTreeWhereOptimizer`, `ClusterProxy::executeQuery`, `distributedIndexAnalysis`,
`SelectQueryInfo`, `SetSerialization`, `ParallelReplicasReadingCoordinator`,
`RelationProfile`, `RuntimeFilterReadRangesRefiner`, `MergeTreeIndexBuildContext`,
the `unitePlans` callers and `PartitionIdToMaxBlock`. Where the owner is shared more widely
(`KeyDescription::reverse_flags`, `KeyCondition::Description::used_keys`,
`MergeTreeDataSelectExecutor::filterPartsByVirtualColumns`, the posting list cursors, settings
that convert only to `std::vector`), the usage is marked with `STYLE_CHECK_ALLOW_STD_CONTAINERS`
and the reason, instead of copying.

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

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c43b9eb]

Summary: ✅


AI Review

Summary

Converts query-plan containers and their callers to memory-tracking allocators. Review found one pre-existing, client-reachable null dereference in the modified ActionsDAG deserializer; it needs a fix or an explicitly linked tracking issue.

Findings

❌ Blockers

  • src/Interpreters/ActionsDAG.cpp:5423: Deserialization does not enforce children-before-parents ordering. All nodes are allocated before decoding, so .at(child_id) accepts a reference to a later node whose result_type is still null. A two-node DAG beginning with plus and children [1, 1] reaches IFunctionOverloadResolver::build → isDynamic → WhichDataType, which dereferences the null type. An Expression step in a client QueryPlan packet reaches this when process_query_plan_packet is enabled; the failure occurs before later validation. Require child_id < i before storing each edge. This also excludes self-references and cycles for function, alias, array-join, and nested-capture DAGs. The defect predates this PR; link a tracking issue if addressing it separately.
Tests
  • ⚠️ Add a focused raw-protocol regression rejecting forward and self child references with an exception while the server remains available; the packet helpers in tests/queries/0_stateless/05427_query_plan_deserialize_deep_recursion.sh provide an existing approach. The finding was verified by tracing current code; no local build or runtime test was available. The fetched CI report showed no failed tests, but does not establish this malformed-input behavior.
Final Verdict

Status: ❌ Block. Enforce the child-order invariant with regression coverage, or link a tracking issue for the pre-existing defect if its fix is kept separate.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... labels Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c43b9eb93 with master c4830992f (stripped binary size, per-symbol sizes and ThinLTO time; 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.

Object file sizes

484 object files changed (+461.52 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/ActionsDAG.cpp.o 1.44 MiB 1.46 MiB +21.66 KiB (+1.47%)
src/CMakeFiles/dbms.dir/Processors/QueryPlan/ReadFromMergeTree.cpp.o 2.55 MiB 2.57 MiB +17.47 KiB (+0.67%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.88, programs/clickhouse-keeper ×0.63 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.9 s 14.4 s +9.2 s (+176%)
Compile time of recompiled translation units

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

Job report

nickitat and others added 2 commits November 8, 2026 13:19
…y_plan

Conflicts in `FragmentGraphTree.cpp` and `TextCanvas`: kept master's new `details`
parameter and used `VectorWithMemoryTracking` for it. Also converted the containers
master added in `useShuffleForOrderByRand.cpp`, `shortCircuitConstantFalseJoin.cpp`,
`FilterStep.cpp`, `ReadFromMergeTree.cpp` and `Serialization.cpp`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
Master added the same `ListWithMemoryTracking.h` and `VectorWithMemoryTracking.h`
includes to `QueryPlan.h` and `ActionsDAG.cpp`, which `clang-tidy` reports as
`readability-duplicate-include`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129617&sha=latest&name_0=PR
#129617

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
nickitat and others added 2 commits November 9, 2026 12:39
…y_plan

Conflicts in `ActionsDAG.h` and `ExpressionJIT.cpp`: kept master's new
`getCompiledFunctions` and `UnorderedSetWithMemoryTracking` for the
`compileExpressions` argument. Also converted the containers master added in
`Optimizations/Utils.cpp`, and removed an include of `StorageFile.h` that master
now has too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
The 54 files in `src/Processors/QueryPlan/Optimizations` whose changes do not
depend on any changed header go to their own PR, so both are smaller to review.
The `QueryPlan` entry of the std containers check moves to whichever of the two
merges last: neither of them alone converts the whole directory.

#129617

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

Master moved the `ActionsDAG` traversals to `ActionsDAGTraversal.h`; the conflicts
in `ActionsDAG.cpp`, `FilterStep.cpp`, `actionsDAGUtils.cpp` and `filterPushDown.cpp`
take master's code with the tracked containers it still declares. The other
conflicts are in `IQueryPlanStep.cpp` includes, `ReadFromMergeTree.h` and
`optimizeUseAggregateProjection.cpp`.

Also converted the containers master added in `RelationEstimateInfo.h`,
`JoinStepLogical.cpp`, `ReadFromMergeTree.cpp`, `Cascades/Properties.cpp` and
`lowerArrayJoinFunction.cpp`, and the `getCompilableDAG` declaration master added
to `JIT/CompileDAG.h`. The new `Cascades` window rule follows `Rule.h`, which is
converted in #130369.

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.

Maybe it'd make sense to introduce some declarations?

VectorWithMemoryTracking<QueryPlanPtr> -> QueryPlanPtrs or similar
VectorWithMemoryTracking<std::string_view> Parts (for local parts, remote parts, etc).

@nickitat
nickitat requested a review from Algunenano November 12, 2026 22:09
@Algunenano
Algunenano added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 13, 2026
@nickitat
nickitat enabled auto-merge November 13, 2026 14:38
Comment thread src/Interpreters/ActionsDAG.cpp Resolved
nickitat added a commit to groeneai/ClickHouse that referenced this pull request Nov 14, 2026
olegkkruglov pushed a commit to olegkkruglov/ClickHouse that referenced this pull request Nov 19, 2026
shankar-iyer added a commit to shankar-iyer/ClickHouse that referenced this pull request Nov 20, 2026
The style check requires the `-WithMemoryTracking` containers in
`src/Processors/QueryPlan` since ClickHouse#129617.

PR: ClickHouse#131216

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Manerone pushed a commit that referenced this pull request Nov 20, 2026
Resolve the conflict in src/Interpreters/ExpressionJIT.cpp: the new
ActionsDAG::getCompiledConjuncts sits right above compileFunctions, whose
parameter type differs on 26.10 (std::unordered_set; master switched it to
UnorderedSetWithMemoryTracking in #129617, which is not on 26.10). Keep the
26.10 signature and add only the lines of #131211.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... 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