Skip to content

Hash the type-derived parameter in the ALP, FPC and GCD codecs - #114189

Merged
rienath merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/alp-fpc-codec-hash-float-width
Aug 23, 2026
Merged

rienath merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/alp-fpc-codec-hash-float-width

Conversation

@groeneai

@groeneai groeneai commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed ALP, FPC and GCD omitting their type-derived parameter from the codec hash. In a Compact part the writer shares one compressed stream per distinct codec hash, so two columns of different value width under the same codec collided and shared one codec object carrying the wrong width. This rejected valid inserts with CANNOT_COMPRESS when the widths disagreed, and otherwise compressed one of the columns worse than it should have.

Description

Closes: #113940
Related: #113798

MergeTreeDataPartWriterCompact::addStreams keys compressed-stream reuse on codec->getHash() with no key-equality fallback, so a hash collision is an object-identity collision. Three codecs resolve a parameter from the column type, keep it out of the codec description AST, and hash only that AST, so two columns of different width shared one codec object and the loser of the race got the other's width:

  • ALP and FPC derive float_width. With Float64 declared first the shared codec carries float_width = 8, a Float32 granule is not a multiple of 8, and ALP throws Code: 270 ... data size 404 is not aligned to 8 (CANNOT_COMPRESS). A mixed-width Tuple(Float64, Float32) CODEC(ALP) reaches the same throw, since the codec is resolved per substream. FPC ceil-divides instead of throwing, so its half is ratio-only: measured +10.0%.
  • GCD derives gcd_bytes_size, so the divisor width depended on declaration order and the ratio suffered. Data round-trips either way, because the width is in the GCD block header. Added on review request so the class stays revertable as one change; Fix GCD codec behavior on signed values #113798 fixes the same updateHash for its own is_signed_type and goes forward independently.

The fix adds the missing field to each hash, matching SZ3, DoubleDelta, Gorilla, T64 and Delta, which already hash their type-derived width. Wide parts were never affected: one stream per column.

Two consequences worth noting. Codec hashes also gate can_substitute_codec_arguments, a whole-codec flag, so Tuple(Float32, Float64) CODEC(FPC, LZ4) now shows as CODEC(FPC, LZ4) rather than CODEC(FPC(12), LZ4); Delta and Gorilla already behave this way, same-width tuples still resolve, and a bare CODEC(FPC) still means level 12. No format change: each codec records the parameter in its own block header, so existing parts stay readable both ways.

Validation

Debug build, base f9dd35fa7f57bbd8ec97be53c15acd82848a98f1.

ALP/FPC (build id a0327326e75c88c307e5efda56857c3df38552c7):

Check Before After
INSERT, default table, f64 then f32, 101 rows Code: 270 ... 404 is not aligned to 8 101 rows, Compact part
Tuple(Float64, Float32) CODEC(ALP), default table Code: 270 ... 12012 is not aligned to 8 1001 rows, values round-trip
ALP mixed vs two single-column tables 234896 vs 228332, order dependent 228332 == 228332
FPC mixed vs two single-column tables 238887 vs 217185 217185 == 217185

GCD (build id bb612f0c6681bdde02436c553770393ff66f63fe, pre-fix control 0a3b06892a5a9cafc8bc2c68a19d5fe9dff3f312):

Check Before After
UInt16 + UInt64 mixed vs two single-column tables 80815 vs 80830 80830 == 80830
declaration order invariance (u16, u64 vs u64, u16) 160544 vs 160540 identical
round-trip on the mixed table 20000/20000 20000/20000
same tables as Wide parts (control, no stream sharing) already equal already equal

04861_codec_hash_type_derived_params (renamed, since it no longer covers only float width) fails on the parent commit and passes with the fix; the two new GCD assertions were verified to redden independently, 5/5 runs failing before and 10/10 passing after under randomized settings, and 4-way self-parallel runs pass.

A control build patching only ALP left the FPC numbers at exactly 238887, confirming the FPC measurement is not leaking from the ALP change.


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

Version info

  • Merged into: 26.8.1.1938 (included in 26.8 and later)

groeneai and others added 2 commits August 10, 2026 12:54
MergeTreeDataPartWriterCompact keys compressed-stream reuse on the codec
hash and has no key-equality fallback, so a hash collision is an object
identity collision. ALP and FPC resolve float_width per column from the
column type, it never enters the codec description AST, and updateHash
hashed only that AST. A Float32 and a Float64 column under the same codec
therefore shared one codec object in a Compact part and the loser of the
race was compressed with the other column's width.

