Repository navigation
Add ZXC compression codec - #110620
Add ZXC compression codec#110620
Conversation
Integrate zxc (https://github.com/hellobertrand/zxc), an asymmetric LZ codec built for very fast decompression, as a new general-purpose codec `CODEC(ZXC[(level)])` (levels 1..7, default 3, compression method byte 0x9e). `ZXC` trades slow compression for fast decompression at a ratio between `LZ4` and `ZSTD`, which suits the compress-once/read-many pattern of analytical columns and decodes especially fast on modern ARM cores. - `contrib/zxc` submodule plus a curated `contrib/zxc-cmake` build that mirrors zxc's per-ISA variant objects with runtime dispatch, without its own `-march=native`/LTO/PGO defaults (ClickHouse manages its own flags). - `CompressionCodecZXC` uses zxc's one-shot frame API with zxc's internal checksum disabled, since ClickHouse already checksums every compressed block. - Documentation and a stateless roundtrip test (all levels plus error handling). Note: `contrib/zxc` points at the upstream repository as a placeholder; before merging it must be replaced with a fork under github.com/ClickHouse. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [6208458] Summary: ✅
AI ReviewSummaryThis PR adds a new general-purpose compression codec, Findings❌ Blockers
Final VerdictStatus: ❌ Block |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
ClickBench benchmark —
|
| Codec | On-disk | Ratio | Load time |
|---|---|---|---|
LZ4 |
14.29 GiB | 4.16× | 663 s |
ZSTD(1) |
9.32 GiB | 6.39× | 621 s |
ZXC(3) |
12.85 GiB | 4.63× | 1156 s |
Query time (sum over 35 queries)
| Codec | Total | Fastest on |
|---|---|---|
LZ4 |
3.82 s | 8 / 35 |
ZSTD(1) |
3.83 s | 9 / 35 |
ZXC(3) |
3.65 s | 25 / 35 |
ZXC(3) is the fastest on the query suite — the decode-bound scans benefit most (e.g. Q21–Q23, Q34–Q35 are ~20–30% faster than both LZ4 and ZSTD). It compresses better than LZ4 (but not ZSTD) at the cost of ~1.8× slower compression — the expected write-once/read-many trade-off. ZSTD(1) remains the best on ratio.
One rough edge to investigate as a follow-up: ZXC has a small fixed per-query overhead on trivial queries (e.g. COUNT(*) ~33 ms vs ~1 ms for LZ4/ZSTD), likely a per-block decode-context setup cost.
Raw single-column codec comparison (whole-column, not per-block): https://pastila.nl/?cafebabe/16ae94cb2aba1cd26c656f3ded96d882.md
ClickBench geomean of ratios — all 43 queriesUsing ClickBench's own summary metric (per-query baseline = the fastest of the compared systems,
By the geomean metric The trivial-query overhead I flagged earlier was a measurement artifact of running each query in a fresh process (first-touch table open); warmed in a single session, |
Fast test only checks out a curated subset of submodules (ci/jobs/fast_test.py), and contrib/zxc was missing from that list. add_contrib() in contrib/CMakeLists.txt silently skips a submodule whose directory is empty, so ch_contrib::zxc was never defined and CMake failed at the src/CMakeLists.txt target_link_libraries step that links clickhouse_compression against it.
The compression frame's method-byte table in the spec enumerates every assigned CompressionMethodByte value; add the 0x9e entry that this PR assigns to the new ZXC codec, per docs/en/interfaces/specs/NativeFormat.md being the single source of truth for the frame's byte encoding.
| UInt32 doDecompressData(const char * source, UInt32 source_size, char * dest, UInt32 uncompressed_size) const override; | ||
|
|
||
| bool isCompression() const override { return true; } | ||
| bool isGenericCompression() const override { return true; } |
There was a problem hiding this comment.
This makes a brand-new on-disk method byte (0x9e) immediately available in CODEC(...) without any allow_experimental_codecs gate. That is risky for mixed-version rollouts: as soon as one new replica writes a part with ZXC, older servers cannot read it, and there is no compatibility knob to keep the cluster on the old codecs while this format soaks in production. Recent new codecs such as ALP and SZ3 stay behind isExperimental() for exactly this reason. Please gate ZXC the same way for now (while still allowing decompression of already-written 0x9e parts).
zxc's x86-64 runtime SIMD dispatch calls `__builtin_cpu_init` / `__builtin_cpu_supports`, which reference compiler-rt's `__cpu_model`. That symbol is not linked into ClickHouse's macOS cross-build, so the `Build (amd_darwin)` job failed with `undefined ___cpu_model`. macOS builds are for local development only, so on Darwin x86-64 restrict zxc to its portable scalar core: `ZXC_DISABLE_SIMD` forces the dispatcher to the `_default` variant (dropping the `__builtin_cpu_*` calls), and we skip building the now-unused per-ISA variant objects. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# Conflicts: # docs/en/interfaces/specs/NativeFormat.md # src/Compression/CompressionInfo.h # src/Compression/registerCompressionCodecs.h
The `amd_msan` flaky check reported `use-of-uninitialized-value` when running the new `04545_zxc_codec` test. zxc's fast decoder copies literals with 32-byte SIMD "wild" loads that can read up to `ZXC_PAD_SIZE` (32) bytes past the end of the compressed input. `CompressionCodecZXC` did not override `getAdditionalSizeAtTheEndOfBuffer`, so it inherited the base default of `0` and ClickHouse sized the compressed source buffer with no initialized tail slack — the SIMD load then read the uninitialized tail. Override `getAdditionalSizeAtTheEndOfBuffer` to reserve 64 bytes of slack at the end of the (de)compression buffers, exactly as `CompressionCodecLZ4` does for the identical over-read pattern. This is a ClickHouse-side fix; no change to the zxc sources is required (the decoder never over-writes the destination and the compressor leaves no uninitialized bytes in its output). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The previous MSan fix (64 bytes of allocated slack after the compressed source) did not clear the `use-of-uninitialized-value` reports in the `amd_msan` jobs, because allocation does not make the bytes defined and, more importantly, the source-tail over-read was never the trigger: those bytes are only wild-copied and never influence a branch. The real cause is toolchain-level: clang's MSan has no precise shadow model for the x86 byte-shuffle intrinsics (`pshufb` and friends) — input shadows are OR-ed positionally instead of being routed through the shuffle, so poisoned lanes that the shuffle discards still poison the logical result. zxc's SIMD kernels deliberately do speculative 16/32-byte loads whose tail lanes fall into malloc'ed scratch buffers or not-yet-written output and are then discarded by such shuffles (e.g. `zxc_decode_copy_overlap_run`, `zxc_pivco_merge`), producing false positives that either fire inside the decoder (level 7 token decoding) or propagate into the decompressed output and fire downstream. AArch64 NEON `tbl` has a precise shadow model, which is why the same code is clean under an aarch64 MSan build. Fix: under `SANITIZE=memory`, build only zxc's scalar core by defining `ZXC_DISABLE_SIMD` on the core and on the `_default` kernel objects and skipping the per-ISA variant objects. The scalar fallbacks branch only on initialized bytes; a scalar MSan build of zxc runs all levels and encodings with poisoned source slack with zero reports. Also correct the `getAdditionalSizeAtTheEndOfBuffer` comment: the slack is still required so the (real, bounded) source over-read stays inside allocated memory, but it is not an MSan mechanism. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=80b9c579e742e8044028edbe00afa80e376e6440&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20flaky%20check%29 PR: #110620 Co-Authored-By: Claude Fable 5 <[email protected]>
The `amd_debug` flaky check failed the test with "Test runs too long (> 180s)" (252 s): 300k rows compressed through nine `ZXC` columns is too much work for a debug build, since `ZXC` compression is slow by design at the higher levels. Reduce to 50k rows — still multiple compressed blocks per column across all levels, which keeps the roundtrip coverage. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=80b9c579e742e8044028edbe00afa80e376e6440&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 PR: #110620 Co-Authored-By: Claude Fable 5 <[email protected]>
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=80b9c579e742e8044028edbe00afa80e376e6440&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 ( It is unrelated to this PR: the same failure hit 25 runs across 23 different PRs (including master, |
|
Investigated. This SIGFPE is unrelated to this PR and a fix is already in progress: #110346 (approved by @PedroTadim), issue #110343. Root cause (from the crash stack in the report): A quota created with a non-positive (zero-length) interval leaves Fix in #110346:
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=80b9c579e742e8044028edbe00afa80e376e6440&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 (STID 4141-584d / 4141-5867). |
Per ClickHouse's supply-chain policy, the contrib/zxc submodule must point at a fork under github.com/ClickHouse rather than the upstream repository. Created https://github.com/ClickHouse/zxc as a fork of https://github.com/hellobertrand/zxc and repointed the submodule URL there. The pinned commit b9890cfe3466b19d0eb5005874ce81728efb9565 is unchanged and is reachable from the fork (it is the parent of the fork's main HEAD). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
The two CI failures on
@groeneai, could you investigate the |
|
The two CI failures on
@groeneai, could you take a look at failure 2 and open a tracking issue / fix in a separate PR if it recurs? I've merged fresh |
|
@alexey-milovidov, findings on both items. Both confirmed structurally unrelated to the ZXC codec. Item 2 - RWLockImpl::getLock re-entrant deadlock (STID 2043-3c5c, Stress test arm_debug) CIDB (30d): exactly 1 occurrence, this PR, 0 on master, 0 on any other PR. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=ee4b5b869d5d3656964166ce79cdc044545bf273&name_0=PR&name_1=Stress%20test%20%28arm_debug%29 Root cause (from the stack + source): the internal cleanup DROP inside This is the same LOGICAL_ERROR class as #79413 / #47023. #86751 (merged, Closes #79413) fixed the sibling Candidate fix direction (mirrors #86751): give the internal DROP context a distinct Failure 2 - Replicated-DB UUID collision (Upgrade check, amd_release) This is a chronic upgrade-check artifact, not a regression. CIDB (30d) for Already tracked, with an open harness allow-list PR: #107126 (masks only the benign |
|
Item 2 (RWLockImpl re-entrant deadlock, STID 2043-3c5c): tracking issue opened at #110893 with the full root cause and the candidate fix (give the internal DROP context a distinct/empty query_id in make_drop_context so it bypasses the RWLock query_id fast-path). Still not reproducible deterministically locally: under the stress thread-fuzzer env I hammered concurrent same-table CREATE OR REPLACE, forced catch-path drops (max_table_size_to_drop=1), forced fill-throw (max_memory_usage), and self-referential CREATE OR REPLACE ... AS SELECT FROM t. All exercise the internal-DROP path but none hit the re-entrant window (holders destruct on unwind before the internal DROP). Per no-speculative-fix I will validate the fix against a failing repro before opening the PR; #110893 tracks it. |
|
The single CI failure on
This is the known @groeneai, the fix is already in progress: #109225 (partial_merge JOIN trigger) and #110778 (ARRAY JOIN trigger) — no new fix needed; linking here for attribution. The branch has been updated with the latest |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 45/52 (86.54%) · Uncovered code |
| # symbol is not linked into ClickHouse's macOS cross-build, so linking fails | ||
| # with "undefined ___cpu_model". macOS builds are for local development only, | ||
| # so restrict zxc to its portable scalar core there. | ||
| set(ZXC_FORCE_SCALAR TRUE) |
There was a problem hiding this comment.
Ok, as it is a very old platform.
Resolve the method-byte collision: ZXC (PR #110620) merged to master taking `0x9f`, the slot PCO used. Move `PCO` to the next free byte `0xa0` (160) and keep `ZXC = 0x9f` (159). Updated `CompressionInfo.h` enum, `01222_system_codecs.reference` (PCO byte 159->160, added the ZXC row, count 17->18), the `NativeFormat.md` byte table + PCO per-column frame section header, and the `PCO` block-layout comment in `CompressionCodecPco.cpp`. Both codecs are registered in `CompressionFactory.cpp`; both submodule entries kept in `.gitmodules`.
|
Hi @alexey-milovidov — a couple of suggestions to make this PR easier for reviewers and the changelog reader. Description (currently
Ignore this if the current title/body is intentional. |
Just clarified with the internal security team, such a policy currently doesn't exist. The security comes from pinning a commit SHA, not from where the repository lives. |
The `ZXC` codec was added in ClickHouse#110620 but, unlike the other recently added codecs (`ALP`, `SZ3`), it was not placed in the experimental category. Mark it experimental so that using it requires `SET allow_experimental_codecs = 1`, matching the convention for new codecs that are not yet meant for production. - `CompressionCodecZXC::isExperimental` now returns `true`, so the codec is rejected with `BAD_ARGUMENTS` unless `allow_experimental_codecs` is enabled, and `system.compression_codecs` reports it as experimental. - Test `04545_zxc_codec` enables the setting and adds a negative case that the codec is rejected without it. - Documentation gets an experimental badge and note. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `ZXC` codec was added in ClickHouse#110620 but, unlike the other recently added codecs (`ALP`, `SZ3`), it was not placed in the experimental category. Mark it experimental so that using it requires `SET allow_experimental_codecs = 1`, matching the convention for new codecs that are not yet meant for production. - `CompressionCodecZXC::isExperimental` now returns `true`, so the codec is rejected with `BAD_ARGUMENTS` unless `allow_experimental_codecs` is enabled, and `system.compression_codecs` reports it as experimental. - Test `04545_zxc_codec` enables the setting and adds a negative case that the codec is rejected without it. - Documentation gets an experimental badge and note. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The previous MSan fix (64 bytes of allocated slack after the compressed source) did not clear the `use-of-uninitialized-value` reports in the `amd_msan` jobs, because allocation does not make the bytes defined and, more importantly, the source-tail over-read was never the trigger: those bytes are only wild-copied and never influence a branch. The real cause is toolchain-level: clang's MSan has no precise shadow model for the x86 byte-shuffle intrinsics (`pshufb` and friends) — input shadows are OR-ed positionally instead of being routed through the shuffle, so poisoned lanes that the shuffle discards still poison the logical result. zxc's SIMD kernels deliberately do speculative 16/32-byte loads whose tail lanes fall into malloc'ed scratch buffers or not-yet-written output and are then discarded by such shuffles (e.g. `zxc_decode_copy_overlap_run`, `zxc_pivco_merge`), producing false positives that either fire inside the decoder (level 7 token decoding) or propagate into the decompressed output and fire downstream. AArch64 NEON `tbl` has a precise shadow model, which is why the same code is clean under an aarch64 MSan build. Fix: under `SANITIZE=memory`, build only zxc's scalar core by defining `ZXC_DISABLE_SIMD` on the core and on the `_default` kernel objects and skipping the per-ISA variant objects. The scalar fallbacks branch only on initialized bytes; a scalar MSan build of zxc runs all levels and encodings with poisoned source slack with zero reports. Also correct the `getAdditionalSizeAtTheEndOfBuffer` comment: the slack is still required so the (real, bounded) source over-read stays inside allocated memory, but it is not an MSan mechanism. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=80b9c579e742e8044028edbe00afa80e376e6440&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20flaky%20check%29 PR: ClickHouse#110620 Co-Authored-By: Claude Fable 5 <[email protected]>
The `amd_debug` flaky check failed the test with "Test runs too long (> 180s)" (252 s): 300k rows compressed through nine `ZXC` columns is too much work for a debug build, since `ZXC` compression is slow by design at the higher levels. Reduce to 50k rows — still multiple compressed blocks per column across all levels, which keeps the roundtrip coverage. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110620&sha=80b9c579e742e8044028edbe00afa80e376e6440&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 PR: ClickHouse#110620 Co-Authored-By: Claude Fable 5 <[email protected]>
Add ZXC compression codec
Integrates zxc, an asymmetric LZ codec built for very fast decompression, as a new general-purpose compression codec
CODEC(ZXC[(level)])(levels 1..7, default 3).ZXCtrades slow compression for fast decompression at a compression ratio betweenLZ4andZSTD— a good fit for the compress-once/read-many pattern of analytical columns, and it decodes especially fast on modern ARM cores (e.g. AWS Graviton).Implementation notes:
contrib/zxcsubmodule plus a curatedcontrib/zxc-cmakebuild that mirrors zxc's per-ISA variant objects with runtime CPU dispatch (portable binary), without zxc's own-march=native/LTO/PGO defaults, since ClickHouse manages its own flags.CompressionCodecZXCuses zxc's one-shot frame API with zxc's internal checksum disabled, because ClickHouse already checksums every compressed block.0x9e. Available likeLZ4/ZSTD(not experimental).Tested on AArch64 (AWS Graviton4): full build, a new stateless test
04545_zxc_codec(all levels roundtrip + detach/attach + error handling), and a real ClickBenchhitsload whereCODEC(ZXC)roundtrips byte-exact throughMergeTreeand out-compressesLZ4at the default level.Raw-codec benchmark on ClickBench
hits(single-threaded, Graviton4): results on pastila.Note
Per ClickHouse's supply-chain policy,
contrib/zxcpoints at a fork under the ClickHouse organization: https://github.com/ClickHouse/zxc (forked from https://github.com/hellobertrand/zxc). The pinned commit is unchanged.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a new codec
ZXC— an asymmetric LZ codec with slow compression and very fast decompression, with a compression ratio betweenLZ4andZSTD.Documentation entry for user-facing changes
ZXCcodec is documented in the compression codecs reference).