Skip to content

Adaptive codec selection: chains - #121630

Merged
rienath merged 10 commits into
masterfrom
chains
Sep 28, 2026
Merged

rienath merged 10 commits into
masterfrom
chains

Conversation

@rienath

@rienath rienath commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Every type-specific candidate now also forms a chain with table's default codec, when that default is a general-purpose compression. For example, integers would now be tried with {NONE}, {ZSTD(3)}, {T64}, {T64 + ZSTD(3)}. A chain is not compressed from scratch. Its first codec has just been compressed as a candidate of its own, so we take that block and run only the remaining stage.

Along the way Multiple lost two copies it made on every block, which speeds up compression on every user-declared chain as well.

Changelog category (leave one):

  • Experimental Feature

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

Adaptive codec selection (enable_adaptive_codec_selection) also tries each specialised codec followed by the table's default codec.


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

Version info

  • Merged into: 26.10.1.901-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7f91713]

Summary: ✅


AI Review

Summary

This PR extends enable_adaptive_codec_selection so type-specific candidates are also tried as specialized + default, and it refactors CompressionCodecMultiple so the chain can reuse the first-stage block instead of recompressing from scratch. The behavior change looks coherent, but the merge-time hot path now does strictly more work for chain-capable candidates and the PR no longer includes performance evidence that this cost is acceptable, so I would still request changes.

Findings

⚠️ Majors

  • [src/Compression/CompressionCodecAdaptive.cpp:174, tests/performance/adaptive_codec_merge.xml:2] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/121630#discussion_r4095381381] Adaptive selection no longer uses tryGetCompressedSize for any candidate that can form a chain, so every merge-time block on integer/date and float columns now pays for a full first-stage compression just to price specialized + default. The author’s reply explains why the first-stage block is reusable once the chain is tried, but it does not establish that the added hot-path work is acceptable, and the current PR simultaneously skips the pr-performance shards and comments out the two perf legs (adaptive_codec_merge and adaptive_codec_merge_chain) that were meant to cover the new chain-pricing paths. Suggested fix: either provide before/after measurements for those merge cases (or re-enable the perf legs and run the performance comparison jobs), or add the sampling/gating mentioned in the PR so we do not pay full first-stage compression on every adaptive block before we have evidence that it is safe.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: provide performance evidence for the merge-time chain-pricing path (adaptive_codec_merge / adaptive_codec_merge_chain, or equivalent focused benchmarks), or add a cheaper gate such as sampling before this extra first-stage compression is paid on every adaptive block.

LLVM Coverage Report

Measured on commit 7f91713.

Metric Baseline Current Δ
Lines 88.10% 88.20% +0.10%
Functions 91.70% 91.80% +0.10%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 117/123 (95.12%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Sep 22, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... label Sep 22, 2026
@Michicosun Michicosun self-assigned this Sep 23, 2026
for (const auto & [codec, chain] : pool)
{
/// A candidate without a chain that reports its size cheaply is measured rather than compressed.
if (auto calculated = chain ? std::nullopt : codec->tryGetCompressedSize(source, source_size))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This removes the cheap tryGetCompressedSize path as soon as a generic default codec makes chaining possible. For the common integer/date case, T64 now has to materialize a full compressed block on every merge-time block just so T64 + default can be priced, even when the winner still ends up being NONE or the default codec.

That is extra CPU work in a hot path, and the PR currently does not show that it is acceptable: the perf-comparison jobs were skipped on this PR, and tests/performance/adaptive_codec_merge.xml comments out the two merge legs that would have exercised this new pricing path. I think this needs either a cheaper gate/sampling step before we pay for the first-stage compression, or benchmark evidence that the added work is acceptable.

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.

On purpose. When we have a chain T64 + ZSTD, we have to compress T64 anyway. Doing a compression of T64 separately just gives us first layer of chain later for free.

@@ -1,33 +1,52 @@
<test>
<!-- TODO: uncomment the adaptive_codec_merge and adaptive_codec_merge_chain legs once sampling lands. -->

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.

  1. I reduced size of adaptive_codec_merge as it was taking a bit too long for our CI.
  2. I commented out adaptive_codec_merge test.
  3. I added a commented out adaptive_codec_merge_chain.

2 and 3 get slower because of this PR. This is expected as we increase number of candidates for adaptivity. But this will be fixed (in fact, they would be faster than current master) when sampling lands. It's strange that I am adding a new test that is commented out, but it makes sense to do it now as it's relevant

for (const auto & [codec, chain] : pool)
{
/// A candidate without a chain that reports its size cheaply is measured rather than compressed.
if (auto calculated = chain ? std::nullopt : codec->tryGetCompressedSize(source, source_size))

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.

On purpose. When we have a chain T64 + ZSTD, we have to compress T64 anyway. Doing a compression of T64 separately just gives us first layer of chain later for free.

@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 7f91713c8c3667cc12b32c313e211ecfc0676739 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

Comment on lines +139 to +140
for (size_t idx = 0; idx < chain.size(); ++idx)
dest[1 + idx] = chain[idx]->getMethodByte();

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.

Do we rewrite the whole chain method byte prefix?

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.

Yes. With one codec we didn't need a prefix as we know from 9-byte header the codec. With chain, 9 byte header just tells us it's CodecMultiple and then we have a prefix [length][codec_1]...[codec_length]. With completed_stages >= 1 we only pass the data, no prefix. So there's no prefix to keep

@rienath
rienath added this pull request to the merge queue Sep 28, 2026
Merged via the queue into master with commit f573c01 Sep 28, 2026
177 checks passed
@rienath
rienath deleted the chains branch September 28, 2026 10:54
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
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-experimental Experimental Feature 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