Skip to content

Fix a crash of a window function over a Tuple with a sparse element - #115705

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-window-function-sparse-tuple
Aug 29, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-window-function-sparse-tuple

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

WindowTransform::appendChunk materializes the columns that the window functions read with
convertToFullColumnIfSparse, which only looks at the top level of a column. A Tuple is never
sparse itself, but its elements can be, so a Tuple with a sparse element passed through unchanged
and the aggregate function then read it as a full column. groupConcat(t) OVER () over a
Tuple(a String) whose element is serialized as ColumnSparse crashes the server.

The aggregation path had the same problem and was fixed in #108790 by using recursiveRemoveSparse;
this does the same for the window functions.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix a crash of a window function over a Tuple with a sparse element, for example groupConcat(t) OVER ().


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

Version info

  • Backported to: 26.8.1.2034, 26.7.6.46, 26.6.4.66, 26.3.29.6

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6682d6c]

Summary: ✅


AI Review

Summary

This PR fixes the WindowTransform materialization gap for window-function inputs by switching the read path from top-level-only wrapper stripping to recursive convertToFullIfWrapped, then keeping the existing recursive LowCardinality removal. The regression test is focused and now covers both a Tuple(String) sparse element and a sparse Tuple(Nullable(String)) element. The two earlier review issues visible on the PR discussion are addressed in the current diff, and I did not find a remaining correctness, compatibility, or test-coverage problem in the final change.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 6682d6c.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.80% 80.80% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6682d6cae with master ae36a6931 (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 710.11 MiB 707.05 MiB -3.06 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

7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline.

Job report

`recursiveRemoveSparse` only descends through `ColumnReplicated` and
`ColumnTuple`, so a sparse leaf hidden under a `ColumnNullable` (for
example `Tuple(a Nullable(String))` with
`nullable_serialization_version = 'allow_sparse'`) survived into the
window transform. Use `convertToFullIfWrapped`, which recursively strips
`Const`/`Replicated`/`Sparse` through every subcolumn, and extend the
test with a nullable tuple element.
…the test

The previous settings produced `Default` serialization for the nullable
element, so the case did not exercise the sparse path.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, the following CI failures on this PR are unrelated to it — please investigate and provide fixes in separate PRs (link them here if already in progress):

The AST fuzzer (amd_debug, targeted) failure is already tracked by #114611.

@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Aug 22, 2026
Comment thread contrib/aws-c-http Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Both are unrelated to this PR. The first one is also a different defect from what the STID suggests.

Bad cast ... to ColumnLowCardinality (STID 4054-5dad). That STID pools three different callers, so the cross-PR count is misleading:

Carrier is 00814_replicated_minimalistic_part_header_zookeeper.sh. The stress fuzzer rewrote that test's ALTER TABLE part_header_r1 MODIFY COLUMN y String into MODIFY COLUMN y LowCardinality(String), so the applied mutation was (MODIFY COLUMN y LowCardinality(String)). Part all_0_1_6_5 was under MutateFromLogEntryTask for that mutation seconds before the abort, and SELECT x, length(y) FROM part_header_r1 ORDER BY x then read the part with the alter conversion for y going through a CAST chain built for a LowCardinality source while the reader supplied a plain ColumnVector<unsigned long>. I am reducing that to a deterministic repro and will open a separate PR.

NATS test_nats_restore_failed_connection_without_losses_on_write. The in-flight fix is #115343. My earlier #112828 merged on 2026-08-13 and did not close the family, so the failures counted here are all post-merge.

@groeneai

Copy link
Copy Markdown
Collaborator

Fix for the Bad cast half: #115964.

One correction to what I wrote above. The fuzzer did not rewrite the test's ALTER TABLE part_header_r1 MODIFY COLUMN y String; that statement ran as written, and the LowCardinality came from separate internal ALTERs the fuzzer issued alongside it. The type direction is therefore the opposite of what I described, which is why my first repro attempt came back clean.

The actual root cause is not in performRequiredConversions. length(y) is answered from the y.size subcolumn, and that rewrite keys on the metadata snapshot type. With an unmaterialized MODIFY COLUMN y String the snapshot says String while the part still holds LowCardinality(String), which has no size subcolumn. MergeTreeReaderCompact already refuses such a read; MergeTreeReaderWide did not, and instead parsed the dictionary indexes stream as string lengths into a ColumnVector<UInt64>. The substreams cache is per storage column, so the full y read adopted that column and the alter-conversion CAST class-cast it. The fix moves the presence check into IMergeTreeReader so both readers share it.

That closes one arm of STID 4054-5dad, not the STID.

alexey-milovidov and others added 3 commits August 25, 2026 13:50
Commit f9f2810 unintentionally moved the `contrib/aws-c-http` gitlink
from `a9745ea9` to `8aefd899`. This PR is a `WindowTransform` fix and
should not change what we build; restore the pointer that `master` has.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexbakharew alexbakharew self-assigned this Aug 28, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 29, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #115705 to 26.8: Fix a crash of a window function over a Tuple with a sparse element
alexey-milovidov added a commit that referenced this pull request Aug 29, 2026
Two differences against 26.3 had to be reconciled:
- 26.3 has no `should_materialize` filter, so the fix applies to its
  materialize-every-column loop;
- 26.3 has no `convertToFullIfWrapped`: that is master's post-rename name, from
  #107773, which also split `LowCardinality` stripping out of it. The predecessor
  `convertToFullIfNeeded` is present here and performs the same recursion into
  subcolumns, which is the actual fix - the previous explicit
  `convertToFullColumnIfReplicated`/`Const`/`Sparse` chain only converted the top
  level, so a sparse element inside a Tuple stayed sparse.

The outer `recursiveRemoveLowCardinality` is kept as it was on this branch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
robot-clickhouse-ci-1 added a commit that referenced this pull request Aug 29, 2026
Cherry pick #115705 to 26.3: Fix a crash of a window function over a Tuple with a sparse element
robot-clickhouse added a commit that referenced this pull request Aug 29, 2026
alexey-milovidov added a commit that referenced this pull request Aug 29, 2026
Same two differences as the 26.3 cherry-pick: 26.6 has no `should_materialize`
filter, so the fix applies to its materialize-every-column loop, and it has no
`convertToFullIfWrapped` - that is master's name after #107773. The predecessor
`convertToFullIfNeeded` is present here and does the same recursion into
subcolumns, which is the fix: the explicit
`convertToFullColumnIfReplicated`/`Const`/`Sparse` chain only converted the top
level, leaving a sparse element inside a Tuple sparse.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
robot-clickhouse-ci-2 added a commit that referenced this pull request Aug 29, 2026
Cherry pick #115705 to 26.6: Fix a crash of a window function over a Tuple with a sparse element
robot-clickhouse added a commit that referenced this pull request Aug 29, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #115705 to 26.7: Fix a crash of a window function over a Tuple with a sparse element
clickhouse-gh Bot added a commit that referenced this pull request Sep 1, 2026
Backport #115705 to 26.6: Fix a crash of a window function over a Tuple with a sparse element
alexey-milovidov added a commit that referenced this pull request Sep 1, 2026
Backport #115705 to 26.3: Fix a crash of a window function over a Tuple with a sparse element
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
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]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…f upstream fixes

The stateless selection gets the upstream tests of the 34 backports of the residual audit
and of the two backports they depend on (ClickHouse#99085, ClickHouse#107562), 04627 (runnable with the gate's
loopback Keeper), and 10317/10318 (Parquet Decimal512): 152 tests. 04670 (needs pyarrow) and
00900 (a long load test whose skip list changed) run outside the gate.

known_defects.json: a fixed KD-UP entry per backport (fixed_by = its commit); KD-UP-108790
points at the ClickHouse#115705 backport, which carries its change; KD-UP-107663 records its ClickHouse#112601
dependency. Defects found by the release gate on the candidate 91efe1f244ce and fixed:
KD-D512-PERF-OVERFLOW-CHECKS (e91167f), KD-TEST-BLOCKCHAIN-TYPENAME (f006d0d),
KD-GATE-NO-KEEPER (095b89c). 80 entries, 0 open.

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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants