Skip to content

Don't prefetch metadata streams of JSON and Dynamic columns at the current mark - #118479

Merged
alexey-milovidov merged 4 commits into
masterfrom
do-not-prefetch-metadata-streams
Sep 12, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
do-not-prefetch-metadata-streams

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Related: #118475

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. Then 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 (648 of 7053 requests for the query from the issue).

The metadata stream is still prefetched by MergeTreeReaderWide::prefetchBeginOfRange for 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):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Don't read the metadata streams of JSON and Dynamic columns twice when prefetching data from MergeTree parts.


Workflow [PR]
Sync PR [sync-upstream/pr/118479]

Version info

  • Merged into: 26.9.1.1231 (included in 26.9 and later)

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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0b052b5]

Summary: ✅


AI Review

Summary

This PR narrows MergeTreeReaderWide::prefetchForColumn so metadata streams of JSON and Dynamic columns are skipped only when a current-mark prefetch cannot be reused. The follow-up fix preserves the useful prefetchBeginOfRange path for ranges starting at mark 0, the new stateless test covers the redundant reopen case on non-first granules, and I did not find a remaining correctness, compatibility, or test-contract issue in the current patch.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 0b052b5.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 7/8 (87.50%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 6, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0b052b50a with master c5c3c4d5d (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

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
  • StressHouse run: 1734d31c-3a17-4644-8fe8-b35e1688246b
  • MIRAI run: 5d389f55-8b31-4acf-a2b8-87f61209f57b
  • PR check IDs:
    • clickbench_43483_1789142256
    • clickbench_43489_1789142256
    • clickbench_43499_1789142256
    • tpch_adapted_1_official_43506_1789142256
    • tpch_adapted_1_official_43518_1789142256
    • tpch_adapted_1_official_43555_1789142256

@Avogar Avogar self-assigned this Sep 8, 2026
alexey-milovidov and others added 3 commits September 11, 2026 11:05
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]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into master with commit e815ea0 Sep 12, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the do-not-prefetch-metadata-streams branch September 12, 2026 08:42
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants