Skip to content

Fix a crash reading a Quantized codec subcolumn through a Merge table whose other table lacks the column - #123895

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-merge-quantized-subcolumn-of-missing-column
Oct 5, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-merge-quantized-subcolumn-of-missing-column

Conversation

@groeneai

@groeneai groeneai commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Reading the codes of a Quantized column (vec.quantized, vec.product_quantization_codebook) through a Merge table no longer crashes the server when another table of the Merge does not have the column.

Description

Closes #123866. Related: #123633 (the regression origin).

SELECT varSamp(cityHash64(vec.quantized)) FROM merge('t.*') crashes the server (SIGSEGV in ColumnConst::ColumnConst from ReadFromMerge::getModifiedQueryInfo) when one table has vec Array(Float32) CODEC(Quantized('product', ...)) and another has no vec; for the other quantization methods the query fails with SIZES_OF_ARRAYS_DONT_MATCH.

#123633 made Merge derive a subcolumn of a column a child does not have from the column's default value. That is right for subcolumns of the declared type (.null, tuple elements, sizes), but quantized and product_quantization_codebook are added by the codec's custom serialization and cannot be computed from a value in memory: for product there is no column at all, so IDataType::getSubcolumn returned null.

Changes:

  • StorageMerge.cpp: both places that fill a missing column (query tree substitution and stream path) derive the subcolumn from the default only when the declared type has it; otherwise it gets the default of its own type, as on 26.9.
  • IDataType::getSubcolumn throws NOT_IMPLEMENTED instead of returning a null column. This also turns getSubcolumn(materialize(vec), 'quantized') (a LOGICAL_ERROR today) and SELECT vec.quantized from a Memory table with a product codec (a SIGSEGV on 26.8/26.9) into an error.

The new test crashes the base server with the reported stack and passes with the fix (50/50 randomized runs); reverting any one of the three changes makes it fail. Not for changelog: the Merge crash is master-only (26.9 returns zero bytes), and the other paths need the experimental enable_quantized_codec.


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

Version info

  • Merged into: 26.10.1.1618-master (included in 26.10 and later)

…child lacks the column

ClickHouse#123633 made `Merge` derive a subcolumn of a column a child table does not have from the
column's default value. That holds for subcolumns of the declared type, but the `quantized`
and `product_quantization_codebook` subcolumns of a `Quantized` codec column come from the
codec's custom serialization and cannot be computed from an in-memory value: for `product`
there is no column at all, so `IDataType::getSubcolumn` returned null and
`getModifiedQueryInfo` built a `ColumnConst` over it (SIGSEGV); for the other methods the
codes of the default `[]` were rejected with SIZES_OF_ARRAYS_DONT_MATCH.

Both places that fill a missing column (the query tree substitution and the stream path)
now derive the subcolumn from the default only when the declared type has it, and give
other subcolumns the default of their own type, which is what releases before ClickHouse#123633 did.

`IDataType::getSubcolumn` now throws NOT_IMPLEMENTED instead of returning a null column,
which every caller dereferenced. This also turns `getSubcolumn(materialize(vec), 'quantized')`
(LOGICAL_ERROR "Empty column was returned") and reading `vec.quantized` from a Memory table
with a `product` codec (null dereference) into an error. `tryGetSubcolumn` is unchanged: its
callers use null as "not available".

Closes ClickHouse#123866

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (3 nits, none blocking).

