Skip to content

Extend adaptive codec selection to all types - #115639

Merged
rienath merged 9 commits into
masterfrom
adaptive-codec-wrap-every-type
Aug 30, 2026
Merged

rienath merged 9 commits into
masterfrom
adaptive-codec-wrap-every-type

Conversation

@rienath

@rienath rienath commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Adaptive codec selection only worked with data types that had specified specialised candidates as we used to compress the default codec twice (once during selection, once during compression). This was fixed in #113511.

With this PR, adaptive codec would be applied to all types and select between the default codec and NONE per block, when no specialised codec is specified. Thus, incompressible data would be stored raw and we'd save time on decompression and some space.

Changelog category (leave one):

  • Improvement

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

With adaptive codec selection (allow_experimental_adaptive_codec_selection), columns without a specialised candidate now select between the default codec and NONE per block, so incompressible data is no longer stored larger than raw.


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

Since #113511 selection compresses each candidate at most once, so the isCandidateType saves nothing. Types with no specialized candidate now get NONE / default codec
@Michicosun Michicosun self-assigned this Aug 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0c7408e]

Summary: ✅


AI Review

Summary

This PR removes the candidate-type gate from adaptive codec selection, so default-coded data streams without a specialized candidate can now choose between the part default codec and NONE during merges and mutations. I did not find a new correctness problem in the codec or writer path, but there are still two accuracy issues in the user-facing text.

PR Metadata
  • Changelog category: Improvement matches the actual change.
  • Changelog entry: required and mostly clear, but it names the wrong setting. allow_experimental_adaptive_codec_selection does not exist; this feature is controlled by enable_adaptive_codec_selection.
  • Suggested replacement: With adaptive codec selection (enable_adaptive_codec_selection), columns without a specialized candidate now choose between the default codec and NONE per block, so incompressible data is no longer stored larger than raw.
Findings

💡 Nits

  • [src/Parsers/ParserCreateQuery.cpp:3183] [dismissed by author -- https://github.com/Extend adaptive codec selection to all types #115639#discussion_r3824027022] The moved note still says "Other columns select between the default codec and NONE", but the new 05023 test still shows structural substreams like String.size staying on the default codec. This is user-visible in mergeTreeCodecBlockCounts, so the docs should narrow the claim to eligible data substreams rather than whole columns.
Final Verdict

No new blocking code issue found in the implementation. The remaining follow-up is to tighten the docs wording and fix the changelog entry's setting name.

LLVM Coverage Report

Measured on commit 0c7408e.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.80% 80.80% +0.00%

Changed lines: Changed C/C++ lines covered: 54/54 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 20, 2026
The specialized codecs above can shrink the right data dramatically, but choosing them takes expertise, and no single choice fits a column whose data changes over time. With the MergeTree setting [`allow_experimental_adaptive_codec_selection`](/reference/settings/merge-tree-settings) enabled, ClickHouse chooses for you. For columns that use the default codec (`CODEC(Default)` or no `CODEC` at all), each block is written with whichever codec would compress it smallest, chosen among the table's default codec, `NONE`, and specialized codecs suited to the column type.

<Note>
Specialized codecs are currently chosen for integers up to 64 bits, enums, dates and times, `Decimal32`/`Decimal64`, and `IPv4`. Other columns select between the default codec and `NONE`.

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 still overstates the current coverage. Structural substreams like String.size, ArraySizes, and NullMap stay on the default path because isSpecialCompressionAllowed filters them out; the new 05023 reference already shows incompressible.size staying LZ4. Please phrase this in terms of the eligible/non-structural data substreams so it matches what users will see in mergeTreeCodecBlockCounts.

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.

The user that cares about these substreams is the one familiar enough with our repo to check the code. User that doesn't shouldn't care about this information.

Also, even if you are in first category, it's quite obvious that structural substreams shouldn't be compressed with the same codec as the data

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0c7408e5f with master 9adeb11c7 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 710.14 MiB 707.08 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@mintlify

mintlify Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Aug 24, 2026, 10:51 AM

Comment on lines +109 to +110
static const CompressionCodecPtr none_codec = CompressionCodecFactory::instance().get("NONE", {});
Codecs pool{none_codec, deployment_default};

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.

Is a single allocation being optimized here?

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. Not much, but it's free

@rienath rienath added the hold Skip for auto-updating. label Aug 25, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Aug 25, 2026
The test guarded against an excessive loop in `skipPrefixBeforeHeader` by putting
`timeout 10` around a query that skips `1000000000` lines of a two-line file.
Both sides of that bound were too close to each other:

- With the fix in place the query is instant, but the server can be stalled by
  something unrelated for seconds. In the reported failure the query took 8.8 s
  of wall time and only 0.17 s of CPU time, and all nine `Real` profiler samples
  show the `TCPHandler` thread blocked in
  `__sanitizer::SizeClassAllocator64::ReturnToAllocator` -> `Semaphore::Wait`
  while destroying the pipeline executor - contention inside the msan allocator,
  not in ClickHouse. That is 88% of the 10 s budget spent on nothing.

- Without the fix the loop is a plain userspace spin: `readImpl` returns early at
  EOF once the file size is known, so there is not even a syscall per iteration.
  At the measured ~40 ns per iteration, `1000000000` lines is only tens of
  seconds - the same order of magnitude as the timeout itself.

Skip `1000000000000000000` lines instead. A fixed server still stops at the end
of the file in constant time, while an unfixed one would need centuries, so the
timeout can be raised to 60 s and the verdict no longer depends on how fast the
machine is.

Closes: ClickHouse#116161

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115639&sha=6d410fc0ff3ed27db04af7aabdf2dc8020438899&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F3%29
Related: ClickHouse#115639

Co-Authored-By: Claude Fable 5 <[email protected]>
@rienath
rienath added this pull request to the merge queue Aug 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 28, 2026
@rienath
rienath added this pull request to the merge queue Aug 30, 2026
Merged via the queue into master with commit b31f966 Aug 30, 2026
847 of 854 checks passed
@rienath
rienath deleted the adaptive-codec-wrap-every-type branch August 30, 2026 16:06
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 30, 2026

This branch was successfully deployed

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

Labels

hold Skip for auto-updating. pr-improvement Pull request with some product 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