Repository navigation
Size merge/mutation index granularity of JSON shared data by read size - #128157
Conversation
The constant adaptive index granularity of a merged or fully-rewritten mutated part was sized by the uncompressed bytes of the source parts on disk. For a JSON column the dynamic shared data keeps a second on-disk copy of its values (the `ObjectSharedDataCopy*` streams of the `ADVANCED` serialization, used for whole-column reads) in addition to the per-bucket representation. Counting both copies made the per-row byte estimate too large, so the merged part got a smaller granularity and too many marks than the data warrants. Size the granularity by the data a read of the source parts actually decompresses instead. Add `IMergeTreeDataPart::getTotalColumnsReadSize`, which for a Wide part sums the streams a whole-column read touches (using the existing per-stream size hints and de-duplicating shared files), so a second representation of the same data is not counted. Merge and full mutation granularity use it; the default falls back to the on-disk size for other part types. The bytes argument of `createMergeTreeIndexGranularity` is now computed lazily, since reading a part's prefixes to get the read size is only needed on the constant-granularity path. This accounting is shared by typed and dynamic shared data because it works off the reader's actual stream list rather than per-serialization logic. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [4b5dcdb] Summary: ✅
AI ReviewSummaryThe PR sizes constant adaptive granularity for merges and full-rewrite mutations using the streams actually read, avoiding duplicate accounting of Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units294 translation units recompiled, 4029 s compile time in total, 294 of them have a recent master baseline. |
Make the read-size accounting cheaper and bound its memory per the PR review: - Compute the read size per column and cache it per column, and size only a column with dynamic subcolumns through a reader; any other column's read size is its already-cached on-disk size. A reader over a single column holds only that column's prefixes, so a vertical merge's preparation no longer deserializes every column's prefixes (and, for a table with a JSON column, no longer holds all LowCardinality dictionaries) at once. - A sample read (read_only_column_sample) lists streams and their sizes without reading data, so it no longer installs the uniform-marks callback that makes a LowCardinality prefix load the single-part dictionary eagerly. - createMergeTreeIndexGranularity calls the byte callback only on the adaptive path; a non-adaptive part gets the fixed row granularity and no longer reads source prefixes for a size it ignores. - A fully expired TTLDrop merge keeps the cheap on-disk size instead of reading source prefixes for a granularity its empty output will not use. Also cover a full-rewrite mutation in the test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
A `Compact` part records only the total size of its columns; its per-column size map is empty. Summing per-column read sizes therefore gave zero for a `Compact` source, so a merge of `Compact` parts into a `Wide` part with constant adaptive granularity sized its granules by no bytes and wrote one huge granule (2 marks instead of about 500 for 10000 rows of 500-byte strings). Move the per-column read size and its cache into `MergeTreeDataPartWide`, which overrides `calculateTotalColumnsReadSize` with their sum. Other part types keep `getTotalColumnsSize` as their read size. Cover a `Compact`-to-`Wide` merge in the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…size-granularity # Conflicts: # src/Storages/MergeTree/MergeTreeReaderWide.cpp
The test inserted 10000-row parts with ~20 rows per granule, so each part had about 500 granules. The `advanced` shared-data serialization writes a per-granule structure for every granule, and under ASan a single run took up to ~200s and timed out in the flaky check. Shrink the data tenfold (1000-row parts, so about 50 granules) while keeping the same granule-size regime and every pinned setting, so the byte accounting still binds and the mark-count ratios -- which are scale-invariant -- still tell the fixed layout from the buggy one. Flaky check before the change: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128157&sha=fbd00224aaa739c6e2db340bd4a1d6bb2dbf3ec9&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 Co-Authored-By: Claude Opus 4.8 <[email protected]>
When a
JSONcolumn's shared data is written with theADVANCEDserialization, the data part keeps a second on-disk copy of the shared-data values (theObjectSharedDataCopy*streams) for fast whole-column reads, in addition to the per-bucket representation. The constant adaptive index granularity of a merged part (and of a full-rewrite mutation) was sized by the source parts' uncompressed size on disk, which counts both copies. The per-row byte estimate was therefore too large, so the merged part got a smaller granularity and more marks than the data warrants.This sizes the granularity by the data a read of the source parts actually decompresses instead. A new
IMergeTreeDataPart::getTotalColumnsReadSizesums, for a Wide part, the streams a whole-column read touches (reusing the existing per-stream size hints and de-duplicating shared files), so a second representation of the same data is not counted; merges and full mutations use it. The accounting is shared by typed and dynamic shared data because it works off the reader's actual stream list rather than per-serialization logic. The bytes argument ofcreateMergeTreeIndexGranularityis now computed lazily, since reading a part's prefixes for the read size is only needed on the constant-granularity path.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the index granularity of merged parts of a
JSONcolumn being smaller than necessary (too many marks), caused by double-counting the shared data's second on-disk copy when sizing adaptive granularity.Workflow [PR]
Sync PR [sync-upstream/pr/128157]
Version info
26.12.1.8-master(included in26.12and later)