Skip to content

Switch the default compression to ZSTD(3) for table data and network - #108786

Merged
alexey-milovidov merged 161 commits into
masterfrom
default-compression-zstd
Sep 5, 2026
Merged

alexey-milovidov merged 161 commits into
masterfrom
default-compression-zstd

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Switch the default compression in ClickHouse from LZ4 to ZSTD(3), for both on-disk table data and network communication.

Motivation

LZ4 has been the default for a long time and optimizes for speed, but ZSTD(3) gives substantially better compression ratios at a still-modest CPU cost, reducing both storage footprint and network traffic out of the box. ClickHouse Cloud already uses a stronger default; this aligns the self-managed defaults.

What changes

  • On-disk table data. CompressionCodecFactory::getDefaultCodec now returns ZSTD(3) instead of LZ4. For MergeTree column data the built-in default is size-aware: when a column specifies no codec and no <compression> server-config case matches, CompressionCodecSelector::choose uses the faster LZ4 below 100 MB and ZSTD(3) at or above it, so freshly inserted data starts as LZ4 and the bigger parts produced by background merges switch to ZSTD(3). The threshold is applied to the part size known when the codec has to be chosen, before the data is written - 0 for a freshly inserted part and the source parts' size for a merge or a mutation - which is the same estimate the <compression> min_part_size conditions have always been matched against, not the size of the resulting part. A rewrite that shrinks its input, such as a TTL DELETE or a collapsing merge, is therefore classified by the input size and can emit a part below the threshold that is still ZSTD(3). The direct getDefaultCodec users — the Log family, part checksums, the HTTP compress=1 output, the StripeLog data stream, and the persistent Set/Join files — are not size-aware and switch uniformly from LZ4 to ZSTD(3). External temporary (spill) files are unaffected: they keep their own temporary_files_codec default (LZ4).
  • Network. The defaults of network_compression_method (LZ4 → ZSTD) and network_zstd_compression_level (1 → 3) are changed, so the native client/server and Distributed (server/server) protocol uses ZSTD(3) by default. The changes are recorded in SettingsChangesHistory.cpp so the compatibility setting restores the previous behavior for these paths. The distributed-query streaming exchange (StreamingExchangeSink) does not read network_compression_method and always uses the server default codec; this is safe because each frame is self-describing (the receiver auto-detects the codec) and the exchange is a transient, same-version channel — StreamingExchangeProtocol rejects peers on a different protocol version, so a stream is never read back by a node expecting a different codec.
  • Upgrade safety. The append-only Log/TinyLog/StripeLog engines resolve the default codec at write time, so a table written before the upgrade (LZ4) and appended to after it (ZSTD(3)) ends up with mixed-codec blocks in one file. Their readers now pass allow_different_codecs = true (as the MergeTree reader already does) so such files still read back correctly. The legacy custom-frame Keeper snapshot format (compress_snapshots_with_zstd_format = false) is pinned to LZ4 so it stays the documented format.
  • Interserver settings copies. The three senders that build the settings for a secondary query (MultiplexedConnections, HedgedConnections, RemoteInserter) now demote the compatibility-derived network settings to unchanged, so the shard re-derives them from the serialized compatibility setting instead of receiving them as explicit changes. Sending them explicitly is not an error - TCPHandler clamps a secondary query's setting violations rather than throwing - but it subjects them to the shard's own settings constraints, which drop a CONST pinned value and clamp a range-pinned one, so the shard would silently run under a codec other than the one the initiator's compatibility selects. The preamble the three senders share now lives in prepareSecondaryQuerySettings and is pinned directly by gtest_secondary_query_settings. Fixing that surfaced a pre-existing bug in the same copies: the two SELECT senders set the dialect = 'clickhouse' override that lets a shard read the ClickHouse-SQL the initiator rewrote for it, but then cleared the changed flag, so Connection::sendQuery - which serializes only changed settings - dropped it; RemoteInserter had no such override at all. A shard whose own user or profile defaults to a foreign dialect therefore re-parsed the rewritten query with the wrong parser. The override is now serialized on all three paths.

Columns, tables, and connections that specify a codec or method explicitly are unaffected — with one exception: streams written through the built-in default codec directly, which ignore per-column codecs and the <compression> config. The StripeLog data stream, the persistent Set/Join backup files (written by SetOrJoinSink and StorageJoin::mutate through a CompressedWriteBuffer with no codec), and MergeTree auxiliary streams such as part checksums (checksums.txt, via MergeTreeDataPartChecksums::write) always follow the new default; see the changelog entry below for the per-path rollback.

Validation

Built locally and verified against the new binary:

  • A MergeTree table created with no explicit codec follows the size-aware default: small parts report LZ4 and parts whose write-time size estimate reaches 100 MB report ZSTD(3) as their default_compression_codec in system.parts. Direct getDefaultCodec streams (e.g. StripeLog) report ZSTD(3) regardless of size.
  • system.settings shows network_compression_method = ZSTD and network_zstd_compression_level = 3.
  • End-to-end SELECT/INSERT over the native protocol with default (now ZSTD) network compression work; all of LZ4/lz4hc/zstd/none still work and an invalid method still errors with BAD_ARGUMENTS.
  • The 02995_new_settings_history consistency check passes (both setting changes are recorded).
  • The client-side and sender-side settings contracts are pinned by unit tests: gtest_network_compression_settings for the client's own helper queries and gtest_secondary_query_settings for the interserver senders. The end-to-end shell test 04758_distributed_compatibility_readonly_constrained_setting cannot prove the sender-side demotion on its own, because a shard clamps a secondary query's setting violations instead of rejecting the query; its comment now says so.
  • The on-disk byte-dump tests (02047_log_family_*_data_file_dumps) were regenerated for the new default: Log/TinyLog keep LZ4-pinned columns, while StripeLog's shared data.bin/index.mrk reflect the ZSTD(3) default (it uses getDefaultCodec and ignores the per-column codec). Size-sensitive stateless and integration tests that assert compressed byte sizes were pinned back to LZ4 (cache segment sizes, distributed-batch corruption offsets, full-disk thresholds, frozen-part checksums).

The CI performance comparison does not measure this tradeoff: the harness pins the built-in default codec
to LZ4 (tests/performance/scripts/config/config.d/compression.xml) and network_compression_method to LZ4
(tests/performance/scripts/config/users.d/perf-comparison-tweaks-users.xml) on both the reference and the
tested server, deliberately, so the report measures query logic rather than drowning in expected codec
regressions. It therefore serves only as a regression filter for the non-codec parts of this change; the
storage/network-vs-CPU tradeoff of LZ4 → ZSTD(3) itself is a well-known property of the two codecs and is
not measured by this pull request's CI.

Documentation updated accordingly, including the Native format and protocol specifications and the <compression> config examples.

Changelog category (leave one):

  • Backward Incompatible Change

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

The default compression method is changed from LZ4 to ZSTD(3). For client/server and server/server network communication it switches uniformly to ZSTD(3). For on-disk table data, MergeTree column data now uses a size-aware built-in default — LZ4 below 100 MB and ZSTD(3) at or above it, applied to the part size known at write time (the source parts' size for a merge or a mutation) rather than to the size of the resulting part — while the direct built-in-default streams (the StripeLog data stream, the persistent Set/Join files, the HTTP compress=1 framed output, and part checksums) switch uniformly from LZ4 to ZSTD(3). This improves compression ratios and reduces storage and network usage out of the box, at a modest increase in CPU usage. None of the on-disk or HTTP paths are controlled by compatibility; the previous behavior can be restored per path as follows. For client/server and Distributed network compression, use the compatibility setting (or set network_compression_method = 'LZ4'). For MergeTree column data, set a column/table CODEC(LZ4) or configure the server <compression> default to LZ4; the same part default also covers the MergeTree auxiliary files that follow it rather than the per-column codec, such as text-index files. For the Log/TinyLog engines, set a column CODEC(LZ4) (their default does not consult the <compression> config). The StripeLog data stream, the persistent Set/Join backup files, the HTTP compress=1 framed output, and MergeTree auxiliary streams such as part checksums (checksums.txt) use the built-in default codec directly — they ignore per-column codecs and the <compression> config — so they always use the new ZSTD(3) default and have no runtime rollback; reading stays correct because every compressed frame is self-describing.


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

Version info

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

Change the built-in default compression codec from `LZ4` to `ZSTD(3)`,
for both on-disk table data and client/server and server/server network
communication.

On-disk: `CompressionCodecFactory::getDefaultCodec` now returns `ZSTD(3)`.
This is the codec applied to columns that do not specify a codec and when
no matching `<compression>` config case is present. It flows through the
`MergeTree` write path, the `Log` family, temporary data, and the HTTP
`compress=1` output.

Network: the defaults of `network_compression_method` (`LZ4` -> `ZSTD`)
and `network_zstd_compression_level` (`1` -> `3`) are changed so that the
native protocol uses `ZSTD(3)` by default. The changes are recorded in
`SettingsChangesHistory.cpp` for the `compatibility` setting.

Docs updated accordingly, including the `Native` format and protocol
specifications and the server `compression` settings.

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

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8b9018b]

Summary: ✅


AI Review

Summary

This PR switches the built-in default compression from LZ4 to ZSTD(3) for native network traffic and most default-coded on-disk paths, adds the size-aware MergeTree fallback, and carries a long tail of follow-up fixes for compatibility-derived settings, helper-query dialect handling, mixed-codec reads, and approximate part-codec provenance. The remaining issue is test coverage: the new warnings-probe regression still does not prove that the profile-default foreign dialect branch is actually active, so that half can pass vacuously.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/05045_client_warnings_probe_with_session_dialect.expect:50] The second half of this test creates a user/profile with dialect = 'kusto' and then checks that warnings still print, but it never proves that the profile is actually in effect. If the login/profile wiring regresses and the session falls back to the default clickhouse dialect, this case still stays green and no longer tests the unconditional dialect = 'clickhouse' override in Client::loadWarningMessages. Add a positive control before the warnings assertion, e.g. run SELECT 1 as $user and require SYNTAX_ERROR, the same way 04658_client_helper_queries_ignore_session_dialect proves its profile-backed half.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: add a positive control to 05045_client_warnings_probe_with_session_dialect.expect so the profile-default dialect = 'kusto' scenario cannot pass vacuously.

LLVM Coverage Report

⚠️ No coverage measurement for commit 8b9018b: incomplete coverage measurement: 1 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_it_7.profdata.

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Jun 29, 2026
Comment thread src/Compression/CompressionFactory.cpp Resolved
Comment thread programs/server/config.xml Resolved
After switching the default compression codec from `LZ4` to `ZSTD(3)`,
several stateless tests that implicitly relied on the `LZ4` default
started producing different output. Pin `LZ4` explicitly where the test
output depends on the codec, so the references stay stable regardless of
the server default:

- `04267_estimate_compression_ratio_window_accumulation` and
  `03363_estimate_compression_bug91415`: pass `'LZ4'` as the codec
  parameter of `estimateCompressionRatio`.
- `03634_autopr_input_bytes_estimation_compact`: set the `MergeTree`
  setting `default_compression_codec='LZ4'` so `ReadCompressedBytes`
  matches the statistics-based estimate.
- `02346_text_index_posting_list_compression_data_size_validation`: set
  `default_compression_codec='LZ4'` so the text index file compression
  (which uses the part default codec) is pinned.
- `01943_log_column_sizes`: add `CODEC(LZ4)` to the `Log`/`TinyLog`
  columns (the `Log` family has no `MergeTree` settings).

