Skip to content

Compress each substream in a separate block in Compact parts - #118162

Merged
Avogar merged 15 commits into
masterfrom
compress-per-substream-in-compact-parts
Nov 24, 2026
Merged

Avogar merged 15 commits into
masterfrom
compress-per-substream-in-compact-parts

Conversation

@Avogar

@Avogar Avogar commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

In Compact parts a column's substreams are packed into the same compressed block; only whole columns are separated into blocks (via compress_per_column_in_compact_parts). Reading a single subcolumn — an Array size, a Tuple element, a JSON path, etc. — therefore had to decompress the whole column's block, including unrelated substreams.

This adds a MergeTree setting compress_per_substream_in_compact_parts (enabled by default) that starts a new compressed block at a column substream boundary once the current block reached min_compress_block_size, so a selective subcolumn read decompresses only that substream while small substreams keep sharing a block. It applies when per-substream marks are written (write_marks_for_substreams_in_compact_parts) and per-column blocks are enabled (compress_per_column_in_compact_parts) — a table that pinned the latter to 0 keeps one block per granule for all streams sharing a codec. A per-column min_compress_block_size override is honoured, matching what the Wide part writer and the JSON shared data serialization already do. The setting respects compatibility: with an older pinned compatibility version parts keep the previous packed layout.

The change is write-time only and format-compatible — it just moves compression-block boundaries, so old and new servers read each other's parts.

Reading one subcolumn of a Compact part, decompressed bytes before → after: Tuple element 2.19 MiB → 0.13 MiB; Array size 2.00 MiB → 0.13 MiB. In the CI performance comparison select t.small from compress_per_substream_compact is 2.35x faster on amd64 and 2.21x faster on aarch64, and the existing json_shared_data_compact read is 1.69x faster.

Changelog category (leave one):

  • Performance Improvement

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

Compact parts can now start a new compressed block at column substream boundaries once the current block reaches min_compress_block_size, controlled by the new setting compress_per_substream_in_compact_parts (enabled by default). Reading a single subcolumn (an Array size, a Tuple element, a JSON path, etc.) decompresses only that substream instead of the whole column's block, while small substreams stay packed together.


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

Version info

  • Merged into: 26.12.1.433-master (included in 26.12 and later)

Add MergeTree setting compress_per_substream_in_compact_parts (default true).
Like compress_per_column_in_compact_parts but at substream granularity: each
column substream in a granule starts a new compressed block, so reading a
single subcolumn (an Array size, a Tuple element, a JSON path, ...) decompresses
only that substream instead of the whole column's block. Applied only when
per-substream marks are written (write_marks_for_substreams_in_compact_parts).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8fdac81]

Summary: ✅


AI Review

Summary

The PR adds compress_per_substream_in_compact_parts to split Compact-part compression blocks at substream boundaries after reaching the effective min_compress_block_size. Reviewed head 8fdac81154fe6b63a09b15d5cb4521c9e68ab1d4; no unresolved findings. The previous finding about preserving compress_per_column_in_compact_parts = 0 is addressed and its thread remains resolved.

Consumers traced: MergeTreeReaderCompactSingleBuffer reads full columns across compression blocks; MergeTreeReaderCompact seeks subcolumn prefixes and data using substream marks; MergeTreeReaderStream uses compressed/decompressed mark offsets for seeks and read bounds. JSON shared-data serializers obtain their internal marks after acquiring streams. Insert, merge, and mutation writers receive the setting through MergeTreeWriterSettings; checkDataPart checks the Compact data file's compressed checksum.

The focused stateless test passed at the reviewed head in Fast test. Earlier performance artifacts at d5ec3bdd4621f86d32d49fb1df2909d3d7f4b9ef support the benefit: the tuple subcolumn query improved from 19.8 to 8.7 ms on amd64 and from 14.9 to 6.9 ms on aarch64.

Missing context / blind spots
  • ⚠️ Broader functional, sanitizer, and performance jobs for the reviewed head were still pending. Their completed CI reports will close this validation gap. No local tests were run in this review job.
Final Verdict

Status: ✅ Approve

Avogar and others added 4 commits September 16, 2026 17:46
Cutting a new compressed block at every substream boundary of a Compact part
granule fragments columns with many small substreams, which costs compression
ratio and read requests. Cut only once the current block reached
min_compress_block_size, matching the Wide writer and the Object shared data
serialization; an explicit min_compress_block_size = 0 still cuts at every
boundary.

Also record the setting in the current version block of the settings changes
history: it was recorded in 26.4, but 26.4 through 26.9 are released and never
had the setting, so a server with compatibility pinned to one of them would get
the new default.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Use `getEffectiveMinCompressBlockSize` for the substream block cut, so a column
that overrides `min_compress_block_size` gets the same treatment as in Wide
parts, and record the setting in the 26.10 block: master moved to 26.10.1, which
makes the 26.9 block a released version that never had this setting.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`index_granularity_bytes = 0` disables adaptive granularity, and non-adaptive
granularity is only supported in Wide parts, so `min_bytes_for_wide_part` was
ignored and every measurement compared two Wide parts. Keep the row-based
granularity by raising the byte limit instead.

Also replace the part size assertion: on a column of many one-byte substreams
the adaptive layout costs ~26% over packing a whole granule into one block, so
assert that it stays near the packed size while cutting at every boundary costs
more than twice as much.

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

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8fdac8115 with master ba1cd6eb7 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4123da939; 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

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

Job report

alexey-milovidov and others added 4 commits September 26, 2026 02:51
…eam-in-compact-parts

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s is off

`compress_per_column_in_compact_parts = 0` keeps all streams sharing a codec in
one compressed block per granule, so cutting at substream boundaries broke that
contract for tables that had pinned the setting. It also let the cut at a column
boundary be decided by the next column's `min_compress_block_size`, because the
stream is carried over when per-column blocks are disabled.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The part size checks compare compressed layouts, and the randomized codec,
serialization versions and part storage type move the baseline more than the
layout does: in CI the same measurement ranged from 933 to 3563 bytes while the
extra layout cost stayed constant, so the ratio bound could not hold.

Also cover the `compress_per_column_in_compact_parts = 0` opt-out, which must
decompress the same bytes whether or not per-substream blocks are enabled.

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

clickhouse-gh Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

I marked all four flagged improvements as not sure (ClickBench Q33 -7.1% and Q34 -9.5%, TPC-H Q1 -18.5% and Q7 -23.5%). This PR only changes how Compact parts are written: a column's substream (Tuple element, Array sizes, JSON path) starts a new compressed block once the current block reaches min_compress_block_size. These benchmarks read plain-typed columns from large Wide parts, so the new code never runs for them. All four queries have noisy master history, and three PR runs shared one node, so the shifts are best read as environment variance; subcolumn-read gains should be judged by the PR's new dedicated perf test instead.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 33 not_sure 1134 1053 -7.1% <0.0001 aggregation: This is a large GROUP BY over plain columns in Wide parts, and the change only alters Compact-part writes for columns with substreams. The -7.1% on a query with noisy history cannot come from this diff.
⚠️ 34 not_sure 1140 1032 -9.5% <0.0001 aggregation: Like Q33, this is a heavy aggregation over plain columns in Wide parts that never reaches the changed Compact writer branch. The -9.5% is variance, and this query's history is noisy.

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

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 65 53 -18.5% <0.0001 aggregation: This scans and aggregates lineitem, which is stored in Wide parts with plain columns. The new substream block cut does not apply, so the -18.5% (12 ms on a fast, noisy query) is not a PR effect.
⚠️ 7 not_sure 81 62 -23.5% <0.0001 join_operator: This is a multi-table join over plain-typed columns. Only the tiny dimension tables are Compact, and they never reach the 64 KiB block threshold the new cut needs, so the -23.5% (19 ms) cannot be attributed to this PR.

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.

Debug info
  • StressHouse run: 0d479500-26e3-40b1-a395-fbf8158be407
  • MIRAI run: 7bad0480-d500-4789-a871-ecd2b3e1ffc7
  • PR check IDs:
    • clickbench_1075252_1791820564
    • clickbench_1075258_1791820564
    • clickbench_1075264_1791820564
    • tpch_adapted_1_official_1075274_1791820564
    • tpch_adapted_1_official_1075286_1791820564
    • tpch_adapted_1_official_1075323_1791820564

@Avogar

Avogar commented Nov 2, 2026

Copy link
Copy Markdown
Member Author
Screenshot 2026-11-02 at 14 50 55 Screenshot 2026-11-02 at 14 51 10 Screenshot 2026-11-02 at 14 51 22

@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 19, 2026
Avogar and others added 4 commits November 24, 2026 12:22
The test has a JSON column (and forces Compact MergeTree parts to measure
subcolumn reads), so the Iceberg performance configuration cannot run it, like
the existing compact_part_subcolumns.xml entry.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ClickHouse/ClickHouse into compress-per-substream-in-compact-parts
Master advanced to 26.12 after the merge; the settings-history record must be
under the current development version.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@nihalzp nihalzp self-assigned this Nov 24, 2026
@Avogar
Avogar added this pull request to the merge queue Nov 24, 2026
Merged via the queue into master with commit c6058ac Nov 24, 2026
194 checks passed
@Avogar
Avogar deleted the compress-per-substream-in-compact-parts branch November 24, 2026 19:45
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 24, 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.

4 participants