Skip to content

Choose the codec of an inserted part by the size of the inserted block - #127652

Merged
alexey-milovidov merged 1 commit into
masterfrom
insert-codec-by-block-size
Oct 24, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
insert-codec-by-block-size

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

The size-aware default codec (#108786: LZ4 below 100 MB, ZSTD(3) above) was evaluated with size 0 for every inserted part. So all inserted data was written with LZ4 and then rewritten with ZSTD(3) by merges. Now the uncompressed size of the inserted block is used: small inserts still use LZ4, and large ones (such as INSERT SELECT with the default 256 MB min_insert_block_size_bytes) use ZSTD(3) right away.

On ClickBench, the inserted parts take 8.85 GiB instead of 14.27 GiB, at the cost of about 33% more CPU in the insert. On slow disks (ClickBench uses EBS gp2, 250 MB/s), the load is bound by disk throughput, so less data written means a faster load.

Split from #126251, as requested in #126251 (comment).

Related: #126251

Changelog category (leave one):

  • Performance Improvement

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

Large inserts into MergeTree tables now write their parts with ZSTD(3) right away instead of writing them with LZ4 first, because the size-aware default codec is now evaluated with the uncompressed size of the inserted block. This reduces the amount of data written during a bulk load.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.727-master (included in 26.11 and later)

The size-aware default codec (`LZ4` below 100 MB, `ZSTD(3)` above) was evaluated
with size `0` for every inserted part, so all inserted data was written with `LZ4`
and then rewritten with `ZSTD(3)` by merges. Use the uncompressed size of the
inserted block instead: small inserts still use `LZ4`, and large ones get `ZSTD(3)`
right away.

Split from #126251
#126251 (comment)

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

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8c5adc4]

Summary: ✅


AI Review

Summary

The PR selects the insert-time compression codec using the uncompressed size of each partition's block, allowing large inserts to use ZSTD(3) immediately. It also updates configured-size-rule assertions and the compression documentation. Review of commit 8c5adc437f8909f5d37bd3a193e481396f93c2ba found no actionable findings. The reported ClickBench measurements support the reduced write volume and disclose the increased insert CPU cost.

Missing context / blind spots
  • ⚠️ Integration results were not available at review time, and no local build was available to run the tests. A passing run of test_default_compression_codec would close this runtime-validation gap.
Final Verdict

Status: ✅ Approve. No code changes requested; integration validation remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 23, 2026
@mintlify

mintlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 23, 2026, 10:13 PM

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Oct 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8c5adc437 with master 3954b49bc (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of e442036ac; 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

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

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse ProfileEvents::global_counters_storage 13.69 MiB 13.75 MiB +64.00 KiB (+0.46%)
programs/clickhouse-keeper ProfileEvents::global_counters_storage 13.69 MiB 13.75 MiB +64.00 KiB (+0.46%)

Job report

@alexey-milovidov alexey-milovidov left a comment

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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 24, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 24, 2026
Merged via the queue into master with commit 48e2841 Oct 24, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the insert-codec-by-block-size branch October 24, 2026 05:57
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 24, 2026
middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Oct 28, 2026
…me size-aware

Since ClickHouse#127652 an inserted block larger than `min_part_size_for_default_codec`
is written with the default codec (ZSTD(3)) instead of LZ4. The test inserts
5000 copies of one 104857-byte string per partition; ZSTD collapses the
repetition, so each part shrank from ~500 MB to ~34 MB and a fetch now lasts
about one second, i.e. about one ASan poll iteration.

The polling loop's only exit was "6 distinct part names were observed in
system.replicated_fetches". In MasterCI c0e5c9a (amd_asan_ubsan, db disk)
the first poll was delayed 2.4 s by system-log table creation on the remote
database disk, so the first batch of 3 fetches started and finished unseen,
`fetched_parts` stayed at 3 and the loop spun into the 900 s pytest timeout,
although all 6 fetches had finished within 3 s.

Pin `CODEC(LZ4)` on the payload column (the repeated string is longer than
LZ4's 64 KiB window, so the parts stay large again, as in ClickHouse#108786 for the
sibling bandwidth tests), and exit the loop once node2 has all 6 parts active
instead of once every transient fetch has been observed. The assertions are
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

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

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. 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.

2 participants