Skip to content

Fix reading a LowCardinality subcolumn of Nullable(Tuple(...)) together with its parent - #112232

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-nullable-tuple-subcolumn-cow-inplace
Jul 30, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-nullable-tuple-subcolumn-cow-inplace

Conversation

@groeneai

@groeneai groeneai commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100394

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

Fixed reading a subcolumn of a Nullable(Tuple(...)) column whose element is a non-nullable LowCardinality(T) when the same query also reads the parent subcolumn. On a Compact part the parent returned wrong values, or the query failed with Unexpected return type from assumeNotNull, or the server was killed by a string_view hardening assertion, because the extracted subcolumn was deserialized into a LowCardinality(Nullable(T)) buffer whose substreams were then shared with the parent's read.

Description

Reported as an AST fuzzer (amd_debug) failure on #100394: CI report.

Logical error: 'Unexpected return type from assumeNotNull. Expected Tuple(b UInt32). Got Tuple(Nullable(UInt32)).'

This is not an analyzer or executor type-derivation problem. It is a regression from my own merged #108679, which introduced this read path. Carriers are master and 26.7: both #108679 commits are ancestors of 26.7 and of master, and of neither 26.6 nor anything older.

I measured the official release binaries 26.6.2.120 and 26.7.2.26 on the shape below, a Compact part with index_granularity = 1. 26.6 is correct on every query. On 26.7 the same queries give three different outcomes, selected by the element type and the projection list rather than by build flags:

query 26.6.2.120 26.7.2.26
SELECT x.a FROM t, the parent alone correct correct, the parent on its own is never wrong
SELECT x.a.b, x.a FROM t, LowCardinality(UInt32) element correct exit status 0, wrong values, and unstable: one row came back as (32438), (31553), (31542), (31253) on four runs where (2) is correct
SELECT x.a.b, x, x.a, isNull(x.a.b), assumeNotNull(x.a) FROM t correct exit status 49 on 4 of 4 runs, Unexpected return type from assumeNotNull. Expected Tuple(b UInt32). Got Tuple(Nullable(UInt32))
SELECT x.a.b, x.a FROM s, LowCardinality(String) element correct the process is killed by SIGABRT on 4 of 4 runs, exit status 134, no rows on stdout: libcxx/include/string_view:331: libc++ Hardening assertion __len <= ... failed

The last row is a real termination on a release build, and it is not a bad cast: the parent reads a nullable dictionary's index data under a declared type that is not nullable and derives a nonsensical string length, which libc++ hardening catches, and std::__libcpp_verbose_abort then calls std::abort(). Code: 49 and the termination are not the same condition selected by build type: on the same release binary the UInt32 element throws while the String element aborts. What the build type does change is the fate of that Code: 49, since LOGICAL_ERROR is turned into an abort in debug and sanitizer builds, which is the form the fuzzer reported.

Root cause

An extracted subcolumn of Nullable(Tuple(...)) with a non-nullable LowCardinality(T) element has its type promoted to LowCardinality(Nullable(T)), so that it can carry the parent's NULLs. MergeTreeReaderCompact therefore creates the result column already as LowCardinality(Nullable(T)), and SerializationNullableWithParentNullMap::deserializeBinaryBulkWithMultipleStreams built its per-range deserialization buffer from it with column->cloneEmpty().

The nested SerializationLowCardinality deserializes into that nullable-dictionary buffer and publishes it to the shared SubstreamsCache. The published substream is therefore not the on-disk LowCardinality(T) representation. A sibling reader of the same streams in the same query, that is the parent subcolumn x.a or assumeNotNull(x.a), adopts the cached column directly, so the parent holds a nullable-dictionary column while its declared type is still Nullable(Tuple(b LowCardinality(UInt32))), and the columnMatchesType post-condition in ExpressionActions throws.

Nothing mutates the published column. It simply was never the right representation. That is also why the parent on its own is always correct and only becomes wrong when the child is read in the same query: without the child read there is nothing in the cache to adopt.

Reproducer

SET enable_nullable_tuple_type = 1;
SET allow_suspicious_low_cardinality_types = 1;

CREATE TABLE t (x Tuple(a Nullable(Tuple(b LowCardinality(UInt32))))) ENGINE = MergeTree
ORDER BY tuple() SETTINGS index_granularity = 1, min_bytes_for_wide_part = 1000000000;
INSERT INTO t SELECT number % 2 ? tuple(NULL) : tuple(tuple(number)) FROM numbers(4);

SELECT x.a.b, x, x.a, isNull(x.a.b), assumeNotNull(x.a) FROM t;

The sharpest form of the bug needs no NULL in the data at all. On a table with zero parent-NULL rows, SELECT dumpColumnStructure(x.a) and SELECT x.a.b, dumpColumnStructure(x.a) must report the same dictionary size, and before this change the second one reported one entry more: the parent's dictionary gained a NULL placeholder purely because the child was also selected. That equality is asserted in the new test, and it is what distinguishes this fix from one that merely stops the exception.

The fix

Deserialize into a buffer that has the on-disk representation, and promote the private per-range column afterwards:

  • SerializationNullableWithParentNullMap now carries the pre-promotion (on-disk) type, passed in at construction by NullableSubcolumnCreator, which is where that type is still known. When it is set, the per-range buffer is built from it instead of from the promoted result column.
  • The new constructor parameter is folded into getHash(), otherwise the two flavours of the wrapper would collide on a single pooled instance.
  • No second promotion is added. With a genuinely non-nullable buffer, the existing promotion inside applyParentNullMapToExtractedSubcolumn becomes reachable and correct and remains the single promotion owner. It runs on the IColumn::mutated private column, so it can never touch the published one. Deleting it now makes the reproducer fail with Cannot apply a null map to LowCardinality(UInt32) with a non-nullable dictionary, so that line is load-bearing.

I first evaluated promoting on a private copy at the in-place promotion instead, and measured it to be a no-op: while the buffer is pre-promoted, that code is unreachable, since its guard is !nestedIsNullable().

Wide parts were measured and are not affected. With write_marks_for_substreams_in_compact_parts = 0 the reader takes the getSubcolumn branch, which already copies, so that path was correct too, and the new test pins that setting to 1 on its Compact tables so it keeps exercising the branch that was broken. A top-level Nullable(Tuple(b LowCardinality(UInt32))) without the outer Tuple is not a carrier either.

The change is in the serialization layer, so it also reaches StorageLog, which builds this wrapper through IDataType::getSerialization and likewise shares one SubstreamsCache per name in storage across subcolumn reads. I am not claiming a Log symptom: reading this shape from a Log table fails with Code: 33 on 26.6, on 26.7, and on master alike, so that is a separate pre-existing problem which this change neither causes nor fixes.

There is no on-disk format change, no new or changed setting, and the non-LowCardinality flavour of the wrapper is unchanged.

Testing

New stateless test 04651_nullable_tuple_lowcardinality_subcolumn_shared_cache, covering the reported query shape, both projection orders, the zero-parent-NULL structural assertion, the leaf types LowCardinality of UInt32, String, FixedString and Date, a multi-element inner tuple, an already-LowCardinality(Nullable(T)) leaf (which must not be de-nullabilised), a wide-part control, a top-level Nullable(Tuple(...)) control, and a multi-range read with a small max_block_size.

Every value in the test was cross-checked against an ENGINE = Memory twin of the same shape, which has no read path and therefore no substreams cache. The test fails on master and passes with this change. It ran 50 times with the default randomization, and the whole nullable_tuple test family ran 50 times each, 1150 runs in total, with no failures.

Note that the fix does not restore the 26.6 output of the child subcolumn: on a parent-NULL row x.a.b is \N here and was 1 or 3 on 26.6, because the promotion to LowCardinality(Nullable(T)) is exactly what #108679 added. What is restored is that reading the child no longer changes what the parent returns.

