Repository navigation
Do not copy column names shaped like Map key subcolumns in every skip index condition - #122144
Conversation
Each `bloom_filter` condition builds and keeps its own set of the column names containing `.key_`, even when the predicate reads no map (`MergeTreeIndices.cpp:99`). 128 indexes over 1000 such columns peak at 73 MiB vs 11 MiB for the same table without them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pre-PR validation: 4/6 ✅a) Deterministic repro? ❌ b) Root cause explained? ✅ c) Fix matches root cause? ✅ d) Test intent preserved? / New tests added? ❌ e) Both directions demonstrated? ✅ f) Fix is general, not a narrow patch? ✅ |
|
Workflow [PR], commit [3d291a2] Summary: ✅
AI ReviewSummaryPR #122144 replaces per-condition copies of column names shaped like Final VerdictStatus: ✅ Approve |
|
CI completed with 1 failure(s) — |
…ditions Every `bloom_filter`, `ngrambf_v1`/`tokenbf_v1`/`sparse_grams` and `text` index condition collected its own set of the table's column and subcolumn names shaped like `<map>.key_<k>`, copying the whole `ColumnsDescription::get` list to do so, although the set is consulted only for predicate column names of that shape. With 128 `bloom_filter` indexes over a table with 1000 such columns the query peaked at 73 MiB instead of 11 MiB. Replace the set with a callback that looks the name up in the metadata snapshot with `ColumnsDescription::tryGetColumn` (columns and regular subcolumns, not dynamic ones), so nothing is collected per condition. Unlike `get`, the lookup also finds subcolumns of `EPHEMERAL` columns, which only refuses more names and stays on the safe side. Rename the proof test to a descriptive name; it passes now. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122144&sha=ff02bb56eaa3d9d6a508ace2e8f1d213cd469add&name_0=PR&name_1=Fast%20test PR: ClickHouse#122144 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 CI confirmed the suspected problem: |
On S3-backed tables, reads emit S3GetObject, DiskS3GetObject, S3ReadRequestsCount and similar events. The old [A-Za-z]+ pattern did not match them, so these lines went to stderr and failed the test under the s3 storage policy. Requested by @clickhouse-gh[bot] in ClickHouse#122144 (comment)
`CREATE TABLE` with 1128 columns and 128 skip indexes took about 100 seconds on the debug build in the flaky check, so the test exceeded the 180 seconds limit. Use 64 indexes and 100 map-key-shaped columns with 4000-character names instead. The old code still peaks at 58 MiB against 7 MiB for the plain names (the test fails), the fixed code peaks equally on both tables. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122144&sha=744757e806f201abe817db433443e06853a1c5a1&name_0=PR PR: ClickHouse#122144 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flaky check still ran the test for more than 400 seconds, also on the release build: each `CREATE TABLE` took about 190 seconds. For every index, `IndexDescription::initExpressionInfo` runs `TreeRewriter`, which copies the whole list of table columns, so 64 indexes over 100 columns with 4000-character names allocated about 2.2 GB per `CREATE TABLE`, and eight parallel copies contended on the `jemalloc` arena locks. Put the long `key_*` / `val_*` names into the elements of a single `Tuple` column instead. Its subcolumns `wide.key_*` are still collected by the old code for every skip index condition (56 MiB against 6 MiB peak on current master), while `CREATE TABLE` only copies one column. The test now takes about a second. Also report an error instead of `OK` when the peak memory cannot be read. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122144&sha=latest&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29 ClickHouse#122144 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pushed a874ca2: merged master and made Other failures are unrelated:
|
…lement names The flaky check still ran the test for about 390 seconds, on the release build too: each `CREATE TABLE` took about 175 seconds of wall time for 18 seconds of CPU. `IndexDescription::initExpressionInfo` runs `TreeRewriter` for every index over all columns and subcolumns and copies every subcolumn name many times (about 2.2 GB in more than a million allocations per `CREATE TABLE`). Under the thread fuzzer, the `jemalloc` arena mutex taken by these allocations is slow, and the samples of `system.trace_log` were in `malloc_mutex_lock_slow` and `DB::injectionImpl`. Use 4 elements with 100000-character names instead of 100 elements with 4000-character names. Each index condition of the old code collects the same number of bytes of names, so the signal is unchanged, but `CREATE TABLE` does about 23 times fewer extra allocations. Eight parallel copies of the test now finish in 3 seconds locally. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122144&sha=latest&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29 ClickHouse#122144 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pushed 6fd3544: merged master and made The other failures are unrelated to this PR, and each already has an open fix:
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units305 translation units recompiled, 3159 s compile time in total, 305 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…ions ClickHouse#122144 replaced the set of column names shadowing Map key subcolumns with the `IsShadowingColumn` callback `is_column_shadowing_map_subcolumn`, so `tryMatchJSONPathValuesNode` no longer compiled after merging `master`. The callback answers for any column or regular subcolumn of the table, while the set held only names shaped like `<map>.key_<k>`. Asking it about every predicate node would refuse typed JSON paths such as `j.a`, so restore `looksLikeMapSubcolumnName` (removed from `master` as unused) and ask the callback only about names of that shape, as `tryParseMapSubcolumnName` does. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114613&sha=e6b2c2eaa9444798c6f6f290531d55938446fd86&name_0=PR&name_1=Fast%20test PR: ClickHouse#114613 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…tion-per-skip-index-condition Master already replaced the per-condition census of names shadowing Map key subcolumns with a lazy `IsShadowingColumn` callback (ClickHouse#122144), which is what this branch did with a `StorageMetadataPtr`. Take master's version of the conflicting files and keep this branch's behaviour for `EPHEMERAL` columns in `IMergeTreeIndex::getMapSubcolumnShadowingCheck`: a subcolumn of an `EPHEMERAL` column is not readable, so it does not refuse the Map key subcolumn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…owing callback Replace the `IsShadowingColumn` callback that came from master (ClickHouse#122144) with this branch's original approach: each `bloom_filter`, `ngrambf_v1`/`tokenbf_v1`/`sparse_grams` and `text` index condition keeps the `StorageMetadataPtr`, and `tryParseMapSubcolumnName` takes the `ColumnsDescription` and looks the name up directly. Remove `IMergeTreeIndex::getMapSubcolumnShadowingCheck`. A subcolumn of an `EPHEMERAL` column is not readable, so it again does not refuse the Map key subcolumn, as tested in `05188_map_subcolumn_shadowed_by_physical_column`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Skip index conditions (
bloom_filter,ngrambf_v1,tokenbf_v1,sparse_grams,text) used to collect their own set of the table's column and subcolumn names shaped like a Map key subcolumn (<map>.key_<k>), copying the wholeColumnsDescription::getlist on every condition. That set is consulted only when a predicate column name has this shape, so the copy was almost always wasted. On wide tables with many such indexes this cost memory and CPU per query (and per partition withuse_constant_folding_in_index_analysis): the added test measured 73 MiB peak vs 11 MiB with 128bloom_filterindexes over 1000attrs.key_*columns.The set is replaced with a callback that looks the name up in the metadata snapshot (
ColumnsDescription::tryGetColumnover columns and regular subcolumns, without dynamic subcolumns) only when needed. The lookup also finds subcolumns ofEPHEMERALcolumns, whichgetomits; that only refuses more names and stays on the safe side.This PR started as a CI proof PR with the test only; CI confirmed the problem (
Fast testfailed with "Peak memory usage: 73 MiB with attrs.key_* names, 11 MiB with attrs.val_* names"), and the fix has been added on top.Related: #119457
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce memory usage and analysis time of filtered queries over wide tables with
bloom_filter,ngrambf_v1,tokenbf_v1,sparse_gramsortextskip indexes: the index condition no longer copies the names of all columns shaped like Map key subcolumns.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122144]
Version info
26.11.1.924-master(included in26.11and later)