Repository navigation
Do not prefetch unneeded substreams when reading a whole JSON path from advanced shared data - #113380
Conversation
…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]>
|
Workflow [PR], commit [e1e5bab] Summary: ✅
AI ReviewSummaryThis PR reduces some remote reads for advanced shared-data Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 44/45 (97.78%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: 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. clickbenchFlagged queries (1 of 43)
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
|
…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]>
…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]>
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]>
| /// 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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]>
Changelog category (leave one):
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
26.8.1.1363(included in26.8and later)