Repository navigation
Cherry pick #132557 to 26.3: Fix a memory leak of min/max states built for _minmax_count_projection - #132774
Conversation
`MergeTreeData::getMinMaxCountProjectionBlock` built each min/max/count state in a temporary place (arena alloc + `create` + `add`) and then called `ColumnAggregateFunction::insertFrom(place)`. That overload does not take ownership: it creates a new column-owned state and merges `place` into it, so `place` was never destroyed. For a `min`/`max` state that owns heap memory (`SingleValueDataGeneric` holding a `Tuple`, `Array` or long `FixedString` field of the first primary key column or of a min-max partition column) every part read leaked one state, which LeakSanitizer reported in a stress run (STID 1830-4545). Build the state inside the column instead (`insertDefault` and fill `getData().back()`, as `FunctionsConversion.cpp` does), so the column owns it from creation and destroys it on every path, including the early returns and an exception from `add`. Results are unchanged: merging into a default state yields the same state. The new test runs the query in a short-lived `clickhouse-local` and counts LeakSanitizer reports in its own log; the count is 0 on builds without a leak sanitizer, and an EXPLAIN line asserts the projection was used. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`makeBlockFromStatistics` had the same shape as the `_minmax_count_projection` builder fixed in the previous commit: it allocated each state in the column's arena, filled it, and passed it to `ColumnAggregateFunction::insertFrom(place)`, which merges `place` into a new column-owned state and never destroys `place`. It does not leak today only because the states it builds have no heap memory: `count`, `min`/`max` of a type whose value is a number (`canStatisticsTrackMinMax`), and `sum`/`avg`/`sumCount` of an integer or `Decimal`. Use `insertDefault` and fill `getData().back()` here too, so the column owns the state from creation and destroys it on every path, including an exception from `add`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…state-leak Fix a memory leak of `min`/`max` states built for `_minmax_count_projection`
|
The only conflict is in On a 26.3 ASan build, I cannot push to |
…2557/cherrypick/26.3/132557 # Conflicts: # src/Processors/QueryPlan/Optimizations/optimizeUseAggregateProjection.cpp
Original pull-request #132557
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job