Skip to content

Fix ColumnBLOB assertion failure in prepareTotals - #98783

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-blob-column-cut-totals
Mar 12, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-blob-column-cut-totals

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fix assertion failure assertTypeEquality in IColumn::cut called from prepareTotals in IOutputFormat
  • The crash occurs in debug/sanitizer builds when a distributed query with WITH TOTALS and function-level arrayJoin is executed across multiple shards
  • Root cause: BlocksMarshallingStep wraps totals columns in ColumnBLOB for network transfer, but ColumnBLOB::cloneEmpty returns the wrapped column type, not ColumnBLOB, causing a type mismatch when prepareTotals tries to cut totals to 1 row
  • Fix: convert ColumnBLOB back to the wrapped column before cutting in prepareTotals

Closes #98700

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=83bbc94a67bd1623704f63e93be899affa30b313&name_0=MasterCI&name_1=AST%20fuzzer%20%28arm_asan%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Test plan

  • Added regression test 04027_totals_blob_columns_cut that reproduces the issue with remote('127.0.0.{1,2}', view(... WITH TOTALS)) WHERE arrayJoin(...)
  • Verify CI passes (AST fuzzer arm_asan specifically)

🤖 Generated with Claude Code


Note

Low Risk
Small, localized change to ColumnBLOB behavior plus a regression test; main risk is unintended overhead/behavior differences when cut() forces BLOB conversion, but it’s only exercised in narrow totals-slicing paths.

Overview
Prevents prepareTotals from triggering a debug/sanitizer assertion when it slices multi-row totals by adding a ColumnBLOB::cut() override that delegates to the underlying wrapped/deserialized column.

Adds a distributed regression test (04027_totals_blob_columns_cut) reproducing the remote(...) WITH TOTALS + arrayJoin scenario and asserting the query completes without crashing.

Written by Cursor Bugbot for commit 21760fc. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.600

When a distributed query with WITH TOTALS and function-level
`arrayJoin` in WHERE/QUALIFY is executed across multiple shards,
the totals may have multiple rows (expanded by arrayJoin).
`BlocksMarshallingStep` wraps columns in `ColumnBLOB` for network
transfer via `addSimpleTransform` which also applies to the totals
port. Then `prepareTotals` in `IOutputFormat` tries to cut the
totals to 1 row, but `ColumnBLOB::cloneEmpty` returns the wrapped
column type (not `ColumnBLOB`), causing an assertion failure in
debug/sanitizer builds.

Fix by converting `ColumnBLOB` back to the wrapped column before
cutting in `prepareTotals`.

Closes #98700

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=83bbc94a67bd1623704f63e93be899affa30b313&name_0=MasterCI&name_1=AST%20fuzzer%20%28arm_asan%29

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

clickhouse-gh Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [21760fc]

Summary: ✅

/// ColumnBLOB stores serialized/compressed column data for network transfer.
/// It cannot be cut directly because its cloneEmpty returns the wrapped column type.
/// Convert it back to the regular column before cutting.
if (const auto * col_blob = typeid_cast<const ColumnBLOB *>(column.get()))

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.

I think, instead, ColumnBLOB should implement cut and all other methods correctly.

alexey-milovidov and others added 2 commits March 5, 2026 03:20
The query uses `WITH TOTALS`, so the output includes the totals row
(data, empty line, totals). The reference was missing the totals part.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
alexey-milovidov and others added 5 commits March 5, 2026 22:57
Move the fix from the call site to the `ColumnBLOB` class itself:
override `cut` to materialize the column (from blob or wrapped column)
before cutting. This is cleaner than special-casing `ColumnBLOB` in
every place that may call `cut`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…tput

The test `04027_totals_blob_columns_cut` was flaky because totals
propagation through `remote()` + `DISTINCT` depends on randomized
settings (e.g. `prefer_localhost_replica`). With some settings, totals
are not produced, causing the reference to mismatch.

Convert from .sql to .sh and use `head -1` to capture only the first
data line. The test still triggers the `ColumnBLOB::cut` code path
when totals are produced, but passes regardless of whether totals
propagate through the pipeline.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread src/Columns/ColumnBLOB.h
if (from_blob_task)
return convertFrom()->cut(start, length);
return wrapped_column->cut(start, length);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete fix: only cut overridden, other methods still crash

Medium Severity

ColumnBLOB::cut is overridden to delegate to the unwrapped column, but filter, permute, index, and all other similar methods still call throwInapplicable. As the reviewer noted, ColumnBLOB needs to implement these methods correctly rather than adding one-off overrides. The current approach creates an inconsistency where cut silently unwraps the column while sibling operations crash, making the fix fragile — any future code path that calls another method on a ColumnBLOB in a similar context will trigger the same class of assertion failure.

Additional Locations (1)

Fix in Cursor Fix in Web

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 for now. Other cases the author of ColumnBLOB, @nickitat, will fix.

@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.20% 83.90% +0.70%
Functions 23.60% 23.90% +0.30%
Branches 75.20% 76.40% +1.20%

PR changed lines: PR changed-lines coverage: 36.36% (4/11)
Diff coverage report
Uncovered code

@alexey-milovidov alexey-milovidov self-assigned this Mar 12, 2026
@alexey-milovidov
alexey-milovidov merged commit 69f4658 into master Mar 12, 2026
159 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-blob-column-cut-totals branch March 12, 2026 06:21
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 12, 2026
@nickitat

Copy link
Copy Markdown
Member

Sorry for the delay with the review. And thanks for fixing the problem. I made a slightly different fix in #99355

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

Labels

pr-ci 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.

Logical error: '(isConst() || isSparse() || isReplicated()) ? getDataType() == rhs.getDataType() : typeid(*this) == typeid(rhs)' (STID: 2508-29b8)

3 participants