Skip to content

Packed skip indices: consolidate access and hide internals - #108853

Merged
Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:packed-skip-index-substream-store
Jul 6, 2026
Merged

Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:packed-skip-index-substream-store

Conversation

@Algunenano

@Algunenano Algunenano commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Follow-up refactor to the packed skip indices feature, addressing review feedback that packed-format knowledge had leaked across many MergeTree classes. Pure consolidation, no behaviour change.

Three steps:

  • Read access: the part and the on-disk storage now expose format-agnostic resolvers, so consumers (the cost model, the index reader, per-part secondary-index size accounting) no longer decide whether a substream lives in skp_idx.packed. The archive overlay is resolved once in DataPartStorageOnDiskBase, gated by the cheap skp_idx_ prefix, and is inert on storages without a standalone archive.
  • Write/mutate: deduplicated the "is this index inside the archive?" probing into a single part method, folded the two archive copy loops into one helper, and bundled MergeTreeWriterStream's four packed-archive constructor arguments into one SizeAdaptivePacking value.
  • Confined SizeAdaptiveSpoolBuffer (the size-adaptive write buffer that decides bundle-vs-spill per substream) to MergeTreeWriterStream.cpp, deleting its standalone header/cpp so the type is no longer includable elsewhere.

Related: #105321

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Version info

  • Merged into: 26.7.1.550 (included in 26.7 and later)

Algunenano and others added 3 commits June 29, 2026 20:44
…he part

The skp_idx.packed read overlay lived in the concrete `DataPartStorageOnDiskFull`
and every size/existence consumer open-coded a "checksums entry, else ask the
storage" two-step, so the packed layout leaked into the read step, the cost
model and the index reader.

Move the overlay into `DataPartStorageOnDiskBase`: `existsFile`, `getFileSize`,
`prepareRead` and `readFileIfExists` are now `final` and resolve a `skp_idx_...`
archive member first, then delegate to the new `existsFileImpl` / `getFileSizeImpl`
/ `prepareReadImpl` / `readFileIfExistsImpl` native hooks that each storage
implements. No storage can bypass the overlay, and one that keeps no standalone
`skp_idx.packed` (e.g. packed part storage) simply has no reader, so the `*Impl`
path serves the substreams. A cheap `skp_idx_` prefix gate runs before the
archive is loaded or probed, so unrelated files (`checksums.txt`, `count.txt`,
column and metadata files) never touch the archive.

Give the part two resolving helpers so callers stop deciding where a stream
lives: `getFileSizeOrZeroResolved` (checksums size, else the storage) and
`getStreamNameOrHashResolved` (checksums name, else the storage). The read-step
cost model, `calculateSecondaryIndicesSizesOnDisk`, `hasSecondaryIndex` and the
index reader now go through them instead of open-coding the fallback.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Follow-up to the read-side consolidation. Removes the remaining duplicated
packed-skip-index logic on the write and mutate paths:

- Replace the two identical "is this index inside the source archive?" lambdas
  in MutateTask with one part method `isSkipIndexInPackedArchive`, which
  enumerates the index's substreams and probes the storage. The part is the
  right owner (it already knows about index substreams) and reuses the storage's
  file-name probe, so no index vocabulary leaks into the storage.
- Fold the identical read/write/copy/finalize body of
  `copyPackedSkipIndicesFilesInto` and `filterPackedSkipIndicesArchiveTo` into a
  shared `copyArchiveEntryTo`; each keeps its own iteration source and predicate,
  so the rewritten archive's entry order is unchanged.
- `initSkipIndices` uses the existing `getSkipIndicesPackedWriter()` accessor
  instead of re-inlining the borrowed-or-owned ternary.
- Bundle `MergeTreeWriterStream`'s four trailing packed-archive arguments into a
  single `SizeAdaptivePacking` value (default = no packing), so column and
  text-index streams keep their plain construction.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The size-adaptive spool buffer is an implementation detail of how a skip-index
stream writes its bytes (bundled into skp_idx.packed when small, spilled to a
standalone file when large). It had its own header/cpp, so the type was visible
to anything that included it.

Move the class into an anonymous namespace in MergeTreeWriterStream.cpp, its
only consumer, and delete the standalone files. Reword the comments elsewhere
that named the class to describe the behaviour ("size-adaptive packing")
instead. Also drop the dead "optional, pass nullptr" path on the shared spill
flag: both the data and marks files always pass it, so it becomes a reference.

No behaviour change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Algunenano
Algunenano requested a review from alesapin June 29, 2026 20:36
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c9a9cf9]

Summary: ✅


AI Review

Summary

This PR consolidates packed skip-index read/write/mutation access behind DataPartStorageOnDiskBase and IMergeTreeDataPart, and moves SizeAdaptiveSpoolBuffer into MergeTreeWriterStream.cpp as an internal implementation detail. I reviewed the current diff, the current code in the touched MergeTree paths, and the existing PR discussion state; I did not find a correctness, safety, compatibility, or test-evidence issue that warrants a new review finding on the current PR head.

Missing context / blind spots
  • ⚠️ I did not run the packed skip-index regression tests locally because this checkout does not have an available build directory/artifacts to execute them against.
Final Verdict

✅ No new findings.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 29, 2026
Algunenano and others added 2 commits June 29, 2026 23:42
initSkipIndices runs from the MergeTreeDataPartWriterOnDisk constructor, so
calling the virtual getSkipIndicesPackedWriter there bypasses dispatch
(clang-analyzer-optin.cplusplus.VirtualCall). Read the members directly
instead; the accessor stays for the external polymorphic callers.

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

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.70% 77.60% -0.10%

Changed lines: Changed C/C++ lines covered: 185/203 (91.13%) · Uncovered code

Full report · Diff report

@Algunenano
Algunenano added this pull request to the merge queue Jul 6, 2026
Merged via the queue into ClickHouse:master with commit f09a73c Jul 6, 2026
177 checks passed
@Algunenano
Algunenano deleted the packed-skip-index-substream-store branch July 6, 2026 13:56
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 6, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…x-substream-store

Packed skip indices: consolidate access and hide internals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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.

2 participants