The reported symptom was a worse compression ratio, but the defect also
rejects valid inserts: with Float64 declared first the shared codec carries
float_width = 8, the Float32 granule is not a multiple of 8, and the
encoders throw CANNOT_COMPRESS. A mixed-width Tuple(Float64, Float32)
reaches the same throw, since the codec is resolved per substream. Wide
parts are immune, using one stream per column by construction.

FPC has the identical defect and is not behind allow_experimental_codecs,
so it affects default settings; it ceil-divides instead of throwing, so its
half is ratio-only (measured +10.0%).

Adding the field to the hash makes both codecs consistent with SZ3,
DoubleDelta, Gorilla and T64, which already hash their type-derived width.
The change only ever splits cache keys that were wrongly merged.

Codec hashes also gate can_substitute_codec_arguments, so a mixed-width
tuple now keeps its codec unresolved: Tuple(Float32, Float64) CODEC(FPC)
reports CODEC(FPC) rather than CODEC(FPC(12)). That matches what Delta and
Gorilla have always done for mixed-width tuples.

No format change: both codecs already write float_width into their own
block header and decompression reads it from the data, so existing parts
stay readable in both directions.

Closes: ClickHouse#113940
…terministic

The test compares sum(data_compressed_bytes) for exact equality between a
mixed-width table (12 B/row) and two single-column tables (4 and 8 B/row). In a
Compact part that sum is the size of one data.bin, and the writer emits one
compressed block per column per granule, so the granule count scales per-block
framing overhead into the total. computeIndexGranularity derives that count from
bytes_uncompressed / index_granularity_bytes capped by index_granularity, and
both of those settings are randomized by clickhouse-test, so a draw that splits
the mixed table into a different granule sequence than the two singles made the
assertions print 0 on a correct build.

Measured over the randomizer's own domains: 0.0492% of slow-build draws and
0.3475% of release-range draws, i.e. about a 9.4% chance of a red on this PR's
own 200-iteration flaky check, recurring on every later run. Witness values
(index_granularity 38947, index_granularity_bytes 103887) reproduce it and are
fixed by this commit, verified on one fixed binary in both directions.

The two pinned values are the product defaults, so the reference is unchanged;
naming them is only what defeats the injection in ClientBase::addMergeTreeSettings,
which skips any setting the table's own SETTINGS already lists. Pinning the two
implicated settings per table is narrower than a no-random-merge-tree-settings
tag, and the exact-equality oracle still reddens on unpatched master.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Two review rounds, each an independent cold read of the resulting code followed by
a second-model pass. Round 0 raised one blocker (accepted, fixed); this round
found none.

Round 0 — blocker, fixed. The three byte-equality assertions compare exact
sum(data_compressed_bytes) between a mixed-width table and two single-column
tables. In a Compact part that sum is one data.bin, and the writer emits one
compressed block per column per granule, so the granule count scales per-block
framing overhead into the total. computeIndexGranularity derives that count
from index_granularity_bytes and index_granularity, and clickhouse-test
randomizes both, so a draw that splits the mixed table into a different granule
sequence than the two singles made the assertions print 0 on a correct
build: 0.0492% of slow-build draws, 0.3475% of release-range draws, about a 9.4%
chance of a red on this PR's own flaky check and recurring afterwards. Fixed by
pinning both settings, at their product defaults, on the seven size-compared
tables; a no-random-merge-tree-settings tag was deliberately not used, since
the per-setting pin is strictly narrower. Verified on one fixed binary: three
forced witness draws each fail without the pin and pass with it, and the pinned
test still reddens on unpatched master with all three equality assertions
reddening independently.

⚠️ The passing 50/50 sweep was not treated as evidence against that finding:
at p = 0.000492 a 50-run sweep has about 2.4% power, so the targeted
witness-forcing arm is the proof and the sweep is recorded only for completeness.

