Repository navigation
Memory tracking containers for columns - #98145
Conversation
…mns` Changed the `scatter` virtual method signature in `IColumn` and all overrides to return `VectorWithMemoryTracking<MutableColumnPtr>` instead of `MutableColumns` (`std::vector<MutableColumnPtr>`), so scatter results are tracked by the memory tracker. Updated all call sites outside `src/Columns` to use `auto` to capture the result, or updated container element types accordingly (`arrayFold.cpp`, `HashedDictionaryParallelLoader.h`). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…vectors Changed `IColumn::Patch::sources` from `std::vector<Source>` to `VectorWithMemoryTracking<Source>` so patch application is tracked by the memory tracker. Changed the inner `std::vector<size_t>` inside `VectorWithMemoryTracking<>` in `ColumnLowCardinality::getPermutation` to `VectorWithMemoryTracking<size_t>`. Updated the single external builder in `applyPatches.cpp`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… `ColumnString` Changed `batchSerializeValueIntoMemory` parameter from `std::vector<char *>` to `VectorWithMemoryTracking<char *>` in `ColumnString`, matching the virtual method signature in `IColumn`. Updated the call site in `ColumnsHashing.h` to use `VectorWithMemoryTracking<char *>` for the local `memories` variable. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Changed the parameter type of `getLeastSuperColumn` from `std::vector<const ColumnWithTypeAndName *>` to `VectorWithMemoryTracking<const ColumnWithTypeAndName *>`, and updated the three call sites in `Planner/Utils.cpp`, `InterpreterSelectWithUnionQuery.cpp`, and `InterpreterSelectIntersectExceptQuery.cpp` to use `VectorWithMemoryTracking` for their local `columns` vectors. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…riminator>` directly Changed all 3 private constructors of `ColumnVariant` to take `VectorWithMemoryTracking<Discriminator>` by value instead of `const std::vector<Discriminator> &`. The member assignment in the full constructor is now a direct move instead of a cross-allocator `.assign(begin, end)`. Updated all `MutablePtr create` inline overloads: `std::vector<Discriminator>` overloads now convert to `VectorWithMemoryTracking<Discriminator>` before calling `Base::create`; `VectorWithMemoryTracking<Discriminator>` overloads now pass directly via move. Updated the `Ptr create` `VectorWithMemoryTracking<Discriminator>` overloads in the `.cpp` to delegate directly to the corresponding `VectorWithMemoryTracking<Discriminator>` `MutablePtr create` overloads, eliminating the previous double-conversion through `std::vector<Discriminator>`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Add `std::vector` forwarding overloads in `ColumnObject.h` for backward compatibility with external callers in `src/DataTypes`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…eate` and `setDynamicPaths` Remove `std::vector` compatibility overloads and update all callers directly: - `ColumnVariant::create` overloads taking `const std::vector<Discriminator> &` removed from `ColumnVariant.h`/`.cpp`; `FunctionsConversion.h` caller updated - `setDynamicPaths` `std::vector` forwarding overloads removed from `ColumnObject.h`; callers updated: - `DeserializeBinaryBulkStateSubObject::dynamic_sub_paths` → `VectorWithMemoryTracking<String>` - `DeserializeBinaryBulkStateObjectStructure::sorted_dynamic_paths` inner type → `VectorWithMemoryTracking<String>` - `result_dynamic_paths` in `DataTypeObject.cpp` → `VectorWithMemoryTracking<std::pair<String, ColumnPtr>>` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…WithMemoryTracking` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…xplicit caller Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… to `VectorWithMemoryTracking` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Update all 7 separate alias definitions to use `VectorWithMemoryTracking<ColumnWithTypeAndName>`, fix explicit `std::vector<ColumnWithTypeAndName>` local variables in call sites, and templatize `applyPermutation` in `ColumnPermuteTransform` to accept any allocator. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…MemoryTracking<ColumnPtr>\` Update the virtual method signature in \`IColumn\`, all 11 override declarations, all 9 override implementations, and both callers in \`MergedData\` and \`ColumnGathererTransform\`. Local \`Columns\` temporaries inside the implementations are converted to \`VectorWithMemoryTracking<ColumnPtr>\` as well. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…umnPtr>\` Update the virtual method signature in \`IColumn\`, all 9 override declarations (including the private \`prepareVariantsForSquashing\` in \`ColumnDynamic\`), all 9 override implementations, and the caller in \`Squashing\`. Local \`Columns\` temporaries inside the implementations are converted to \`VectorWithMemoryTracking<ColumnPtr>\` as well. The initializer-list call in \`StreamingFormatExecutor\` requires no change. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…lumns/tests\` Full replacement across all test files, except: - \`Columns\`, \`MutableColumns\`, \`ColumnRawPtrs\` aliases (preserved per project convention) - \`std::vector<String>\` used in \`checkInsertFrom\`/\`checkInsertManyFrom\`/\`checkInsertRangeFrom\` helper parameters and corresponding local variables — these are compared via \`ASSERT_EQ\` against \`variant_names\` (type \`Names = std::vector<String>\`) and \`operator==\` requires matching allocators - \`std::vector<std::thread>\` in \`gtest_column_dump_structure\` is replaced as it is unrelated to column API boundaries Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ynamic\` Replace remaining \`std::vector<String>\` usages (\`expected_names\` parameters and local variables) with \`VectorWithMemoryTracking<String>\`. Fix the 8 \`ASSERT_EQ\` comparison sites against \`variant_names\` (type \`Names = std::vector<String>\`) by converting \`expected_names\` via range constructor: \`Names(expected_names.begin(), expected_names.end())\`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Since \`variant_names\` is of type \`Names\` (= \`std::vector<String>\`), replace \`VectorWithMemoryTracking<String>\` with \`Names\` for \`expected_names\` variables and parameters. This avoids the need for range-constructor conversions at \`ASSERT_EQ\` sites and keeps the test types consistent with the API types they compare against. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…/Columns - ColumnDynamic.h: member `variants_with_failed_combination` - ColumnObject.cpp: local `new_dynamic_paths` in `serialize` - ColumnReplicated.cpp: local `indexes_of_default_values` in `getNumberOfDefaultRows` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- member `sorted_dynamic_paths` and its iterator pair Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…/Columns Internal struct members and type aliases: - ColumnDynamic.h: `VariantInfo::variant_name_to_discriminator`, `variant_mappings_cache`, `serialization_cache`, `DynamicColumnCheckpoint::variants_checkpoints`; `Statistics::variants_statistics` and `shared_variants_statistics` kept as `std::unordered_map` (external API boundary via SerializationVariant) - ColumnObject.h: `Statistics::dynamic_paths_statistics`, `Statistics::shared_data_paths_statistics`, `PathToColumnMap`, `PathToDynamicColumnPtrMap` - ColumnReplicated.h: `insertion_cache` Updated `extendVariantColumn` signature and `getCheckpoint` local variable in ColumnDynamic.cpp, and test helper in gtest_column_dynamic.cpp. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ing in src/Columns - ColumnObject.h: private constructors, public create methods - ColumnObject.cpp: all local variables, constructor/create definitions, CheckpointsMap type alias; also updates VectorWithMemoryTracking element types - ColumnDynamic.cpp: local vars in takeDynamicStructureFromSourceColumns and prepareVariantsForSquashing - Collator.h: AvailableLocalesMap type alias - Updated external callers: DataTypeObject.cpp (createColumn local var) and gtest_column_object.cpp (test local var) - Updated tests: gtest_column_dynamic.cpp, gtest_column_unique.cpp, gtest_weak_hash_32.cpp Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…rderedMapWithMemoryTracking - ColumnDynamic.h: Statistics::variants_statistics, Statistics::shared_variants_statistics - SerializationVariant.h/.cpp: updated serializeBinaryBulkWithMultipleStreamsAndUpdateVariantStatistics parameter and internal tmp_statistics local variable Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
740e91d to
afa999e
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces systematic memory tracking for column-related containers in the ClickHouse codebase. The main goal is to replace standard containers (std::vector, std::unordered_map, std::set) with memory-tracking variants to enable throwing memory tracking and prevent out-of-memory (OOM) kills in production environments.
Changes:
- Replaced standard container types with memory-tracking variants (VectorWithMemoryTracking, UnorderedMapWithMemoryTracking, SetWithMemoryTracking) for column-related data structures
- Updated IColumn::scatter return type and all implementations to return VectorWithMemoryTracking
- Changed ColumnsWithTypeAndName typedef to use VectorWithMemoryTracking
- Updated CI style checks to enforce memory-tracking containers in src/Columns directory
- Special exemptions for Columns, MutableColumns, and ColumnRawPtrs which remain as std::vector with STYLE_CHECK_ALLOW_STD_CONTAINERS markers
Reviewed changes
Copilot reviewed 89 out of 89 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Columns/IColumn.h | Updated scatter method signature and prepareForSquashing to use VectorWithMemoryTracking |
| src/Columns/IColumn_fwd.h | Added VectorWithMemoryTracking for EqualRanges and ColumnCheckpoints; kept Columns/MutableColumns/ColumnRawPtrs as std::vector with exemption markers |
| src/Core/ColumnsWithTypeAndName.h | Changed typedef to use VectorWithMemoryTracking |
| src/Columns/ColumnVariant.h | Updated internal data structures and method signatures to use memory-tracking containers |
| src/Columns/ColumnObject.h | Replaced std::unordered_map with UnorderedMapWithMemoryTracking for path mappings |
| src/Columns/ColumnDynamic.h | Updated variant info structures and caches to use memory-tracking containers |
| src/Storages/*.cpp | Updated scatter call sites to use auto instead of explicit MutableColumns type |
| src/Processors/Transforms/*.cpp | Updated to work with new container types |
| src/Functions/*.cpp | Adapted to new ColumnsWithTypeAndName type |
| src/Columns/tests/*.cpp | Updated test code to use memory-tracking containers |
| ci/jobs/scripts/check_style/check_cpp.sh | Added src/Columns to directories enforcing memory-tracking container usage |
|
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
Do not merge before investigating and fixing:
Stateless tests (arm_asan, targeted) failure
00633_materialized_view_and_too_many_parts_zookeeper FAIL cidb
Integration tests (amd_asan, db disk, old analyzer, 4/6) failure
test_ttl_replicated/test.py::test_ttl_compatibility[node_left1-node_right1-1] FAIL cidb, #98166
@alexey-milovidov, please make your automatics more accurate. |
|
Waiting while these tests will be fixed in master. |
|
@alexey-milovidov, would you like to take another look? |
|
|
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 83.33% (920/1104, 7 noise lines excluded) |
`26.3` has neither the untrusted-count hardening that this change rewords on master (the `reserveOrThrowTooMany*` helpers and the `MAX_DYNAMIC_TYPES_LIMIT` check) nor master's newer `SerializationObjectHelpers` signatures. Keep the `26.3` code and apply only the switch to memory-tracked containers, with `unflattenAndInsertPaths` instantiated for `std::vector<ColumnPtr> &&`. The version 2 query in the test expects the non-flat path list to be memory-tracked, which came with #98145 and is not in `26.3`, so the test keeps only the version 3 (FLATTENED) query that this change fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Note
Medium Risk
Touches core
IColumnAPIs (scatter,prepareForSquashing, dynamic-structure helpers) and many column implementations, so regressions would surface broadly at runtime or as subtle performance/memory-limit behavior changes.Overview
Primary change: replaces
std::vector/std::unordered_map/std::unordered_set(and related aliases) used throughoutsrc/ColumnswithVectorWithMemoryTracking,UnorderedMapWithMemoryTracking,UnorderedSetWithMemoryTracking, andSetWithMemoryTrackingto ensure allocations participate in throwing memory tracking.API surface updates: updates
IColumnand many column overrides to use these memory-tracked containers forscatterreturn values,prepareForSquashinginputs, dynamic-structure plumbing, and related helpers (e.g.,countColumnsSizeInSelector,ColumnVariantdiscriminator mappings,ColumnObjectpath maps/sets).Tooling: extends the style check to lint
src/Columnsfor directstd::*container usage.Written by Cursor Bugbot for commit 9f33db3. This will update automatically on new commits. Configure here.
Version info
26.4.1.88