Skip to content

Backport #115705 to 26.3: Fix a crash of a window function over a Tuple with a sparse element - #117073

Merged
alexey-milovidov merged 3 commits into
26.3from
backport/26.3/115705
Sep 1, 2026
Merged

alexey-milovidov merged 3 commits into
26.3from
backport/26.3/115705

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #115705
Cherry-pick pull-request #117058

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.3.29.6

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Aug 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [6a26447]

Summary: ✅



The backported test crashed on `26.3` with
`Bad cast from type DB::ColumnSparse to DB::ColumnString` already in the plain
`SELECT groupConcat(t)` query, before reaching the window function that this
backport is about.

`Aggregator::prepareAggregateInstructions` on `26.3` only strips top-level
sparsity from aggregate arguments. A column that is dense at the top level but
holds sparse subcolumns - exactly a `Tuple` with a sparse element - was left
un-materialized and took the regular `add` path, where
`SerializationString::serializeTextQuoted` does
`assert_cast<const ColumnString &>` and aborts.

Cherry-pick the one-line condition (and its test) from
#108790, which is on `master` but
was never backported: keep the argument sparse only when it is a genuine
top-level `ColumnSparse`, which is the only form the `addBatchSparse` fast path
consumes. `recursiveRemoveSparse` is a no-op when there is nothing sparse to
strip, so the dense and top-level-sparse paths are unchanged.

Verified against the `26.3` CI binary of this pull request: the reference output
of `04416_groupconcat_tuple_sparse_subcolumn` matches, and the query aborts
without this fix.

Related: #108790
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Both red jobs (Stateless tests (amd_asan, distributed plan, parallel, 1/2) and Stress test (amd_tsan)) aborted with Bad cast from type DB::ColumnSparse to DB::ColumnString in SerializationString::serializeTextQuoted <- SerializationTuple::serializeText <- GroupConcatData::insert <- Aggregator::executeWithoutKeyImpl. That is the plain SELECT length(groupConcat(t)) line of the backported test, not the window-function line this backport is about.

Root cause: Aggregator::prepareAggregateInstructions on 26.3 only strips top-level sparsity from aggregate arguments, so a Tuple that is dense at the top level but has a sparse element reached the regular add path. That was fixed on master by #108790 (merged 2026-06-29), which was never backported.

Pushed:

  1. a merge of 26.3 (the branch was 22 commits behind), and
  2. the prerequisite one-line Aggregator fix plus its test 04416_groupconcat_tuple_sparse_subcolumn cherry-picked from Fix Bad cast ColumnSparse to ColumnString in groupConcat over Tuple with sparse subcolumn #108790.

Verified against the 26.3 CI binary of this pull request that the crash reproduces without the fix and that the reference output of 04416_groupconcat_tuple_sparse_subcolumn matches on 26.3.

Note: the sibling backport #117076 (to 26.6) is red for exactly the same reason and needs the same prerequisite.

@alexey-milovidov
alexey-milovidov merged commit 97c1b5f into 26.3 Sep 1, 2026
34 checks passed
@alexey-milovidov
alexey-milovidov deleted the backport/26.3/115705 branch September 1, 2026 19:34
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
AGG: window function over a Tuple with a sparse element -> crash.
Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/115705.PROD263.txt).
Upstream patch unchanged, with its test(s): 04416_groupconcat_tuple_sparse_subcolumn, 05025_group_concat_window_sparse_tuple.
It also contains the fix of ClickHouse#108790 (groupConcat over a Tuple with a sparse String, 26.3 backport ClickHouse#117568, reproduced on the production build: evidence/fix_ci_20260925/upstream_repro/residual/108790.PROD263.txt): the 26.3 backport ClickHouse#117073 carries the identical Aggregator.cpp change and test 04416, so ClickHouse#108790 needs no separate commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants