Repository navigation
Re-resolve a nested subcolumn name at the array level it was resolved at - #113752
alexey-milovidov merged 6 commits into
Conversation
Reading a "sizeN" subcolumn of a nested Array(JSON) path aborted the server
with a LOGICAL_ERROR from IColumn::assertTypeEquality, reached through
SerializationDynamicElement::deserializeBinaryBulkWithMultipleStreams.
A "sizeN" name is not fixed: the digit is the array depth counted from the
column root, so the same name denotes a differently shaped subcolumn at each
level. Resolution threads that level correctly, but the level was dropped when
the remaining subcolumn name was stored for later re-resolution, and every
public IDataType::getSubcolumn entry point hardcoded it to zero. One name was
therefore resolved twice at two different levels, yielding two different types,
and insertRangeFrom appended a mismatched column.
The level is not stored anywhere. SerializationArray keeps one ArrayElements
entry on settings.path for the whole of nested deserialization, one per array
wrapper, so the depth is already available at each re-resolution site and is
derived there with the existing ISerialization::getArrayLevel. Deriving it per
call also keeps the serialization pooling hash unchanged, which storing it
would not have done.
IDataType::getSubcolumn and tryGetSubcolumn take a defaulted
initial_array_level, forwarded through their ColumnConst recursions so a
wrapped column does not silently reset the level. The default keeps every other
call site behaving exactly as before: git grep -nE
'(->|\.)(getSubcolumn|tryGetSubcolumn)\(' -- src/ finds 15 non-test member
calls, and only the three nested re-extraction sites pass a level, where the
previous code passed a literal zero.
The array level was measured at each of the three sites before the fix was
trusted: 1 and 2 for two- and three-level paths through
SerializationDynamicElement, and 1 for both shared-data sites. Mutants that
drop the level at one site, replace it with a constant, or replace it with zero
each redden only the arms belonging to that change.
The ColumnConst recursion of the resolving API cannot be reached from any site
that passes a level, so it is covered by two gtests rather than by the
stateless test, one per entry point, each pinned by its own mutant.
No stream names and no on-disk layout change: the part file list is identical
before and after on the same fixture.
Internal second-model review (2 rounds, 5 findings adjudicated)Two independent review rounds ran before this PR was opened: a cold code review plus an independent Round 2 findings
Round 1 findings (all agreed, all fixed in round 1) The commit message, this comment and the evidence claimed "nine existing callers" of the changed Noted, not fixed here. Under the Every countable claim in the PR body, this comment and the commit message was re-derived from the Session id: cron:clickhouse-review-slot-10:20260807-010200 |
Pre-PR validation gate (a-i)
Mutants. M1-M4 and M6-M7 are applied to the server (shipping Build ID
Other runs. 50 randomized plus 50 plain runs of the new test all pass. A 339-test subcolumn slice run on both binaries with the same explicit test list gives identical failure sets and identical reasons: the same 8 tests fail on both, in the same buckets (3 Noted, not fixed here (one concern per PR). Under the |
|
cc @Avogar @CurtizJ, could you review this? A |
|
cc @Avogar |
|
Workflow [PR], commit [c8c01a6] Summary: ✅
AI ReviewSummaryThis PR reworks the nested Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus:
LLVM Coverage ReportMeasured on commit c8c01a6.
Changed lines: Changed C/C++ lines covered: 28/28 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units3022 translation units recompiled, 15979 s compile time in total, 3022 of them have a recent master baseline. |
CI finish ledger - e2d7952Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
All 175 check-runs completed (156 success, 17 skipped, 2 failure); Neither failure is caused by this diff, so nothing is fixed in this PR for them. Session id: cron:our-pr-ci-monitor:20260807-130000 |
Two conflicts, both in the deserialization sites this branch edits. Master refactored `deserializeBinaryBulkWithMultipleStreams` to take `IColumn &` instead of `ColumnPtr &` and dropped `rows_offset` (a1e364e, 40656cb), and it stopped keeping the shared-variant / shared-data map columns in the deserialization state. Both conflicted files were reseeded from master verbatim and the three `getArrayLevel(settings.path)` arguments re-applied on top, so every refactor line survives byte-for-byte: - SerializationDynamicElement.cpp: unchanged apart from the added argument. - SerializationObjectSharedDataPath.cpp: `dynamic_column` is now an `IColumn &` rather than a `MutableColumnPtr`, so the MAP-branch call reads `dynamic_column.getPtr()`; the ADVANCED-branch call is unchanged. `getArrayLevel` and `getSubcolumnData(..., size_t initial_array_level, ...)` are byte-identical on master, and `Substream::Bucket` is not an `ArrayElements` substream, so the level computed at each site is unchanged. `IDataType.cpp`/`.h` auto-merged; master's `getSerializationInfo` overload split and `createColumn` de-virtualization are preserved. The merged tree differs from master by exactly this PR's own 7 files (+266/-11) and moves no submodule pin.
|
Two measured things a reviewer needs before spending time here. The red #116393 overlaps this PR and should decide how it lands. It replaces Its reference file records @Avogar, your call and I will do either: rebase this test onto the non-JSON spelling so it survives #116393, or close this PR if you would rather carry the level at those two call sites inside that refactor. |
CI finish ledger - d0650fbCI is fully finished at this commit. One check failed, and it has an owner.
Everything else at this commit is green: 177 praktika nodes, 155 Session id: cron:our-pr-ci-monitor:20260827-200000 |
The level was threaded into the public IDataType::getSubcolumn and tryGetSubcolumn so that the three sites which re-resolve a stored subcolumn name could re-resolve it at the level it was resolved at. The next commits reach the same result without a level at those sites, by storing the name in the form that resolves to the same substream at array level 0. The functional test is kept and adapted later; the gtests only pinned the ColumnConst forwarding of the reverted parameter.
…he nested subcolumn fix
"sizeN" counts Array wrappers from the root of the column, so the array sizes get a different number at every array nesting level. SerializationDynamicElement and SerializationObjectSharedDataPath keep such a name to resolve it again against the type of a dynamically typed value alone, that is at array level 0, when the value comes from the shared variant or from shared data. The name kept the number it was resolved with, so the two resolutions disagreed on the type and insertRangeFrom aborted in IColumn::assertTypeEquality, or, in a release build, segfaulted or returned a wrong size. The name is now renumbered when it is stored. The substreams path that getSubcolumnInfo reports tells whether it really resolved to the array sizes - a name alone cannot, since a Tuple element or a JSON path can be spelled the same - and the array level inside that path is the number the sizes get against the type alone. The user-facing names do not change: they stay relative to the root of the column, as 03813_size_subcolumn_of_dynamic_subcolumn pins them. A name that is not the array sizes is stored unchanged. Such a name can still mean different substreams at different levels, which is the subject of ClickHouse#116393 rather than of this fix.
…ai/fix-nested-array-level-size-subcolumn
|
Thanks, that is much smaller than mine, and keeping the level inside I rebuilt One case the rework does not cover, which I think is why the four arms had to come out of the test: CREATE TABLE t (json JSON) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t FORMAT JSONAsObject {"a" : [{"b" : [42, 43]}]}
SELECT json.a.:`Array(JSON)`.b.:`Array(JSON)`.size0 FROM t;That still gives SELECT json.a.:`Array(JSON)`.b.:`Array(JSON)`.c.:`Array(JSON)`.size0 FROM t04812_json3;
SELECT jd.a.:`Array(JSON)`.size0 FROM t04812_shared;
SELECT mp.values.values.a.:`Array(JSON)`.size0 FROM t04812_map;All four abort on master as well, so none of this comes from your commits. It is the other half of #113686, and nothing covers it now. All four are Two ways out, and the choice is yours:
I am happy to push either on top of your commit with the four arms restored. Tell me which you want. Merging this as it stands and handling the remaining direction separately also works for me. |
I believe this should cover it: #116393 |
|
It does cover them. I built your branch head
One consequence, since it decides what 04812 should look like afterwards:
So whichever of the two merges second owes Nothing outstanding from me on this PR. |
ReproducerCREATE TABLE t (json JSON) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t SELECT '{"a":[{"b":[42,43]}]}'::JSON;
SELECT json.a.:`Array(JSON)`.b.:`Array(JSON)`.size1 FROM t;
-- 26.8.2.7 / 26.7.6.57 / 26.6.4.55 / 26.3.33.24 (release, aarch64): [55766552] -- a garbage size; expected [0]
-- sanitizer/debug build: the same SELECT aborts (SIGABRT) in IColumn::assertTypeEquality
-- 26.1.12.23 and older: [[]] -- the name never resolved to the array sizes, no bad readResults:
Backport the fix to CC introducing PR reviewer: @yariks5s CC component owner: @alexey-milovidov Analysis metadata
|
Adapt #113752 to 26.3, which has no `SubcolumnInfo` with a resolved substream path: `IDataType::getSubcolumnData` marks a resolved subcolumn as the array sizes in `SubstreamData::is_array_sizes_subcolumn` (forwarded through the `Array` and `Nullable` wrappers), and `getSubcolumnNameForZeroArrayLevel` derives the level-0 number by subtracting the array level the name was resolved with. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a segfault and silently wrong results when reading a
sizeNsubcolumn of a nestedArray(JSON)path; in debug and sanitizer builds the same read aborted with aLOGICAL_ERRORinIColumn::assertTypeEquality. Closes #113686.Description
What breaks. Reading a
sizeNsubcolumn of a nestedArray(JSON)path aborts inIColumn::assertTypeEquality, fromSerializationDynamicElement::deserializeBinaryBulkWithMultipleStreams:Release builds. The check is compiled out, so the read proceeds. Measured on stock release master
26.9.1.880: a segfault (Address: 0x58),PARAMETER_OUT_OF_BOUNDfromColumnArray::insertRangeFrom, or a wrong size ([110459705806544]instead of[2]).Root cause. The digit in a
sizeNname is the array depth from the column root, so the same name denotes a different subcolumn at each level.SerializationDynamicElementandSerializationObjectSharedDataPathkeep such a name and resolve it again at array level 0 when the value comes from the shared variant or from shared data. The kept name carried the number it was resolved with, so the two resolutions disagreed on the type.What the change does. The name is renumbered when it is stored.
IDataType::getSubcolumnNameForZeroArrayLevelreads the substreams pathgetSubcolumnInforeports, since only that tells whether the name really resolved to the array sizes, and rewrites the digit to the array level inside it. No level is stored and no public signature changes.Validation. On a debug build of the head the regression test output is byte-identical to its
.reference; on master it aborts.Not fixed here.
.size0on such a path is an ordinary path at the level it was resolved at and the array sizes at level 0, so the renumbering does not fire and the read still aborts at the same assertion. That is unchanged from master and is a separate ambiguity, sincesize0can then mean two subcolumns; it is addressed in #116393.Reported on #112945. The fix in its present form is @ Avogar's rework of my original change.
Workflow [PR]
Sync PR [sync-upstream/pr/113752]