Skip to content

Fix low_cardinality_allow_in_native_format=0 handling in parallel blocks marshalling - #107319

Merged
azat merged 1 commit into
ClickHouse:masterfrom
azat:marshalling-low-cardinality-fix
Jun 12, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
azat:marshalling-low-cardinality-fix

Conversation

@azat

@azat azat commented Jun 12, 2026

Copy link
Copy Markdown
Member

Note, I need this for chdig, since the driver I'm using does not support reading LowCardinality

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):

Fix low_cardinality_allow_in_native_format=0 handling in parallel blocks marshalling

With enable_parallel_blocks_marshalling enabled (the default) and low_cardinality_allow_in_native_format = 0, distributed queries over LowCardinality columns returned corrupted data or failed on the initiator with:

Code: 33. DB::Exception: Cannot read all data. Bytes read: 1. Bytes expected: 4. (CANNOT_READ_ALL_DATA)

convertColumnsToBLOBs serialized columns into ColumnBLOB on the remote replica using their actual types (e.g. LowCardinality(String)), ignoring the setting. NativeWriter::write then applied recursiveRemoveLowCardinality only to the type (it is a no-op for a ColumnBLOB column) and announced the stripped type (String) on the wire, so the initiator deserialized the LowCardinality-formatted blob with the plain type's serialization.

Strip LowCardinality from the column before serializing it into the blob, mirroring what NativeWriter does for regular columns.

…locks marshalling

With `enable_parallel_blocks_marshalling` enabled (the default) and
`low_cardinality_allow_in_native_format = 0`, distributed queries over
`LowCardinality` columns returned corrupted data or failed on the
initiator with:

    Code: 33. DB::Exception: Cannot read all data. Bytes read: 1. Bytes expected: 4. (CANNOT_READ_ALL_DATA)

`convertColumnsToBLOBs` serialized columns into `ColumnBLOB` on the
remote replica using their actual types (e.g. `LowCardinality(String)`),
ignoring the setting. `NativeWriter::write` then applied
`recursiveRemoveLowCardinality` only to the type (it is a no-op for a
`ColumnBLOB` column) and announced the stripped type (`String`) on the
wire, so the initiator deserialized the `LowCardinality`-formatted blob
with the plain type's serialization.

Strip `LowCardinality` from the column before serializing it into the
blob, mirroring what `NativeWriter` does for regular columns.

Co-Authored-By: Claude Fable 5 <[email protected]>
@azat
azat requested a review from nickitat June 12, 2026 12:59
@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2603a4d]

Summary: ❌

job_name test_name status info comment
Unit tests (asan_ubsan, function_prop_fuzzer) FAIL
FunctionsStress.stress FAIL cidb, issue
AllTests FAIL cidb

AI Review

Summary

This PR fixes low_cardinality_allow_in_native_format = 0 with parallel block marshalling by stripping LowCardinality from non-Tuple columns before ColumnBLOB serialization, so the detached payload matches the type later announced by NativeWriter. The touched send paths both pass the query setting through, receiver-side detached serialization still adapts/casts after unmarshalling, and the added shard stateless test covers the failing remote-query path.

Missing context / blind spots
  • ⚠️ I could not run the new stateless test locally because this checkout has no build or build_* binary. The Praktika CI report linked from the PR comment showed no failed jobs at review time.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 12, 2026
@nickitat nickitat self-assigned this Jun 12, 2026
@azat
azat enabled auto-merge June 12, 2026 13:22
@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 21/32 (65.62%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@azat
azat added this pull request to the merge queue Jun 12, 2026
Merged via the queue into ClickHouse:master with commit 02a5100 Jun 12, 2026
164 of 166 checks passed
@azat
azat deleted the marshalling-low-cardinality-fix branch June 12, 2026 18:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 12, 2026
alexey-milovidov added a commit that referenced this pull request Jun 13, 2026
…r cap

`arrayResize` read its size argument via `IColumn::getInt`, which for a
`Decimal` column returns the raw unscaled value rather than the logical one.
As a result `arrayResize([1, 2, 3], 1.5::Decimal(2, 1))` resized to 15
elements instead of 1, inconsistently with `Float` and integer sizes (which
truncate towards zero). A tiny fractional value such as
`-0.000000000000000000000006116852::Decimal(38, 30)` has a raw value of
`-6116852`, so the array was padded with millions of elements.

Convert a `Decimal` size to a plain integer before resizing, so its real
(rounded towards zero) value is used.

This was found by `FunctionsStress.stress` (`function_prop_fuzzer`), where the
above query made a worker pad ~6 million elements one by one and get reported
as stuck. The existing `arrayResize` argument cap did not prevent it: it only
bounds the value from above (`value > limit`), so a large-magnitude negative
size slips through, and for a `Decimal` it compares the logical value while the
function used the raw one. Make the cap bound the magnitude instead
(`abs(value) > limit`) so large negative sizes are clamped too.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107319&sha=2603a4dd53466ae560f080b1a55ed3009d28fa9e&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%2C%20function_prop_fuzzer%29
Related: #107319

Co-Authored-By: Claude Opus 4.8 <[email protected]>
azat added a commit to azat-archive/chdig that referenced this pull request Aug 12, 2026
clickhouse-rs does not support Map(LowCardinality), but we do not have
such type in our queries, so we do not need to touch
low_cardinality_allow_in_native_format, besides there is [1]

  [1]: ClickHouse/ClickHouse#107319

So instead of tunning 2 settings, better tune 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

3 participants