Repository navigation
Fix a nested null map subcolumn of a Variant element ignoring the discriminators - #120099
Conversation
…criminators
For a Variant/Dynamic/JSON element that is a tuple, the null map of a Nullable
field of that element returned 0 on every row holding a different alternative,
although the field itself reads NULL there. Since optimize_functions_to_subcolumns
is enabled by default and rewrites isNull(x) to x.null, a plain
SELECT count() FROM t WHERE value.`Tuple(a Nullable(UInt32), b String)`.a IS NULL
silently dropped the matching rows: 1 instead of 2 on a three-row merged part.
SerializationVariantElement fills rows whose discriminator is not the element's
with the result column's default. For the value read that default IS NULL, so it
is correct; a null map is a bare UInt8 whose default 0 means "not null", which
makes it the one subcolumn whose value for an absent element is not its default.
Nothing on the path could distinguish the two: SerializationVariant::enumerate
Streams attaches one subcolumn creator per alternative, while the selection
happens per subcolumn beneath it, and ISerialization::createFromPath hands a
creator only the selected subcolumn's (serialization, type, column) - where a
null map's type is plain UInt8, indistinguishable from a genuine UInt8 element.
prev_type, which ClickHouse#112338 used to derive nullable_added_by_extraction, therefore
carries one bit too few for this case.
So ISubcolumnCreator gains one virtual with a default no-op,
specializeForSelectedSubcolumn, which names the selected substream to the
enclosing creators. VariantSubcolumnCreator uses it to learn that the selection
is a null map and then writes 1 for absent rows at all four read sites and in
both in-memory creator paths. SerializationVariantElementNullMap already does
exactly this for the top-level x.<Elem>.null, and cannot serve the nested case
because all three of its create() overloads discard prev and would throw away
the field's own on-disk null map. Nine of the ten creators inherit the no-op.
createFromPath and makeSubcolumnInfo also pass the true selected terminal, since
on the dynamically-resolved-descendant arm the leaf lives in the nested path and
path[prefix_len - 1] is only the prefix the dynamic type matched.
Two guards keep the change to the case where the null map is the only place the
information can live: the extraction must not have wrapped the element in
Nullable, where absence is already NULL, and the selection must still be a bare
UInt8, since an Array or Map below has already made it Array(UInt8), whose value
for an absent element is the correct default []. That leaves the fix orthogonal
to ClickHouse#119222, which flips allow_nullable_tuple_in_extracted_subcolumns to true.
No on-disk or format change: the same streams are requested and only the value
written into rows where the element is absent changes. This is not a regression -
released 26.8.3.105 already returns 0 there; our ClickHouse#112338 removed a SIGSEGV on the
sibling value read, which is what makes the contradiction observable and puts the
IS NULL rewrite on a completing path.
Closes: ClickHouse#119935
Co-Authored-By: Claude Opus 5 <[email protected]>
…rm the remaining fill Review round 1. The column overload of VariantSubcolumnCreator::create now expands the null map with expandDataByMask and default value 1 instead of a hand-rolled loop. That is ColumnNullable::expand's own idiom for the same semantic, it expands in place rather than allocating a second column, and it restores the three size validations the loop had dropped: a previous-column and mask pair that disagreed returned PaddedPODArray padding bytes as null-map values, where the untouched expand call raises a diagnosable LOGICAL_ERROR. The regression test gains a pure Variant column added by ALTER TABLE ADD COLUMN, in a compact and in a wide part, which reach the read that finds no discriminators stream at all; and two rows asserting that optimize_functions_to_subcolumns still rewrites IS NULL on this nested subcolumn, so the two count forms cannot agree by both ceasing to exercise it. The !state fill in SerializationDynamicElement mirrors the identical branch in SerializationVariantElementNullMap; no SQL-reachable read of a nested null map was found that reaches it.
…he in-memory branches Review round 2. `SerializationVariantElement::insertRowsForAbsentElement` reached `IColumn::insertManyDefaults` for the per-row absent case introduced in the previous round. That function begins with `reserve(size() + length)`, and `ColumnTuple`, `ColumnNullable`, `ColumnMap` and `ColumnLowCardinality` do not override it, so a tuple element paid a virtual `reserve` fanned out over every field for every absent row, and one exact-size `PODArray` reallocation per leaf field whenever capacity equalled size. The helper now takes the single-row fast path `insertDefault`, which is what that site called before, and keeps `insertManyDefaults` for the two bulk fills, where the single up-front reserve is what is wanted. The regression test gains two `ENGINE = Memory` cases. They are the only reads that enter `DataTypeDynamic::getDynamicSubcolumnInfo`'s in-memory branches for a type extracted from the shared variant and for a type no row holds: the `MergeTree` cases that look equivalent go through `SerializationDynamicElement`'s per-row decode instead, whose `insertDefault` of the nullable-safe element type already yields `NULL`. Both branches returned 0 for an absent row before this change. The `!state` fill in `SerializationDynamicElement` mirrors the identical branch in `SerializationVariantElementNullMap`; no SQL-reachable read of a nested null map was found that reaches it. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review over three rounds: an independent model (engine: codex; 3 findings in round 1, Round 1
Round 2 (re-review of the resulting tree)
Round 3 (re-review of the resulting tree)
Severity: ❌ blocker / Two things checked and deliberately not raised. The One clearance worth stating for a serialization change: no Session id: cron:clickhouse-review-slot-10:20260914-223500 |
|
Workflow [PR], commit [657a015] Summary: ✅
AI ReviewSummaryThis PR fixes the case where a nested Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 657a015.
Changed lines: Changed C/C++ lines covered: 171/174 (98.28%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260914-214400 |
…-nested-null-map-119935
CI finish ledger - 13008a6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Two notes so the red marks are not misread. The Session id: cron:our-pr-ci-monitor:20260915-043204 |
|
Fixing PR for the Still not caused by this PR: the test's lightweight delete waits on a mutation that the server-global merges/mutations pool-headroom guard refuses to assign, and that refusal reuses an already-saturated 60 s merge-selecting interval instead of retrying sooner. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units3052 translation units recompiled, 15647 s compile time in total, 3052 of them have a recent master baseline. |
… merges/mutations pool contention 04068_lwd_minmax_projection_recovery_rmt stops making progress and is killed by the Fast test 60 second per-test cap: 3 failures in 190,994 runs over 45 days, none of them on master, and in the job that surfaced it (#120099) it was the sole red of 15,103 rows. It is a stall rather than a slow test (the OK maximum is 7.0 s over 25,331 Fast test runs and 14.5 s over 10,219 arm_darwin runs, while the failures sit at 60.05 and 60.10 s), and the non-replicated sibling of this test has 0 failures in 190,985 runs. The twelve single-row INSERTs each schedule the merge-selecting task, so twelve iterations run back to back, find nothing mergeable and return AttemptStatus::CannotSelect, which multiplies merge_selecting_sleep_ms up to max_merge_selecting_sleep_ms (60 s). DELETE FROM then creates the mutation, and the single iteration that sees it is refused by the pool-headroom guard in CompactionStatistics::getMaxSourcePartBytesForMutation: max_tasks_count (32) - occupied (25) < number_of_free_entries_in_pool_to_execute_mutation (8) so max_source_part_bytes_for_mutation is 0 and mergeSelectingTask returns AttemptStatus::Limited. Limited matches neither arm of the backoff epilogue, so the saturated 60 second interval is reused verbatim, no MUTATE_PART entry is created, and lightweight_deletes_sync = 2 blocks until max_execution_time fires. With the threshold at 0 the guard's comparison is unconditionally true for this table, so the mutation is assigned on the first iteration that sees it, whatever unrelated parallel tests are doing to the server-global pool. The non-replicated sibling is immune because StorageMergeTree::mutate() calls background_operations_assignee.trigger(), which shrinks its backoff instead of leaving it saturated. Reproduced as a 2x2 over pool occupancy and this diff, on one server and one binary: the pristine file with an occupied pool fails with code 159 after 60.64 s; this diff under the same occupancy passes in 2.69 s with byte-for-byte reference output; both files pass on an idle pool, which places the failure on occupancy rather than on the test. 100 of 100 randomized runs of this test and its plain sibling pass, as do 10 runs each of 02440_mutations_finalization and 03716_mutations_parts_postpone_reasons_rmt. The engine-level starvation, where Limited reuses a saturated interval for every Replicated table, is tracked upstream in #61902 and is deliberately not touched here; this is the same test-side remedy already merged in #118435 and #112090 for the identical log signature. Related: #120099 Co-Authored-By: Claude Opus 5 <[email protected]>
|
This is quite complex, but acceptable. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results when reading the
nullsubcolumn of aNullablefield of aVariant,DynamicorJSONelement, for examplevalue.`Tuple(a Nullable(UInt32), b String)`.a.null. On rows holding a different alternative the subcolumn returned0although the field itself wasNULL, sooptimize_functions_to_subcolumns(enabled by default) rewritingIS NULLto that subcolumn silently dropped matching rows. Closes #119935.Description
For a
Variant/Dynamic/JSONelement that is a tuple, the null map of aNullablefield of that element read0on every row holding a different alternative, although the field itself readsNULLthere.optimize_functions_to_subcolumnsis on by default and rewritesisNull(x)tox.null, so with rowsa = 1,a = NULLand'not a tuple'in one merged part:SerializationVariantElementfills rows whose discriminator is not the element's with the result column's default. For the value read that default isNULL, so it is correct; a null map is a bareUInt8whose default0means "not null", making it the one subcolumn whose absent value is not its default. Nothing could tell:createFromPathgives a creator only the selected subcolumn's type, column and serialization, where a null map looks like anyUInt8.So
ISubcolumnCreatorgains one defaulted virtual,specializeForSelectedSubcolumn, letting the Variant element creator learn the selection is a null map and write1for absent rows, asSerializationVariantElementNullMapalready does for the top-levelx.<Elem>.null. Nine of the ten creators inherit the no-op. Untouched: aNullable-wrapped element, where absence is alreadyNULL, and anArray/Map-wrapped map, whose absent[]is right.Not a regression: 26.8.3.105 already returns
0there; #112338 only removed a SIGSEGV on the sibling read, making the contradiction observable. The fixed path is the one where the extraction cannot express absence asNULL, i.e.allow_nullable_tuple_in_extracted_subcolumns = 0- master's default today, and 26.3-26.8. After #119222 flips that default, master no longer reaches this path by default; the fix stays correct, orthogonal to it, and needed for released versions.New test: 90 assertions, 23 wrong without the fix.
04652/04653untouched and green.Workflow [PR]
Sync PR [sync-upstream/pr/120099]
Version info
26.10.1.226-master(included in26.10and later)