This round — no blockers, no majors. Verified independently before reading
the implementation's own evidence: the hashed field set now equals the compared
field set for both codecs (ALP state is exactly float_width + variant, and
variant already reached the hash through the description AST; FPC is the same
shape with the compression level in the AST); all eight codecs that receive a
column type were re-audited, leaving ALP + FPC as exactly the remaining
carriers with GCD correctly left to #113798; both getHash() consumers are
accounted for; and there is no format exposure, since each codec records the
width in its own block header and decompression dispatches on the value read back
from the data. Compact data.bin checksums are recomputed at write time and
checkDataPart skips the uncompressed check for Compact parts, so re-partitioning
the streams cannot invalidate a stored checksum. Wide parts are structurally
immune.

Two notes accepted but not blocking:

  • 💡 The CODEC(FPC(12), LZ4) to CODEC(FPC, LZ4) change happens because
    can_substitute_codec_arguments is a whole-codec flag, and the argument that
    disappears is FPC's compression level rather than a width, unlike Delta and
    Gorilla whose descriptions carry the width itself. Harmless, since a bare
    CODEC(FPC) still means level 12. The description was reworded for that
    precision.
  • 💡 Four test section comments are phrased with reference to the defect rather
    than as standing invariants. Left as they are: they make otherwise-opaque
    byte-equality assertions readable, and test files are outside the comment
    budget that applies to src/.

One future interaction, not a defect here: #113824 would replace
allow_experimental_codecs with per-codec settings, which is what this test's
SET uses. Re-checked with a fresh clock, that PR is open with changes requested
and master still declares allow_experimental_codecs, so this test is correct as
master stands; whichever merges second adapts the other's line.

Session id: cron:clickhouse-review-slot-10:20260810-153300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate
# Gate Answer
a Deterministic repro? Yes. CREATE TABLE t (n UInt64, f64 Float64 CODEC(ALP), f32 Float32 CODEC(ALP)) ENGINE = MergeTree ORDER BY n; then insert 101 rows on a default table: Code: 270 ... data size 404 is not aligned to 8. Fires every run, no settings overrides needed.
b Root cause explained? Yes. The Compact-part writer keys compressed-stream reuse on codec->getHash() with no key-equality fallback. ALP/FPC resolve float_width per column from the column type, it never enters the codec description AST, and updateHash hashed only that AST, so two columns of different float width shared one codec object carrying the wrong width.
c Fix matches root cause? Yes. The missing field is added at the hash, i.e. at the cache key, not guarded at the throw site. Rejected alternatives: putting float_width into the codec AST (changes SHOW CREATE TABLE for every ALP column) and keying the writer's streams on the column type (wrong layer, papers over every codec).
d Tests added? Yes, 04861_codec_hash_float_width, stateless SQL, parallel-safe, no no-parallel tag. Four assertions: the rejection is gone, mixed-width bytes equal the two single-column baselines exactly for both codecs, declaration order no longer matters, and the mixed-width Tuple case inserts and round-trips.
e Both directions demonstrated? Yes. The test fails on unpatched master and passes with the fix, and each of the four assertions was verified to redden independently (the equality checks return 0 0 0 on master vs 1 1 1 with the fix).
f General across code paths? Yes. All 8 codecs receiving a column type were audited. ALP and FPC both had the defect and both are fixed; SZ3, DoubleDelta, Gorilla, T64 and Delta already hash their type-derived state. GCD is the same defect but is owned by open #113798, so it is deliberately untouched here.
g General across inputs? Yes. Verified Nullable(Float32/64) and Array(Float32/64) (both reject on master, fixed here), mixed-width Tuple, both declaration orders, and boundaries: empty table, 1 row, 2 rows, NaN, Inf, -Inf. Map/LowCardinality are rejected identically on both arms (not valid ALP targets). Wide parts confirmed structurally immune by measurement.
h Backward compatible? Yes, and no setting changes, so no SettingsChangesHistory.cpp entry. No format change: both codecs already write float_width into their own block header and decompression reads it from the data. Verified in both directions: parts written before the fix read identically after it (including appends and OPTIMIZE FINAL), and parts written after it read identically before it.
i Invariants preserved? Yes. The change only ever splits cache keys that were wrongly merged; it never merges keys that were separate. The one other getHash() consumer, can_substitute_codec_arguments, is affected intentionally and is called out in the PR description. Compact parts gain at most one extra stream per codec, bounded by the number of distinct float widths.

Build id a0327326e75c88c307e5efda56857c3df38552c7, base f9dd35fa7f57bbd8ec97be53c15acd82848a98f1. 50/50 randomized runs of the new test pass. Across all 115 codec/alp/fpc stateless tests the failure set is identical to pristine master apart from 04861 itself.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rienath @Algunenano, could you review this? The Compact-part writer keys compressed-stream reuse on the codec hash with no key-equality fallback, and ALP and FPC left the per-column float width out of that hash, so a Float32 and a Float64 column under the same codec shared one codec object carrying the wrong width, which rejects valid inserts with CANNOT_COMPRESS and otherwise compresses one column worse.

@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [366fe60]

Summary: ✅


AI Review

Summary

This PR fixes getHash() for ALP, FPC, and GCD so Compact-part stream sharing and tuple codec-argument substitution no longer treat distinct type-derived codec states as identical. I re-checked both getHash() consumers, the current merged GCD signedness coverage already on master, the new regression test, and the prior discussion; I did not find a remaining blocker or major issue in the current code.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.10% 87.00% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.30% -0.10%

Changed lines: Changed C/C++ lines covered: 7/7 (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 10, 2026
@kshcherbatov

Copy link
Copy Markdown
Collaborator

@groeneai @rienath My two cents on this: it's unclear whether or when #113798 will be merged. To fix the atomicity/isolation logic, I suggest also fixing the GCD gcd_bytes_size right here. Therefore, my pull request will only apply the change to the brand new 'is_signed_type' field on top of these changes.

This means that if one of them has to be reverted, we can update all the related code at once.

@groeneai

Copy link
Copy Markdown
Collaborator Author

I would rather leave the GCD hash where it is, for two reasons.

It is already in #113798. Your updateHash hunk adds hash.update(gcd_bytes_size) and hash.update(is_signed_type) as two adjacent lines, so moving one of them here leaves two open PRs editing the same two lines of the same function: a conflict for whichever lands second, and a revert of this PR would then pull the sibling line out from under your is_signed_type. Keeping both together in yours is the arrangement that survives a revert. Your coverage is already there too, since 04813 scenario B mixes UInt32 and UInt64 in a Compact part, which is exactly the gcd_bytes_size collision.

On atomicity, the three codecs are already independently revertable, which is stronger than bundling. The fixes share no code: separate files, separate updateHash, separate tests. Reverting this PR touches only CompressionCodecALP.cpp, CompressionCodecFPC.cpp and one test, so it cannot disturb GCD. Bundled, a problem in any one hash would force a revert of all three.

On timing, #113798 reads as mergeable rather than stuck: the 08-07 review comments are answered and you re-requested review on 08-08, so a re-review is the only thing outstanding. If it does get abandoned, ping me and I will take the GCD hash on its own.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4fe4918

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_asan_ubsan) / Hung check failed, possible deadlock found cancelled DROP TABLE prometheus wedged 2719 s in waitTableFinallyDropped via StorageTimeSeries::dropInnerTableIfAny, convoying 6 DROP/DETACH DATABASE victims behind the DDL guard #113397 (external, open)
Stress test (amd_asan_ubsan) / Sanitizer (STID: 1367-26c6) LeakSanitizer, 1008 blocks, 0 direct, all indirect #113397 (external, open)

Not PR-caused: this branch changes two compression codecs and one stateless test. The new test
04861_codec_hash_float_width is OK 242 times in this run, and neither failure touches
src/Compression. The root of the hang is a PromQL carrier
(log_comment: 04811_promql_topk_bottomk_limitk.sql), reached only when
enable_materialized_cte is force-enabled by #113772, which merged into the base of this build.

Both rows resolve to the same holder defect rather than to two independent failures. The leak
artifact carries resolveMaterializingCTEs (11 blocks), DelayedMaterializingCTEsStep (16) and
MaterializedCTE (61) with zero direct blocks, which is the materialized-CTE plan self-reference
cycle #113397 fixes; a leaked plan graph pins every StoragePtr it carries, so
isSharedPtrUnique never releases the drop-queue entry and the cancelled DROP waits forever.
#113397 is absent from this build: MaterializingCTEStep.h at 41499e3ada3b8063 still holds the
strong MaterializedCTEPtr materialized_cte member it converts to a weak pointer.

Four merged candidates were checked and deliberately not linked, because each is already an
ancestor of the failing build (behind_by = 0), so none of them resolves this: #97586, #113263,
#113504, #107604.

Build (arm_release) / Post Hooks also appears as a CIDB row, but that check's GitHub
conclusion is success and its praktika result is OK (Failures: 0/4), so it is bookkeeping
noise rather than a failure.

Session id: cron:our-pr-ci-monitor:20260810-230000

@rienath rienath left a comment

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.

Looks good! @kshcherbatov is right, let's move the GCD fix to this PR and add a test. From atomicity and revert standpoint, it's better to have it here. We will go forward with the #113798 in any case

A Compact part shares one CompressedStream between columns whose codec hashes
are equal (MergeTreeDataPartWriterCompact::addStreams). CompressionCodecGCD
hashed only its codec description, which carries no arguments, so two GCD
columns of different width mapped to the same stream and the column that lost
the race was compressed with the other one's divisor width. The result was a
worse compression ratio that also depended on the declaration order. Data
round-trips either way, because the divisor width is stored in the GCD block
header.

Requested by rienath on ClickHouse#114189 to keep the whole updateHash class of fixes in
one PR, so a revert stays atomic. The GCD arm of
04861_codec_hash_type_derived_params fails without this change and passes with
it; the test is renamed because it no longer covers only float width.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai groeneai changed the title Hash the per-column float width in the ALP and FPC codecs Hash the type-derived parameter in the ALP, FPC and GCD codecs Aug 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done in f390f66: CompressionCodecGCD::updateHash now hashes gcd_bytes_size.

Test coverage is in the same file, renamed to 04861_codec_hash_type_derived_params since it no longer covers only float width. The GCD arm mixes UInt16 and UInt64 in a Compact part and asserts two things: mixed-width bytes equal two single-column tables, and the result is independent of declaration order. Both assert 0 on the parent commit and 1 with the fix, 5/5 runs failing before and 10/10 passing after under randomized settings. A Wide-part control passes in both directions, which confirms the oracle measures stream sharing rather than an incidental byte difference. Round-trip is unaffected either way, since GCD stores the width in its own block header.

Title, changelog and description now enumerate all three codecs.

One note on #113798: its updateHash hunk adds gcd_bytes_size and is_signed_type as two adjacent lines, so whoever lands second will see a small conflict here. is_signed_type does not exist in master yet, so it is not something I can take in this PR.

I did not change the changelog category. It is currently Improvement. FPC and GCD are not experimental, so Bug Fix (user-visible misbehavior in an official stable release) is arguably the better fit given the CANNOT_COMPRESS rejection; happy to switch it if you agree.

@clickhouse-gh

clickhouse-gh Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 366fe60e4 with master bc1887c54 (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 705.75 MiB 702.73 MiB -3.02 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, 24 s compile time in total, 10 of them have a recent master baseline.

Job report

kshcherbatov added a commit to kshcherbatov/ClickHouse that referenced this pull request Aug 17, 2026
Polish comments explaining the codec's intent (why GCD is computed over
magnitudes for signed types, why `compressDataForType`'s template
parameter `T` is always unsigned) and trim the two regression tests to
focus on the negative-value/signedness bug this branch actually fixes,
dropping coverage that duplicated other tests or was out of scope.

Also revert the `hash.update(gcd_bytes_size);` line added to
`CompressionCodecGCD::updateHash` in f789550. That line worked
around a larger-scope issue: `updateHash` for several codecs does not
account for type-resolved parameters, so structurally identical
`CODEC(...)` columns of different types can share a `CompressedStream`
and silently borrow each other's decoding parameters. This class of bug
is tracked and fixed for all affected codecs by ClickHouse#113940 / PR ClickHouse#114189,
which will merge before this branch, so the one-off fix here is
removed to avoid scope creep and duplicated logic. The corresponding
`04813_gcd_codec_hash_signedness` width-collision scenario is dropped
for the same reason.

Separately, a codec instance can be cached and reused keyed off its
textual `CODEC(...)` description, which can serve a suboptimal cached
codec for a superficially identical declaration on a different column
type. This is a distinct, larger-scope issue tracked as ClickHouse#114202 and is
not addressed here.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f390f66

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Cannot start clickhouse-server startup abort loading a URL-engine table whose named collection is missing (Code: 669, There is no named collection 04320_url_engine_dispatch_partition_and_format_test_1_nc, while attaching test_1.04320_url_engine_dispatch_partition_and_format_test_1_n__fuzz_4) #110529 (ours, open)

Not PR-caused: this PR's diff is the three codec files plus its own test, and it greps 0 for every
frame in the failure (NamedCollectionsFactory, StorageURL, DatabaseOrdinary, table loading).
Breadth of the signature over 14 days: 10 rows across 9 distinct PRs, including 1 on master.

Session id: cron:our-pr-ci-monitor:20260818-010000

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
@rienath

rienath commented Aug 19, 2026

Copy link
Copy Markdown
Member

Sync, wake up...

@rienath

rienath commented Aug 20, 2026

Copy link
Copy Markdown
Member

@groeneai merge master or make an empty commit. The sync was not created because of github outage

The sync PR for ClickHouse#114189 was never created because of a GitHub outage, so the
already-approved PR could not progress. Requested by rienath on the PR.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-improvement Pull request with some product improvements labels Aug 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@rienath Pushed an empty commit, head is now 6e309ff47fe2e8a2a1b0cd670c872c82a607d1a1. The CH Inc sync status has not posted yet, but it took about 75 minutes on the previous head, so I will report back here if it still does not get created.

@alexey-milovidov alexey-milovidov left a comment

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.

LGTM

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6e309ff

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_debug) / Logical error "Bucket 0 is pushed twice" (STID 2508-47d5) pre-existing flake in the distributed partial-aggregation path (30d breadth: 5 distinct PRs, 0 on master) #114523 (external, open)

Session id: cron:our-pr-ci-monitor:20260820-220000

@rienath

rienath commented Aug 22, 2026

Copy link
Copy Markdown
Member

@groeneai fix was merged. Resolve conflicts and merge master

Resolve the CompressionCodecGCD::updateHash conflict as a union of both sides.
Master's ClickHouse#113798 added is_signed_type to the hash; this branch added
gcd_bytes_size. GCD takes no AST arguments (setCodecDescription("GCD", {})),
so both values are derived from the column type and neither reaches
updateTreeHash. Keeping only one still lets two CODEC(GCD) columns that differ
in the other value share a CompressedStream in Compact parts.
Master's ClickHouse#113798 added <Common/SipHash.h> to this file, so the copy this
branch added is now redundant. The ALP and FPC siblings carry one each.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master, head is now 366fe60e4ec47063ec9ad89ac4a4f49731240d8e and the PR is mergeable again.

One conflict, in CompressionCodecGCD::updateHash: #113798 added hash.update(is_signed_type) there while this branch added hash.update(gcd_bytes_size). I kept both. GCD takes no codec arguments, so both values come from the column type and neither reaches updateTreeHash - dropping either one still lets two CODEC(GCD) columns that differ in it share a stream in a Compact part. Verified by building the is_signed_type-only variant: the two GCD byte-equality assertions in 04861 fail on it and pass with both lines. 04813 and 04814 from #113798 pass unchanged.

Also dropped the duplicate <Common/SipHash.h> the merge left in that file, since #113798 already added it.

@rienath
rienath added this pull request to the merge queue Aug 23, 2026
Merged via the queue into ClickHouse:master with commit 58d7129 Aug 23, 2026
178 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 23, 2026
@clickgapai

Copy link
Copy Markdown
Contributor
Reproducer
-- clickhouse local (or a server); Compact part, two columns of different
-- value width under the same codec name.

-- 1) ALP: valid INSERT is rejected (26.3+)
SET allow_experimental_codecs = 1;
CREATE TABLE alp_reject (n UInt64, f64 Float64 CODEC(ALP), f32 Float32 CODEC(ALP))
ENGINE = MergeTree ORDER BY n
SETTINGS min_rows_for_wide_part = 1000000000, min_bytes_for_wide_part = 1000000000;
INSERT INTO alp_reject SELECT number, sin(number) * 1000, sin(number) * 1000 FROM numbers(101);
-- Code: 270. DB::Exception: Cannot compress with ALP codec, data size 404 is not aligned to 8. (CANNOT_COMPRESS)

-- 2) FPC: no error, just ~10% worse compression (all branches)
CREATE TABLE fpc_mix (f32 Float32 CODEC(FPC), f64 Float64 CODEC(FPC)) ENGINE = MergeTree ORDER BY tuple()
SETTINGS min_rows_for_wide_part = 1000000000, min_bytes_for_wide_part = 1000000000;
CREATE TABLE fpc_32 (f32 Float32 CODEC(FPC)) ENGINE = MergeTree ORDER BY tuple()
SETTINGS min_rows_for_wide_part = 1000000000, min_bytes_for_wide_part = 1000000000;
CREATE TABLE fpc_64 (f64 Float64 CODEC(FPC)) ENGINE = MergeTree ORDER BY tuple()
SETTINGS min_rows_for_wide_part = 1000000000, min_bytes_for_wide_part = 1000000000;
INSERT INTO fpc_mix SELECT sin(number) * 1000, sin(number) * 1000 FROM numbers(20000);
INSERT INTO fpc_32 SELECT sin(number) * 1000 FROM numbers(20000);
INSERT INTO fpc_64 SELECT sin(number) * 1000 FROM numbers(20000);
SELECT (SELECT sum(data_compressed_bytes) FROM system.parts WHERE table = 'fpc_mix' AND active)
     = (SELECT sum(data_compressed_bytes) FROM system.parts WHERE table IN ('fpc_32','fpc_64') AND active);
-- observed 0 (238887 vs 217185 bytes); expected 1

▶ Run on ClickHouse Fiddle

Results:

  • Reproduces on: 26.7, 26.6, 26.5, 26.3, 25.8
  • Tested versions: master, 26.7, 26.6, 26.5, 26.3, 25.8
  • Also tested (unsupported, context only): 26.2 reproduces
  • Fix merged on master (not re-verified: tested master build predates this PR's merge — a clean verdict is not attributable to the fix). The releases listed above still have the bug and need the backport.

CC component owner: @alexey-milovidov @Algunenano

Analysis metadata

comp-codecs · Severity P2 · Finding phase_d_pr114189

  • Verified against master build 4a31c250cf20
  • Could not test: master
Introducing change: not identified
  • No clean release baseline found and no lower bound established — source-build bisect is required to pin the introducing PR (not yet performed).
  • Secondary components: comp-testing

@groeneai

Copy link
Copy Markdown
Collaborator Author

Backport request: v25.8-must-backport

@alexey-milovidov could you apply v25.8-must-backport here? Per
tests/ci/cherry_pick_branches.py::select_backport_branches that single label expands to
25.8, 26.3, 26.5, 26.6, 26.7, which is exactly the active release set.

Affectedness measured against the official per-branch builds, not inferred. FPC needs no
experimental setting, so this is reachable from ordinary use on every release:

build ALP mixed-width insert FPC compressed bytes, shared vs separate
master 97a238df (26.8.1.1940) ok, 101 rows 217185 == 217185
26.7.6.9 Code: 270 ... data size 404 is not aligned to 8 238887 vs 217185
26.6.4.13 same 238887 vs 217185
26.5.8.14 same 238887 vs 217185
26.3.22.4 same 238887 vs 217185
25.8.33.4 Code: 432 Unknown codec family: ALP 238887 vs 217185

The master row is attributable to this fix, since 58d7129b is an ancestor of 97a238df. The
21702-byte gap is the compression lost to the shared stream, 10.0% on 20k rows.

All five branches conflict, so the robot will open cherry-pick PRs rather than take the
resolved-tree fast path. Two things will bite whoever resolves them:

  1. is_signed_type comes from Fix GCD codec behavior on signed values #113798, which is on master but is not an ancestor of any release
    branch (0 occurrences in CompressionCodecGCD.cpp there). The conflict block offers both
    hash.update(gcd_bytes_size) and hash.update(is_signed_type), and taking it verbatim will not
    compile. Keeping only gcd_bytes_size preserves this fix: the GCD case in 04861 is UInt16
    vs UInt64, so it differs in width and not in signedness.
  2. On the release branches ICompressionCodec.h only forward-declares SipHash and
    CompressionCodecGCD.cpp carries no <Common/SipHash.h> include, so that include has to
    survive the resolution or hash.update fails on an incomplete type. The 26.x ALP conflict is in
    the include block as well, not at the fix site.

CompressionCodecFPC.cpp auto-merges cleanly on all five. CompressionCodecALP.cpp does not exist
on 25.8, so that branch gets the FPC and GCD halves only.

@rienath

rienath commented Aug 23, 2026

Copy link
Copy Markdown
Member

No need backport. ALP is experimental. Improved ratios of FPC and GCD are nice, but we don't backport improvements

@groeneai

Copy link
Copy Markdown
Collaborator Author

Understood, no backport. Withdrawing the label request above.

@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.3, 26.5, 26.6, 26.7. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

7 participants