# Sev Finding Verdict Evidence / action
1 💡 isSubcolumnOfDefaultValue checks only the top-level Merge type, so a Quantized type that Merge wraps into a Variant still derives vec.Array(Float32).quantized of a missing column from the default AGREE, noted, not blocking That read now gives NOT_IMPLEMENTED instead of a crash; the table with the codec column already fails with ILLEGAL_COLUMN in that shape
2 💡 No test statement for SELECT vec.quantized from a Memory table with a product codec AGREE, noted, not blocking Measured by hand (abort on base, NOT_IMPLEMENTED with the fix); the IDataType::getSubcolumn change is pinned by the getSubcolumn(materialize(vec), 'quantized') statement
3 💡 The new throw line in IDataType::getSubcolumn is 150 columns wide AGREE, noted, not blocking none

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261004-193600

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: a product-codec table plus a table without vec under merge(), then the reported query; 100% on the base build (debug assertion in ColumnConst::ColumnConst, the issue's stack).
b Root cause explained? #123633 derives a subcolumn of a missing column from the default value; the codec's quantized/product_quantization_codebook subcolumns come from its custom serialization and have no column for an in-memory value, so IDataType::getSubcolumn returned null.
c Fix matches root cause? Yes: the derivation is limited to subcolumns of the declared type at both Merge sites (one helper), and the throwing getSubcolumn no longer returns null.
d Test intent preserved / new tests added? New 05321_merge_quantized_codec_subcolumn: report query, product and int8 codes, codebook, size0, a Distributed child, in-memory getSubcolumn.
e Both directions demonstrated? Base server dies on the first statement; fixed build passes 50/50 randomized runs; reverting each of the three changes alone makes the test fail.
f Fix is general across code paths? Both #123633 sites; the getSubcolumn function, the Memory fill and MergeTree missing-column fill go through the same throwing call; tryGetSubcolumn callers unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? product and int8; structural size0 still derived; Const recurses into the checked branch; the codec rejects any wrapper around the column.
h Backward compatible? (maintainer-approved exception only) Yes: restores the 26.9 result for the Merge reads; no setting, format or metadata change.
i Invariants and contracts preserved? IDataType::getSubcolumn never returns null; tryGetSubcolumn keeps null as "not available"; the stream path fills (name, type) as before #123633.

Session id: cron:clickhouse-impl-slot-6:20261004-152100

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d6e2c04]

Summary: ✅


AI Review

Summary

This PR narrows StorageMerge's missing-column fallback so only subcolumns that belong to the declared value are derived from the parent default, while serialization-defined Quantized companion subcolumns fall back to their own type defaults instead. It also hardens IDataType::getSubcolumn to throw NOT_IMPLEMENTED instead of dereferencing a null in-memory subcolumn. I did not find an unresolved correctness, compatibility, or testing gap in the current diff.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit d6e2c04.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 91.80% -0.30%
Branches 79.70% 79.70% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-storage-merge Merge table engine (logical union over tables) and related mechanics. labels Oct 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d6e2c04e8 with master 98f3cad68 (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8d70b14

Every failure below has an owner: a fixing PR (mine 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
Stateless tests (arm_binary, parallel) / 02482_load_parts_refcounts flaky, not from this PR (all 46 same-settings reruns pass): after DETACH/ATTACH, a reloaded outdated part of a ReplicatedMergeTree table reports refcount 2 instead of 1. This PR changes only the Merge subcolumn path and IDataType::getSubcolumn, nothing in part loading. 4 unrelated PRs in 90 days a fix task is created (investigating at full effort, fixing-PR link to follow here)
Mergeable Check, PR rollups, red only because of the row above a fix task is created (the one above)

All 146 checks completed, Finish Workflow is green and CH Inc sync passed. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261005-010535

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 02482_load_parts_refcounts created: #123934

@PedroTadim PedroTadim self-assigned this Oct 5, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@alexey-milovidov this seems to fix a regression from #123923

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai merge with master and resolve the conflict

…o fix-merge-quantized-subcolumn-of-missing-column

# Conflicts:
#	src/Storages/StorageMerge.cpp
@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in d6e2c04. The only conflict was the include list in src/Storages/StorageMerge.cpp (master dropped includes it no longer uses; I kept just the new DataTypes/DataTypeFactory.h), so the PR diff against master is unchanged. Rebuilt; 05321_merge_quantized_codec_subcolumn and 05317_merge_subcolumn_of_missing_column pass 20/20 with randomized settings.

@PedroTadim
PedroTadim added this pull request to the merge queue Oct 5, 2026
Merged via the queue into ClickHouse:master with commit f4583f3 Oct 5, 2026
149 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 5, 2026
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 comp-storage-merge Merge table engine (logical union over tables) and related mechanics. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-not-for-changelog This PR should not be mentioned in the changelog 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.

SELECT ... FROM merge() with subcolumn access causes SIGSEGV in IDataType::getSubcolumn via ColumnConst construction

3 participants