Skip to content

Do not prefetch unneeded substreams when reading a whole JSON path from advanced shared data - #113380

Merged
Avogar merged 10 commits into
masterfrom
json-shared-data-skip-subcolumn-substream-prefetch
Aug 13, 2026
Merged

Avogar merged 10 commits into
masterfrom
json-shared-data-skip-subcolumn-substream-prefetch

Conversation

@Avogar

@Avogar Avogar commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Do not prefetch unneeded substreams when reading a whole JSON path from advanced shared data.

Version info

  • Merged into: 26.8.1.1363 (included in 26.8 and later)

…shared data

In the advanced JSON shared-data serialization, reading a whole path needs only the
`Structure`, `PathsMarks` and `Data` substreams. The `Substreams`, `SubstreamsMarks`
and `PathsSubstreamsMetadata` substreams are needed only to read a subcolumn of a path.

`SerializationObjectSharedDataPath::enumerateStreams` always enumerated all of them,
so the prefetch pool issued read requests for substreams that are never read when the
whole path is requested. Enumerate the subcolumn-only substreams only when a subcolumn
is actually requested. This mostly benefits reads from object storage, where every
extra substream is a separate object and adds a request round-trip.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1e5bab]

Summary: ✅


AI Review

Summary

This PR reduces some remote reads for advanced shared-data JSON by dropping unneeded metadata streams for whole-path / sub-object reads and by adding merge_tree_prefetch_json_shared_data_substreams. The SerializationSubObjectSharedData part looks correct, but one mixed-projection path still enumerates the subcolumn-only metadata streams, and the PR still has no targeted evidence for its Performance Improvement claim.

Findings

⚠️ Majors

  • [src/DataTypes/Serializations/SerializationObjectSharedDataPath.cpp:139] [dismissed by author -- https://github.com/Do not prefetch unneeded substreams when reading a whole JSON path from advanced shared data #113380#discussion_r3719228370] SerializationObjectSharedDataPath::enumerateStreams still decides whether to enumerate ObjectSharedDataSubstreams, ObjectSharedDataSubstreamsMarks, and ObjectSharedDataPathsSubstreamsMetadata from the local path_subcolumn shape alone, even though deserializeBinaryBulkStatePrefix on lines 205-217 shares requested_paths / requested_paths_subcolumns across sibling projections and already promotes a whole-path read by erasing the subcolumn entry. In mixed reads such as json.a together with json.a.b, the sibling subcolumn serializer still has a non-empty path_subcolumn, so these extra shared-data metadata streams are still enumerated and prefetched even though the read was already promoted to a whole-path read in memory.
  • [src/Storages/MergeTree/MergeTreeReaderWide.cpp:591] [dismissed by author -- https://github.com/Do not prefetch unneeded substreams when reading a whole JSON path from advanced shared data #113380#discussion_r3752083337] The PR is still labeled Performance Improvement, but the current PR body, diff, and discussion still do not include a targeted before/after measurement for advanced shared-data JSON reads. The public Cloud performance comment from 2026-08-04 explicitly says ClickBench does not execute this code path, so there is still no proof that the change improves latency or remote reads rather than just moving work around.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: make the stream suppression follow the shared requested_paths_subcolumns state after prefix deserialization so mixed whole-path / subcolumn reads stop enumerating the subcolumn-only metadata streams; add a focused benchmark or measurement for advanced shared-data JSON reads and include the before/after numbers in the PR.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.80% +0.10%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.10% +0.10%

Changed lines: Changed C/C++ lines covered: 44/45 (97.78%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR is narrowly scoped: it only skips prefetching of JSON shared-data substreams in Wide parts (a new merge_tree_prefetch_json_shared_data_substreams setting). ClickBench's tables have no JSON columns, so neither flagged query executes the changed code path. Q17's flagged -13.5% improvement is therefore run-to-run variance rather than a real PR effect and has been downgraded, and Q18's -8.1% delta was already correctly suppressed as within master's variance band. No evidence of a genuine performance change from this diff.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 17 not_sure 556 481 -13.5% <0.0001 io: This PR only changes JSON shared-data substream prefetch skipping in Wide parts; ClickBench Q17 reads no JSON columns, so the -13.5% is run-to-run variance, not a PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 7b0517fe-705c-4eb6-8071-7d056afbc999
  • MIRAI run: 3c662740-721e-4cab-b73a-55ca64b32fd3
  • PR check IDs:
    • clickbench_912483_1786546451
    • clickbench_912495_1786546451
    • clickbench_912501_1786546451
    • tpch_adapted_1_official_912525_1786546453
    • tpch_adapted_1_official_912539_1786546452
    • tpch_adapted_1_official_912554_1786546452

…shared data

`SerializationSubObjectSharedData` reads all shared-data paths matching a prefix as
whole paths and extracts the sub-paths in memory (subcolumns of matching paths are
removed from `requested_paths_subcolumns` in `deserializeBinaryBulkStatePrefix`), so
the `Substreams`, `SubstreamsMarks` and `PathsSubstreamsMetadata` substreams are never
read. Stop enumerating them in `enumerateStreams` so the prefetch pool does not issue
read requests for substreams that are never read. Same as the previous change for
`SerializationObjectSharedDataPath`, but here it always holds (there is no subcolumn case).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Avogar and others added 2 commits August 5, 2026 12:04
…to a mark

The `ObjectSharedDataData`, `ObjectSharedDataSubstreams` and `ObjectSharedDataSubstreamsMarks`
substreams are read by seeking to a per-path mark that is only known after the structure and
paths marks are deserialized. `prefetchBeginOfRange` prefetches every enumerated stream from the
beginning of the granule, so for these substreams the prefetch lands at the wrong position and is
always cancelled and re-read at the real mark, wasting a read request (relevant for object storage).

Add `ISerialization::isPrefetchUnneededSubstream` and skip prefetching such substreams in
`MergeTreeReaderWide::prefetchForColumn`. The actual read path is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Keep the JSON shared data details only in the isPrefetchUnneededSubstream implementation;
use general comments in the header and in MergeTreeReaderWide.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Avogar Avogar changed the title Do not read subcolumn substreams when reading a whole JSON path from shared data Do not prefetch unneeded substreams when reading a whole JSON path from advanced shared data Aug 5, 2026
Avogar and others added 3 commits August 6, 2026 14:29
Add `merge_tree_prefetch_json_shared_data_substreams` (default true, current behavior).
When disabled, the JSON shared data substreams that are read by seeking to a mark
(`Data`/`Substreams`/`SubstreamsMarks`) are not prefetched, since prefetching them from
the beginning of the granule reads the wrong position and is wasted. The setting is passed
into `isPrefetchUnneededSubstream` so the whole decision lives in one place.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@kssenii kssenii self-assigned this Aug 10, 2026
Comment on lines +710 to +714
/// These JSON shared data substreams are read by seeking to a specific mark that is known only
/// during deserialization, so prefetching them from the beginning of the granule is wasted.
const auto type = path[prefix_len - 1].type;
return type == Substream::ObjectSharedDataData || type == Substream::ObjectSharedDataSubstreams
|| type == Substream::ObjectSharedDataSubstreamsMarks;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CheSema I think your work should address this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me clarify why this may be needed. Prefetching these substreams can be wasted work. In the advanced JSON shared-data serialization a granule can hold a lot of data (many paths), and reading one path does not start at the granule's beginning: we first read the path's mark from a separate stream, then seek to that position inside the granule and read only that path's data. So a prefetch from the start of the granule may fetch data we never read.

I am not 100% sure it's beneficial, this is why I added iе under a setting, I will test it on Tenable instance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I get this, just Sema is implementing a more clever way of prefetching, not just at the beginning of the mark, so I thought to let him know about this case.

Avogar and others added 2 commits August 11, 2026 12:53
Narrow the skip to `ObjectSharedDataData` (the large stream read by seeking to a per-path
mark); `Substreams`/`SubstreamsMarks` are small per-granule metadata usually covered by the
prefetch buffer, so skipping their prefetch gives no benefit. Rename the predicate to
`isPrefetchNeededForSubstream` (returns whether a substream should be prefetched) for readability.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Avogar
Avogar added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit a37b9c5 Aug 13, 2026
181 checks passed
@Avogar
Avogar deleted the json-shared-data-skip-subcolumn-substream-prefetch branch August 13, 2026 19:27
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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