`02967_http_compressed` cannot pin the codec: the HTTP `compress=1`
output uses `CompressionCodecFactory::getDefaultCodec` directly with no
per-query override. Its reference is updated to the new `ZSTD(3)` output
(verified to match the bytes produced by `clickhouse compressor` with
`ZSTD(3)`, which are identical to the CI result).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Compression/CompressionFactory.cpp Resolved
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Compression/CompressionFactory.cpp Resolved
alexey-milovidov and others added 5 commits June 29, 2026 04:28
Follow-up to the previous commit, after determining empirically how each
code path selects its codec:

- `03634_autopr_input_bytes_estimation_compact`: the compact-part input-bytes
  estimate serializes a sample with `getDefaultCodec` (now `ZSTD(3)`), so the
  actually-read compressed bytes must use the same codec to stay within the
  test's 2x tolerance. Pin `default_compression_codec='ZSTD(3)'` instead of
  `LZ4` (the previous commit pinned `LZ4`, which left the estimate and the
  reads mismatched).
- `02346_text_index_posting_list_compression_data_size_validation`: the text
  index files are compressed with `getDefaultCodec` directly, which is not
  controlled by a column codec or the `default_compression_codec` setting.
  Drop the ineffective setting and update the reference to the `ZSTD(3)` sizes.
- `03595_funcs_on_zero` (`no-fasttest`): pass `'LZ4'` to `estimateCompressionRatio`.
- `00753_system_columns_and_system_tables_long` (`long`): add `CODEC(LZ4)` to the
  `TinyLog`/`Log` columns whose `total_bytes` depend on the default codec
  (`StripeLog` and `Memory` are codec-independent here; the `MergeTree` table is
  already pinned to `LZ4` by the test harness for `no-random-*` tests).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The msan flaky check confirmed the `TinyLog`/`Log` `CODEC(LZ4)` pins work
(`total_bytes` = 27/43), but `StripeLog` reports `135` instead of `113`.
Unlike `TinyLog`/`Log`, `StripeLog` compresses its combined data stream with
`getDefaultCodec` (now `ZSTD(3)`) regardless of the column codec, so its size
cannot be pinned via SQL — update the expected `total_bytes` to the `ZSTD(3)`
value. The value is stable: it depends only on the default codec, not on the
randomized query settings (`min`/`max_compress_block_size`, etc.).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
With `ZSTD(3)` as the default codec, the autopr input-bytes estimate (which
serializes a few sampled blocks via `getDefaultCodec`) lands at up to ~2x the
actual full-column compressed size for highly-compressible columns: `ZSTD(3)`
compresses the full column better than the small sample predicts, and the
sampled-block set varies with thread scheduling, so the previous 2x tolerance
flaked right at the boundary (`query_2`: 808201 vs 1617909 = 2.002x). Widen the
tolerance to 4x, which still catches gross misestimation. The table stays pinned
to `ZSTD(3)` so the estimate and the reads use the same codec.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
estimateCompressionRatio('') uses the default codec; pass 'LZ4' explicitly so
the ratio does not depend on the server default. (no-fasttest test, skipped by
Fast test, surfaced in the full parallel stateless run.)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`test_jbod_overflow` inserts random printable ASCII into a small (40MB) jbod
disk and asserts the data overflows to the `external` disk. `randomPrintableASCII`
data is entropy-light (95-symbol alphabet): `ZSTD(3)` (the new default codec)
entropy-codes it ~18% smaller than `LZ4`, so the parts now fit in the jbod and
no longer overflow, failing `assert ... == 'external'`. Pin the column to
`CODEC(LZ4)` so the on-disk part size is independent of the server default codec.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Compression/CompressionFactory.cpp Resolved
alexey-milovidov and others added 5 commits June 29, 2026 09:09
`03634_autopr_output_bytes_estimation` compares the autopr output-bytes estimate
against hardcoded `expected_bytes` with a 2.5x tolerance. The estimate serializes
the output (aggregation state) with `getDefaultCodec`; under the new `ZSTD(3)`
default, query_12's output compresses to ~3.6M instead of the ~11.2M seen under
`LZ4`, exceeding the 2.5x bound. Update query_12's expected value to 3620000.
Across three CI runs the estimate was stable (3609402/3622834/3629968), and it is
the only query whose LZ4-calibrated expectation falls outside 2.5x of the ZSTD
estimate; the others remain within tolerance.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
test_recompression_ttl asserts the pre-recompression part reports
`default_compression_codec == 'LZ4'`. With the default codec switched to
`ZSTD(3)` the initial part now reports `ZSTD(3)`, failing the assertion (same
situation as the stateless `01465_ttl_recompression`). Pin
`default_compression_codec = 'LZ4'` on all three tables so the initial parts
stay `LZ4`; the `RECOMPRESS CODEC(ZSTD(...))` codecs are unaffected (recompression
wins over the setting).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ault

`test_backward_compatibility::test_aggregate_states` compares the serialized
state of every aggregate function between an old and a new server. The old
server defaults to `LZ4` and the new one to `ZSTD(3)`; `estimateCompressionRatio`
is the only aggregate whose state encodes the argument compressed with the
server's default codec, so its state (and final ratio) legitimately differs
across the change and the cross-version comparison is meaningless. Skip it,
matching how the test already skips functions it cannot meaningfully compare.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`04100_autopr_input_bytes_estimation_aggregation_in_order` checks the autopr
input/output byte estimates. Both use `getDefaultCodec`, now `ZSTD(3)`:
- Pin `default_compression_codec='ZSTD(3)'` so the read bytes match the input
  estimate (the `no-random-*` harness would otherwise inject `LZ4`).
- The output estimate serializes the aggregation output with `getDefaultCodec`;
  under `ZSTD(3)` the two `max_threads=1` queries (`agg_in_order_single`,
  `agg_in_order_multi_agg`) compress ~5x smaller (4781834 / 6889765) than the
  original `LZ4`-era expectations (25519057 / 33649632), exceeding the 2x bound.
  Recalibrate those two expected values; the `max_threads=4` queries stay within
  tolerance.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The flaky check showed `04100`'s autopr output-bytes estimate swings several-fold
between runs under `ZSTD(3)` (e.g. agg_in_order_single 4.78M..20.4M, multi_agg
6.89M..45.2M) because the estimate serializes the aggregation output with the
default codec and is very sensitive to randomized block-sizing query settings -
a sensitivity that did not surface under the previous `LZ4` default (04100 is
green on master). Add `no-random-settings` (the test already used
`no-random-merge-tree-settings` "to stabilize the test") so the query settings
are fixed and the estimate is deterministic. The expected output values may need
a follow-up recalibration to the deterministic `ZSTD(3)` values.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Compression/CompressionFactory.cpp Resolved
alexey-milovidov and others added 2 commits June 29, 2026 16:31
With `no-random-settings` now fixing the query settings, `04100`'s autopr output
estimates are deterministic under `ZSTD(3)`: agg_in_order_single=20406542 and
agg_in_order_multi_agg=45288700 (identical across all flaky-check reruns). These
are within 2x of the original `LZ4`-era expectations (25519057 / 33649632 — ratios
1.25x / 1.35x), so the original values hold. The earlier recalibration to
4781834 / 6889765 was based on an outlier randomized-settings run and is reverted.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Compression/CompressionFactory.cpp Resolved
alexey-milovidov and others added 4 commits June 29, 2026 21:58
The `Log`, `TinyLog`, and `StripeLog` engines write each insert with the
current default codec and append it to the same compressed stream. Their
columns store no per-stream codec on disk, and the codec is resolved fresh at
write time from `CompressionCodecFactory::getDefaultCodec`. Switching that
default from `LZ4` to `ZSTD(3)` therefore makes an upgraded table append
`ZSTD(3)` blocks after the existing `LZ4` blocks in one `.bin`/`index` file.

The readers constructed their `CompressedReadBuffer`/`CompressedReadBufferFromFile`
with `allow_different_codecs = false`, and `CompressedReadBufferBase` throws
`CANNOT_DECOMPRESS` when the method byte changes within a single stream. So a
post-upgrade `SELECT` (or `StripeLog` index load / restore) over a range that
spans the append boundary would fail to read existing data.

Each compressed block is self-describing (its codec method byte is in the
header), so a mixed-codec append-only stream is valid. Set
`allow_different_codecs = true` on the Log-family read paths, exactly as the
`MergeTree` reader already does. A new gtest
`gtest_mixed_codec_append` writes an `LZ4` block followed by a `ZSTD(3)` block
and asserts both buffer types the Log family uses read it back with the
tolerance on, and still throw `CANNOT_DECOMPRESS` with it off.

A SQL-level upgrade test is not possible in a single server: the Log family
has no per-query or `ALTER MODIFY ... CODEC` override, so a mixed-codec file
can only arise from a cross-version change of the global default codec.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`KeeperSnapshotManager` writes snapshots with a no-argument `CompressedWriteBuffer`
when `compress_snapshots_with_zstd_format` is `false`. That setting is documented
as "Write compressed snapshots in ZSTD format (instead of custom LZ4)", i.e. the
`false` branch is the legacy custom-frame `LZ4` format. With the default codec
now `ZSTD(3)`, that branch would silently start emitting `ZSTD(3)`-framed
snapshots while still being presented as the legacy `LZ4` format.

Old snapshots remain readable either way (the custom-frame reader auto-detects
the codec from each frame's method byte), so this is not a correctness bug, but
pinning `LZ4` keeps the documented legacy format literally true and independent
of the server's default codec.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After switching the default codec to `ZSTD(3)`, more tests whose output depends
on the on-disk/network byte volume need the codec pinned so they do not depend
on the server default:

- `02047_log_family_data_file_dumps` and
  `02047_log_family_complex_structs_data_file_dumps`: these dump the exact bytes
  of the `Log`/`TinyLog`/`StripeLog` `.bin` files. Pin the columns to
  `CODEC(LZ4)` so the references keep validating the on-disk layout regardless
  of the default codec (explicit `CODEC(LZ4)` produces byte-identical output to
  the previous implicit `LZ4` default).
- `test_replicated_fetches_bandwidth`: the throttling assertions depend on the
  size of the fetched parts. `randomPrintableASCII` produces random printable
  ASCII, which `ZSTD` entropy-codes noticeably better than `LZ4`, shrinking the
  parts enough to change fetch timing. Pin the `data` column to `CODEC(LZ4)` in
  all of these tests, matching the existing fix in `test_jbod_overflow`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The sample `<compression>` block recommended uncommenting it "for better
compression", but its case used `<method>zstd</method>` with no level, i.e.
`ZSTD(1)`, which is weaker than the new `ZSTD(3)` default. Enabling it would
have reduced compression for matching (large) parts.

Give the example an explicit `<level>` above the default so the case genuinely
improves compression for large parts, and reword the surrounding comment.

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

Copy link
Copy Markdown
Member Author

Addressed the AI review (the Block verdict's required actions) and the two real CI failures. Pushed 3760d22dd06..2b5e1c427ac.

Log-family mixed-codec upgrade path (the blocker). Log/TinyLog/StripeLog resolve the default codec at write time and append into one stream, so an upgraded table mixes pre-upgrade LZ4 blocks with post-upgrade ZSTD(3) blocks in a single file; the readers used allow_different_codecs = false and threw CANNOT_DECOMPRESS. Each block is self-describing, so the fix is to set allow_different_codecs = true on the Log-family readers (data file, StripeLog index load, restore-from-backup index) - exactly what the MergeTree reader already does. Added gtest gtest_mixed_codec_append covering both buffer types with an LZ4→ZSTD(3) stream (reads with tolerance on; still throws with it off).

Global-default consumers, settled.

  • Keeper: the legacy custom-frame snapshot path (compress_snapshots_with_zstd_format = false) is now pinned to LZ4, keeping its documented format.
  • Streaming exchange and external temporary (spill) files: verified safe - the exchange reader auto-detects the per-frame codec and is transient/version-handshaked; spill files keep their own temporary_files_codec default (LZ4) and never go through getDefaultCodec. No change required.

Docs / user-facing. Narrowed the rollback guidance (PR body + changelog): compatibility restores only the network defaults, not table-data/HTTP framed output. Removed the incorrect "temporary data" claim. Updated the config.xml <compression> example to an explicit level above the ZSTD(3) default.

CI reds. 02047_log_family_*_data_file_dumps and all throttling tests in test_replicated_fetches_bandwidth are pinned to CODEC(LZ4) (random-ASCII parts shrink under ZSTD, which perturbed the byte dumps and the fetch-throttling timing).

Left open for you, @alexey-milovidov: the performance-evidence thread on network_compression_method. This is the deliberate ZSTD(3)-vs-LZ4 tradeoff aligning self-managed with Cloud; attach before/after numbers if you want them in the PR.

Verification: the three changed dbms TUs and the new gtest compile cleanly under the RelWithDebInfo build; the mixed-codec read behavior is identical to the existing, passing MergeTree mixed-codec gtest (gtest_reader_mixed_codecs). A full link of unit_tests_dbms was not feasible in this environment (the shared build dir has no linked binary), so the gtest was compile-verified rather than executed.

alexey-milovidov and others added 2 commits June 30, 2026 02:58
`Log`/`TinyLog` store each column with its own codec, so pinning the columns to
`CODEC(LZ4)` keeps their on-disk byte dumps independent of the server default
codec. `StripeLog`, however, writes a single shared `data.bin` (and its
`index.mrk`) through `CompressionCodecFactory::getDefaultCodec`, ignoring the
per-column codec, so its dumps reflect the default — which this PR changes to
`ZSTD(3)`. The previous column-codec pin therefore could not stabilize the
`StripeLog` sections, and `02047_log_family_data_file_dumps` /
`02047_log_family_complex_structs_data_file_dumps` still differed from their
references.

Regenerate the `StripeLog` sections of both references under the `ZSTD(3)`
default (the `Log`/`TinyLog` sections are byte-identical) and update the
explanatory comment to describe the per-engine behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Three more stateless tests asserted sizes that depend on the default
compression codec and broke under the `ZSTD(3)` default:

- `02241_filesystem_cache_on_write_operations`: the cached on-disk segment
  byte totals shift (`ZSTD(3)` has slightly larger per-block overhead than
  `LZ4` on the tiny, highly-compressible blocks this test writes). Pin the
  columns to `CODEC(LZ4)` and update the three echoed `CREATE TABLE` lines in
  the reference.
- `03546_add_distinct_to_in_clause`: compares compressed `NetworkReceiveBytes`
  between the with-`DISTINCT` and without-`DISTINCT` queries; under the
  `ZSTD(3)` network default the repetitive without-`DISTINCT` stream is
  entropy-coded almost as small as the tiny with-`DISTINCT` payload, so the
  strict comparison flaps. Pin `network_compression_method = 'LZ4'`.
- `03783_autopr_dataflow_cache_reuse_qcc`: the existing
  `default_compression_codec = 'LZ4'` pin only covers wide parts; the
  compact-part byte estimation falls back to `getDefaultCodec` (now `ZSTD(3)`),
  and the merge-tree-settings randomizer can force compact parts. Add
  `min_bytes_for_wide_part = 0` so the estimate uses the on-disk `LZ4` ratio.

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

This branch was successfully deployed

1 active deployment
staging - docs — 8b9018bb Deployed Sep 5, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-backward-incompatible Pull request with backwards incompatible changes 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.

6 participants