Repository navigation
Don't prefetch metadata streams of JSON and Dynamic columns at the current mark - #118479
Conversation
The `dynamic_structure` and `object_structure` streams of `Dynamic` and `JSON` columns are read only while deserializing the prefix and are released right after that. `MergeTreeReaderWide::prefetchForColumn` enumerated them again for the current mark, created the stream again and read the file a second time: one extra request per `JSON` path on object storage. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [0b052b5] Summary: ✅
AI ReviewSummaryThis PR narrows Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 0b052b5.
Changed lines: Changed C/C++ lines covered: 7/8 (87.50%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
The skip in `MergeTreeReaderWide::prefetchForColumn` was unconditional, so it also removed the prefetch done by `prefetchBeginOfRange`. For a range that starts at mark `0` that prefetch is the useful one: the prefix is not deserialized yet, and `deserializePrefix` reuses exactly this prefetch instead of erasing it from `prefetched_streams`, so it was the only asynchronous overlap for the first granule of a `JSON` or `Dynamic` column. Skip the metadata stream only when the prefetch cannot be reused: after the prefix of this column has been deserialized (the stream is released by then and would be created again), or for a range that does not start at mark `0` (the prefix always reads from the beginning of the file, so a prefetch at the current mark is at the wrong offset anyway). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…fetch The previous check compared `FileOpen` against `MarkCacheMisses` plus the number of substreams, which is only a rough bound and did not hold in CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118479&sha=4213123082adde4cc42f100f552bde50b7ecb8dc&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 #118479 Read the same granule twice, with and without `local_filesystem_read_prefetch`, and require that the prefetching read does not open more files. The mark cache is cleared before every run, and a warm-up read is done first, so both runs open the same files except for the streams prefetched at the current mark. Verified with a control binary without the fix: the test fails there (74 versus 68 opened files) and passes with the fix (68 versus 68). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Related: #118475
The
dynamic_structureandobject_structurestreams ofDynamicandJSONcolumns are read only while deserializing the prefix and are released right after that. ThenMergeTreeReaderWide::prefetchForColumnenumerated them again for the current mark, created the stream again and read the file a second time: one extra request perJSONpath on object storage (648 of 7053 requests for the query from the issue).The metadata stream is still prefetched by
MergeTreeReaderWide::prefetchBeginOfRangefor a range that starts at mark 0, where the prefix deserialization reuses exactly this prefetch.The test reads the same granule (not the first one) with and without prefetch and checks that the prefetching read does not open more files.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Don't read the metadata streams of
JSONandDynamiccolumns twice when prefetching data fromMergeTreeparts.Workflow [PR]
Sync PR [sync-upstream/pr/118479]
Version info
26.9.1.1231(included in26.9and later)