ColumnsOwnershipValidator (#110471) does not catch this, because the published column is legitimately shared. Only its representation was wrong. I did not extend the validator here.

26.7 is affected, so this wants v26.7-must-backport after merge.

Version info

  • Merged into: 26.8.1.474 (included in 26.8 and later)

groeneai and others added 3 commits July 27, 2026 22:52
…entation

An extracted subcolumn of a Nullable(Tuple(...)) column whose element is a
non-nullable LowCardinality(T) has its type promoted to
LowCardinality(Nullable(T)) so that it can carry the parent's NULLs. On a Compact
part MergeTreeReaderCompact therefore creates the result column already promoted,
and SerializationNullableWithParentNullMap built its per-range deserialization
buffer from it. The nested SerializationLowCardinality deserializes into that
nullable-dictionary buffer and publishes it to the shared substreams cache, so
the published substream is not the on-disk LowCardinality(T) representation. A
sibling reader of the same streams, that is the parent subcolumn or
assumeNotNull() over it, adopts the cached column directly and ends up holding a
nullable dictionary under a declared type that is not nullable. Depending on the
build that surfaces as wrong values, Code: 49, or an abort on a bad cast.

Nothing mutated the published column; it was never the right representation.

Build the buffer from the pre-promotion type instead, which NullableSubcolumnCreator
still knows and now passes to the wrapper, and let the existing promotion in
applyParentNullMapToExtractedSubcolumn promote the private per-range column
afterwards. That keeps a single promotion owner and leaves the published
substreams in the representation a reader of the parent expects. The new
constructor parameter enters getHash() so the two flavours of the wrapper cannot
share a pooled instance.

Promoting on a private copy at the in-place promotion instead was evaluated and
measured to be a no-op: while the buffer is pre-promoted, that code is
unreachable, because its guard is !nestedIsNullable().

Wide parts were unaffected, since MergeTreeReaderWide reads each column
separately, and so was the getSubcolumn branch taken when
write_marks_for_substreams_in_compact_parts is disabled, which already copies.

Regression from ClickHouse#108679, which introduced this read path. Affects master and 26.7.

Related: ClickHouse#100394
…t and the pooling hash

Length-prefix the on-disk type name in getHash(), matching SerializationNamed and
SerializationLowCardinality, the two in-tree serializations that fold a variable-length
string into a pooling key. No behaviour change: the name is the last field hashed and
SipHash mixes the total byte count, so no collision was reachable.

The test's leading comment stated the pre-fix behaviour as the expectation while the
assertion checks the opposite; reworded to the invariant actually asserted, which is that
the parent's dictionary must stay non-nullable and must not gain a NULL placeholder when
the child subcolumn is read in the same query. The reference is regenerated because the
file uses -- { echo }.

The PR description previously asserted three release-build symptoms without measuring
them, two of which contradicted each other. Measured on the official 26.6.2.120 and
26.7.2.26 binaries: 26.6 is correct on every query, while on 26.7 the same shape gives
unstable wrong values for a LowCardinality(UInt32) element, Code: 49 for the
assumeNotNull projection, and a libc++ string_view hardening termination for a
LowCardinality(String) element. The termination is real but is not a bad cast, so that
wording is gone.

Co-Authored-By: Claude Fable 5 <[email protected]>
The test's fails-without-the-fix property holds only on the branch of
MergeTreeReaderCompact::readData that reads through the parent-null-map
wrapper, which is selected by write_marks_for_substreams_in_compact_parts.
Pin it to 1 on the five Compact carrier tables so a server- or job-level
override cannot silently move the test onto the getSubcolumn branch, which
already copies and was never broken. The wide-part table and the deliberate
top-level non-carrier control are left alone.

Correct the wide-part comment as well. MergeTreeReaderWide keys its
SubstreamsCache by name in storage and does share one cache between a parent
subcolumn and its child, so "each column gets its own read" was the wrong
reason; wide is simply measured as unaffected.

The release-build symptom for a LowCardinality(String) element was
re-measured with the exit status taken directly from the binary invocation:
the process is killed by SIGABRT, exit status 134, on four of four runs with
no rows on stdout. The earlier record of status 0 came from reading $? after
a pipeline.
@groeneai

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

Pre-publication review by an independent model (engine: codex), plus my own cold review of the
resulting code, over 3 rounds: 10 gate findings and 8 of my own, 15 adjudicated verdicts
(11 AGREE, 4 DISAGREE), 2 fix rounds. Per round the gate reported 1, then 6, then 3 findings,
and my own review 3, then 3, then 2. The last round found no blocker and no major on either side.
Both blockers were about unmeasured claims in this description, not about the fix.

# Sev Finding Verdict Evidence / action
1 ❌ The description asserted three release-build symptoms that were never measured, two of them contradicting each other ("wrong values, Code: 49, or an abort with a bad cast" against "wrong results rather than an exception"), and the abort-with-a-bad-cast form is unreachable on a release build AGREE - fixed @ b9b2150c assert_cast is a bare static_cast under NDEBUG (src/Common/assert_cast.h:24-43), and Code: 49 is LOGICAL_ERROR, aborted only in debug or sanitizer builds (src/Common/Exception.cpp:99-110). Re-measured on the official 26.6.2.120 and 26.7.2.26 binaries instead of softening the text: 26.6 correct everywhere, 26.7 giving three outcomes selected by the element type. All three are now in the table above with their measured exit statuses
2 ❌ The third release symptom was asserted three times while its only artifact recorded exit status 0 AGREE - fixed @ 4029d193 The old log read $? after a pipeline. Re-measured with the status taken directly off the invocation: SIGABRT, exit status 134, 4 of 4 runs, no rows on stdout, with child-alone and parent-alone controls in the same log returning correct rows. The claim survived rather than being softened
3 ⚠️ "Wide parts are safe because each column gets its own read" is the wrong reason AGREE - fixed @ 4029d193 MergeTreeReaderWide keys its SubstreamsCache by name in storage (:196) over a reader member cleared only after the whole loop (MergeTreeReaderWide.h:116, :248), so it does share one cache between a parent subcolumn and its child. The measured fact is unchanged; the description and the shipped test comment now say "measured and not affected" with no mechanism asserted
4 ⚠️ The test's fails-without-the-fix property depends on a default: the defect lives on one of MergeTreeReaderCompact::readData's two subcolumn branches, selected by write_marks_for_substreams_in_compact_parts AGREE - fixed @ 4029d193 Pinned to 1 on the five Compact carrier tables. The deliberate non-carrier controls, the wide-part table and the top-level shape, are left unpinned so they keep showing what they are there to show. Re-ran the buffer-revert mutant afterwards: it still fails with the exact error and with the dictionary-size oracle diverging, which is what proves the pin did not move the test onto the branch that was never broken
5 💡 The test's leading comment stated the pre-fix behaviour as the expectation while the assertion checks the opposite AGREE - fixed @ b9b2150c Reworded to the invariant actually asserted; the reference delta is exactly the two echoed comment lines
6 💡 getHash folded a variable-length type name in without a length prefix AGREE - fixed @ b9b2150c Both in-tree serializations that do this prefix the length (SerializationNamed.cpp:29-31, SerializationLowCardinality.cpp:54-56). No collision was reachable, so this is idiom only
7 💡 The blast-radius paragraph read as MergeTree-only AGREE - fixed @ b9b2150c The wrapper is also reached from StorageLog (StorageLog.cpp:345, caches shared per name in storage at :262/:274). Stated as reach only: reading this shape from a Log table fails with Code: 33 identically on 26.6, 26.7 and master, so that is a separate pre-existing problem this change neither causes nor fixes
8 💡 The rendered Related: link sat only inside the leading HTML comment, which does not render AGREE - fixed @ 4029d193 Added below the comment block, which is kept byte-identical
9 💡 applyParentNullMapToExtractedSubcolumn's header comment requires a nullable dictionary, which the new caller intentionally does not pass AGREE, noted, not changed Correct and worth stating: NullableUtils.h:44-46 predates this change and is byte-identical to master, but the input it excludes is introduced here. The promotion is documented at its own site (NullableUtils.cpp:129-133) and the exclusive-ownership half of the contract, the part that carries the safety, still holds. Left for the follow-up that already exists for this area rather than rebuilding the 15 translation units that include the header for a comment
10 💡 Use Critical Bug Fix (crash, data loss, RBAC) instead of Bug Fix DISAGREE I do not self-select that category; it is set on an explicit maintainer request, and none was made here. Same-family precedent: #108679 described a server abort during a merge and shipped as Bug Fix. The finding was also premised on the termination claim that finding 2 had just shown was unmeasured at the time
11 💡 Write create instead of create() in a comment DISAGREE No such convention: 296 /// comments in src/ use the backticked-with-parens form, including NullableUtils.cpp:233 in a file this PR already edits, and no style check enforces it. Changing it would make the new comment inconsistent with its immediate neighbours
12 💡 The changelog entry is past-tense and exposes buffer and cache mechanics; replace it with a shorter present-tense summary DISAGREE CHANGELOG.md has 405 entries starting "Fixed" and 1089 starting "Fix" against 48 "Fixes", so the guideline's present-tense example is not enforced, and #108679 shipped the same shape. More importantly the proposed replacement drops the exact user-visible error text, which is what makes the entry findable by someone hitting it, and collapses three measured element-type-dependent outcomes into one phrase. The entry is one sentence and names user-visible artefacts plus one clause of mechanism
13 💡 No commit message carries the CI report URL DISAGREE That instruction is conditional on the URL being supplied to me as an operator instruction; here it came from a comment on #100394. The instruction that binds this PR is satisfied: the full canonical report URL is in the description above, together with the rendered Related: line for the linked PR. Adding it to a commit would need a new no-op commit, since amend and rebase are not used here
14 💡 HEAD~2's commit message still carries the retracted "abort on a bad cast" wording AGREE, noted, not changed HEAD~1's message records the retraction explicitly, no in-tree comment or test carries the wording, and the description is what gets reviewed. Not fixable without amending history
15 💡 The description attributed the debug-build stop to assert_cast AGREE - fixed in this description The measured debug stop for the assumeNotNull projection is the columnMatchesType post-condition (ExpressionActions.cpp:693-704), which is not build-gated at all; what the build type changes is Exception::handleErrorCode turning LOGICAL_ERROR into an abort

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by a fix round are auto-dropped.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One clickhouse local invocation on a Compact part: SELECT x.a.b, x, x.a, isNull(x.a.b), assumeNotNull(x.a) FROM t over Tuple(a Nullable(Tuple(b LowCardinality(UInt32)))) aborts with Unexpected return type from assumeNotNull. Expected Tuple(b UInt32). Got Tuple(Nullable(UInt32)), byte-identical to the CI message. No fuzzer, no randomization, no timing. A second, independent oracle needs no NULL at all: on a table with zero parent-NULL rows, SELECT dumpColumnStructure(x.a) and SELECT x.a.b, dumpColumnStructure(x.a) must report the same dictionary size, and before the fix the second reported one entry more.
b Root cause explained? Yes. The extracted subcolumn's type is promoted to LowCardinality(Nullable(T)), so MergeTreeReaderCompact creates the result column already promoted, and SerializationNullableWithParentNullMap built its per-range deserialization buffer from it via cloneEmpty(). SerializationLowCardinality then publishes that nullable-dictionary buffer to the shared SubstreamsCache, so the published substream is not the on-disk LowCardinality(T) representation. A sibling reader of the same streams (the parent x.a) adopts the cached column directly and ends up holding a nullable dictionary under a non-nullable declared type, which the columnMatchesType post-condition rejects. Nothing mutates the published column; it was never the right representation. Regression from my own merged #108679, which created this path.
c Fix matches root cause? Yes. It changes what the buffer is, at the layer that chooses the buffer: when the subcolumn type was promoted from a non-nullable LowCardinality(T), the buffer is built from the on-disk type, and the promotion happens afterwards on the private per-range column. No widened bound, no no-random-* tag, no relaxed columnMatchesType, no suppressed publication (publication is load-bearing: it is what lets parent and child share a single stream read), and no guard at the throw site.
d Test intent preserved / new tests added? New stateless test 04651_nullable_tuple_lowcardinality_subcolumn_shared_cache.{sql,reference}. No existing test weakened, retagged or removed. It is parallel-safe (own tables in currentDatabase(), plain MergeTree SQL), so no no-parallel and no no-fasttest. Its Compact tables pin write_marks_for_substreams_in_compact_parts = 1, so the test keeps exercising the branch that was broken even under a server- or job-level override of that default; mutant (a) was re-run after the pin and still kills.
e Both directions demonstrated? Yes, on Build-ID-verified binaries. Pristine master: RC=134 with the exact CI message, and the new test aborts at its structural-oracle line. With the fix: RC=0 and the test matches its reference. Additionally three mutants were each rebuilt and each failed: reverting the buffer construction brings the CI message back; the alternative cloneEmpty() + nestedRemoveNullable() form passes every value query but silently leaves Unique(size = 2), which is exactly why the dictionary-size assertion is in the test; deleting the existing promotion in applyParentNullMapToExtractedSubcolumn fails with Cannot apply a null map to LowCardinality(UInt32) with a non-nullable dictionary, proving that line is load-bearing. The release-build half was measured on the official 26.6.2.120 and 26.7.2.26 binaries: 26.6 is correct on every query, while 26.7 gives unstable wrong values for the UInt32 element, Code: 49 for the assumeNotNull shape, and a SIGABRT from a string_view hardening assertion for the String element (exit status 134, 4 of 4 runs, no rows on stdout, status captured directly off the invocation). The fixed build clears all three.
f Fix is general across code paths? The invariant is that a column published to the shared substreams cache must hold the on-disk representation of that stream, since sibling readers adopt it directly. Grepping the serializations for a wrapper that clones a possibly-promoted result column before delegating yields exactly two: this one, and SerializationVariantElement, which already keeps its buffer in the on-disk representation. Every other candidate path was measured rather than assumed: the wide reader (measured, not a carrier; it does share one SubstreamsCache per name-in-storage, so the reason is not per-column reads), the getSubcolumn branch used when write_marks_for_substreams_in_compact_parts = 0 (already copies), and the in-memory subcolumn creator (already promotes a private copy). The fix is at the source, not at the site that threw.
g Fix generalizes across inputs (params/datatypes/wrappers)? Verified against an ENGINE = Memory twin for each shape: LowCardinality of UInt32, String, FixedString(3) and Date; a multi-element inner tuple; an already-LowCardinality(Nullable(T)) leaf, which must not be de-nullabilised and is not; plain Nullable(T) and non-LowCardinality leaves; zero-NULL, alternating and mixed data; 4 and 30 rows; index_granularity 1 and 3; max_block_size 1, 2 and 4 so that a cached substream spans several ranges; Compact and Wide; both projection orders.
h Backward compatible? (maintainer-approved exception only) Yes. Read path only, no on-disk format change, no new or changed setting, so no SettingsChangesHistory.cpp entry. The new constructor parameter defaults to null, leaving the non-LowCardinality flavour byte-identical, and it is folded into getHash() so the two flavours cannot share a pooled instance. 26.7 is affected and wants v26.7-must-backport after merge.
i Invariants and contracts preserved? The cache-publication invariant is what this restores. applyParentNullMapToExtractedSubcolumn's documented contract (exclusive ownership, column able to represent NULL) is now genuinely satisfiable on this path, and it remains the single promotion owner; it runs on the IColumn::mutated private column, which is cloned if the cache still holds a reference, so the published column can never be mutated. The promotion deliberately runs before the memoryIsZero early return, which is why the zero-parent-NULL case is correct, and that case is asserted in the test. Pooling identity is preserved by the hash. No lock, ordering or restart-recovery contract is involved.

Session id: cron:clickhouse-impl-slot-43:20260728-051900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Avogar @CurtizJ - could you review this? It fixes a regression from #108679: an extracted subcolumn of Nullable(Tuple(...)) with a non-nullable LowCardinality(T) element was deserialized into an already-promoted LowCardinality(Nullable(T)) buffer, so the substreams published to the shared cache were not the on-disk representation and a sibling reader of the parent subcolumn adopted them directly, giving wrong values, Code: 49, or a termination on 26.7 depending on the element type.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c2b049]

Summary: ✅


AI Review

Summary

This PR fixes the Nullable(Tuple(...)) plus non-nullable LowCardinality(T) subcolumn regression by deserializing the shared substream in its on-disk LowCardinality(T) representation and only promoting the private per-range column before the parent null map is applied. The current head matches that contract, the follow-up test change no longer asserts the unspecified value of assumeNotNull(NULL), and I did not find any remaining correctness, coverage, or metadata issues; the current Praktika report is all green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 28, 2026
…on test

assumeNotNull has an unspecified result when its argument is NULL, so the
04651 regression test must not pin the values it produced on the parent-NULL
rows: those values are today's implementation detail and would make the test
fail on unrelated changes even with the shared-cache bug still fixed.

Every assumeNotNull call is now wrapped in ignore(), which keeps the call
evaluated while dropping the value comparison. Keeping it evaluated is
required: what the bug breaks is the function's return-type post-condition
(Expected Tuple(b UInt32), Got Tuple(Nullable(UInt32))), not the value, so a
form that removes the call would remove the coverage.

The two other forms suggested in review were measured and rejected:
toTypeName(assumeNotNull(...)) is constant-folded at analysis time, so
assumeNotNull is never executed and a build with the fix reverted passes;
restricting the comparison to non-NULL rows removes the parent-NULL rows,
which are exactly the rows that trigger the promotion. With ignore(), a build
with the fix reverted still fails with the original message.

Reported by the automated review on the pull request.
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 80.60% 86.30% +5.70%
Functions 91.50% 92.10% +0.60%
Branches 72.60% 78.40% +5.80%

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

Full report · Diff report

@PedroTadim

Copy link
Copy Markdown
Member

cc @nihalzp

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's quite complex, but looks alright.

@alexey-milovidov alexey-milovidov self-assigned this Jul 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 30, 2026
Merged via the queue into ClickHouse:master with commit 79be89f Jul 30, 2026
178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 31, 2026
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

The backport ask covering this PR is on #111949, together with the per-branch measurements: #111949 (comment)

Two points from there that apply to this PR specifically. The floor is v26.7-must-backport, not v26.6: the promoted non-nullable LowCardinality path this PR patches only exists from #108679, which is not on 26.6. And it should be labelled only after #111949's 26.7 backport has merged, otherwise this cherry-pick is computed against a 26.7 that still lacks that fix and conflicts.

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

4 participants