Skip to content

Fix the type of a defaulted Nested member subcolumn under shared offsets - #116553

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-defaulted-nested-member-subcolumn-type
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-defaulted-nested-member-subcolumn-type

Conversation

@groeneai

@groeneai groeneai commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

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

Fixes an error when reading a subcolumn of a Nested member added by ALTER TABLE ... ADD COLUMN whose element type wraps the tuple, for example Array(Nullable(Tuple(a String, b Float64))). Previously such a read failed with LOGICAL_ERROR on the rows written before the member was added; it now returns the default values.

Description

Related: #110957 (comment)
Related: #113891

getBaseTypeOfArray walks the storage type consuming a tuple-element path and stops at the first type it cannot enter. Its caller then stripped the whole path from the subcolumn name regardless of how much was consumed, so createColumnWithDefaultValue got an empty subcolumn name, skipped IDataType::getSubcolumn, and produced a default column of the parent's type. Nullable in that position is the third wrapper to land there after Tuple and Map, so instead of adding a fourth branch the descent now reports how many names it consumed and the caller leaves the remainder to the authoritative subcolumn extraction, subtracting the array levels that extraction contributes. No shape that master gets right changes: where the descent consumes the whole path the arithmetic reduces to the old one, and the new dimension term only removes levels the old code over-counted. An unaccountable remainder now throws instead of building another malformed column.

Reachable by a plain ALTER TABLE ... ADD COLUMN, on MergeTree (Wide and Compact) and on Memory, by a direct read as well as through merge(). Every shape I found has a Nullable(Tuple) element, which is GA and allowed by default since 26.9: the official 26.9.1.1629 build returns Code: 49 here with default settings, and 26.6, 26.7 and 26.8 do with enable_nullable_tuple_type = 1. None returned wrong values rather than the error.

Reported by @ rorylshanks from the targeted AST fuzzer, STID 1611-37da, check AST fuzzer (amd_debug, targeted, old_compatibility): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110957&sha=90a374d351eb9475c2ad4bde5c6f17cafce082a6&name_0=PR&name_1=AST%20fuzzer%20(amd_debug%2C%20targeted%2C%20old_compatibility). It is not caused by that pull request: I reproduced it on plain master. Issue 113891 is a different site (a mutation write, no fillMissingColumns frame) and is not fixed here. The same shape later hit AST fuzzer (amd_tsan) on #117830: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117830&sha=7491d4607a38d8a06a2bb0f0bed5097013f78c0f&name_0=PR&name_1=AST%20fuzzer%20%28amd_tsan%29

Validated shapes, base vs fixed (click to expand)
shape subcolumn base fixed
MergeTree Wide, member re-added, read via merge() .b error 99
same, direct read .b error [] [NULL] [NULL,NULL]
plain ADD COLUMN, no DROP, no mutation .b error correct
Compact part .b error correct
ENGINE = Memory .bb error [NULL,NULL,NULL]
depth 2, Map inside the tuple .k.keys error [] [[]] [[],[]]
depth 2, Array inside the tuple .k error [] [[]] [[],[]]
wrapper below a tuple element, so the descent answers only a strict prefix .k.bb error [NULL,NULL,NULL]
same, where the remainder adds an array dimension .k.m.keys error [[],[],[]]
share_nested_offsets = 0 .b ok unchanged
member present in the part .b ok unchanged
Array(Point), no settings .1 ok unchanged
Array(Variant(...)), Array(Dynamic) .UInt64 ok unchanged

Not made correct, and unchanged from master: a depth-numbered remainder such as .k.size1 fails with Code: 44 on both, only the subcolumn name in the message differs.

Both existing test files gained arms rather than a new file: 04329 owns the Memory reader, 04770 the MergeTree Wide and Compact readers and the reported merge() read. Every arm asserts through materialize, because a bare length passes on a wrongly typed column; the one exception is the merge() arm, which asserts through that path's own converting step, the shape that was reported. 50 randomized runs of each file pass, as do 13 neighbouring Nested subcolumn tests.


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

Reading a Nested member subcolumn that a part does not store synthesizes a
default column from the sibling's shared offsets. getBaseTypeOfArray walks the
storage type consuming the tuple-element path, stops at the first type it cannot
enter, and did not report how much of the path it had consumed. The caller
stripped the whole path from the subcolumn name regardless, so
createColumnWithDefaultValue received an empty subcolumn name, skipped
IDataType::getSubcolumn, and built a default column carrying the parent's type.
The block then disagreed with its own header, which a type-checking consumer
rejects. With an element type of Array(Nullable(Tuple(a String, b Float64))),
reading .b through merge() gives

  Unexpected return type from materialize.
  Expected Array(Nullable(Float64)).
  Got Array(Nullable(Tuple(String, Float64))).

Nullable in that position is the third wrapper to stop the descent, after Tuple
and Map, so instead of adding a fourth branch the descent now reports the length
of the prefix it consumed and the caller leaves the remainder in the subcolumn
name for IDataType::getSubcolumn to resolve. The array-level accounting subtracts
the dimensions that extraction contributes, and a remainder that cannot be
accounted for throws rather than building another malformed column. A complete
descent leaves an empty remainder, so every shape that works today evaluates the
original arithmetic unchanged.

Both callers of fillMissingColumns were affected, so 04329 gains the Memory arms
and 04770 the MergeTree and merge() arms. One 04329 arm puts the wrapper below a
tuple element, so the descent consumes a strict prefix of the path rather than
none of it or all of it, and a second does the same with a remainder that adds
an array dimension of its own. The Compact reader finds a missing member's
offsets in its own implementation, so it gets its own arm, which asserts the
part kind and the absence of the member as well as the value. Every arm asserts
through materialize, because a bare length passes on a wrongly typed column. A
depth-numbered remainder such as .k.size1 is not made correct: it fails with
Code 44 on master too, and only the subcolumn name in the message changes.

Found by the targeted AST fuzzer on an unrelated pull request, STID 1611-37da,
and reported by rorylshanks. It reproduces on plain master, by a plain ALTER
TABLE ADD COLUMN, on Wide and Compact parts and on Memory, and by a direct read
as well as through merge(). It needs enable_nullable_tuple_type, which is off by
default, so it is not reachable in a default configuration.

Co-Authored-By: Claude Opus 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 Aug 26, 2026
@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 code review with
no access to the author evidence. Three rounds; the third raised nothing.

# Sev Finding Verdict Evidence / action
1 ❌ The shape matrix claimed Compact coverage, but no committed arm pinned a Compact part, and that reader locates a missing member's offsets by its own route AGREE, fixed Added a 04770 Compact arm that asserts part_type and the member's absence from the active part, measured in both directions.
2 ⚠️ Every arm stopped at the wrapper without consuming a single name, so an implementation reporting only "none or all" would pass the entire suite AGREE, fixed Added 04329 arms where the wrapper sits below a tuple element, plus one whose remainder adds an array dimension. A narrow none-or-all mutant fails exactly those two with Code: 44 and leaves the contrast cells and all of 04770 untouched, which pins the consumed length at one.
3 ⚠️ The description claimed every arm asserts through materialize; the merge() arm does not AGREE, fixed That arm asserts through the converting step, which is the shape that was reported. Corrected before the final review pass.
4 ⚠️ Could the new throwing getSubcolumnType call turn a working query into an error? DISAGREE The only names that resolve on the previously used wrapped type but not on the base type are sizeN, and for a requested .sizeN the reconstruction never resolved them before either. Both revisions fail that shape with the same error code, which is the depth-numbered case stated in the description.
5 ⚠️ Is the reachability claim falsified by a custom-named tuple, where the descent also stops and no setting is needed? DISAGREE An instrumented build shows the whole column is read for that shape with an empty requested subcolumn, so no subcolumn is built and the early stop is harmless. Array(Variant(...)) and Array(Dynamic) behave the same way.
6 ⚠️ #116393 touches the same file and the same function DISAGREE It is open and unmerged, and it changes NestedUtils.* in none of its files, so the descent still stops at Nullable reporting nothing and it does not fix this. Disclosed rather than blocked, with one caveat for whoever lands second: its hunk ends one blank line above this one, and it makes the collected element list more complete, which is exactly the input the new dimension check reads, so that check is worth re-running once both are in.
7 💡 The Wide fixture leaves the block-number and block-offset settings randomized while the Compact one pins them DISAGREE The asymmetry is load-bearing on both sides. A plain DROP COLUMN on a Wide full-storage part never reaches the mutation interpreter, so nothing materializes those columns there, while the compact path pushes every surviving column through it and does. index_granularity_bytes = 0 keeps the Wide fixture out of that path.
8 💡 The commit message called a BETA-tier setting experimental; the description explained the no-op property with a premise that is false for a member carrying no tuple element on its path; the new type walk adds one traversal per defaulted column AGREE on the first two, both corrected. Noted on the third: it is a fraction of two comparable walks the same loop already performs, on a defaulted-column path.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding. I also re-derived the dimension arithmetic, the new internal check's reachability, the
determinism of the new system.parts assertions under settings randomization, and the template and
description budgets; those closed clean and are not listed.

Session id: cron:clickhouse-review-slot-11:20260826-160300

@clickhouse-gh clickhouse-gh Bot closed this Aug 26, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 6 statements, one clickhouse local invocation, LOGICAL_ERROR every run. Not a rate.
b Root cause explained? getBaseTypeOfArray consumes only a prefix of the tuple-element path and did not report how much; the caller stripped the whole path, so the subcolumn name reaching createColumnWithDefaultValue was empty and IDataType::getSubcolumn was skipped, giving the parent's type. Confirmed by instrumenting the strip site, not by reading alone.
c Fix matches root cause? Yes, the contract is fixed at the source. No wrapper enumeration, no tag, no widened bound, no guard at the failure site.
d Test intent preserved / new tests added? 8 arms added across 2 existing files; none removed, weakened or retagged. All but the merge() arm assert through materialize, since a bare length passes on a wrongly typed column; that one asserts through the converting step it reported. Two arms consume a strict prefix of the path, pinning a consumed length that is neither zero nor the whole path, and one of those also carries a remainder that adds an array dimension. The Compact arm additionally asserts the part kind and the member's absence from the active part, so it cannot silently degrade into a copy of the Wide arm.
e Both directions demonstrated? Yes, on Build-ID-verified binaries from one tree: base aborts with the reported signature, fixed returns the correct value. Both files pass 50 randomized runs each.
f Fix is general across code paths? Both callers of fillMissingColumns measured and both were affected (MergeTree reader and ReadFromMemoryStorageStep); Wide and Compact; ADD COLUMN and DROP plus re-ADD; direct read and merge(). getBaseTypeOfArray has one caller.
g Fix generalizes across inputs? Matrix measured: Nullable(Tuple) at depth 1 and 2, Map and Array inside the tuple, custom-named Point, Variant, Dynamic, share_nested_offsets 0 and 1, column present and absent, empty and 1 and 2 element rows. One remainder shape is not made correct and already fails identically on master (Code: 44 for a sizeN tail); it is stated in the description.
h Backward compatible? Yes. No setting added or redefaulted, so no SettingsChangesHistory.cpp entry; no serialization or on-disk format change. Blocks that were malformed become correct.
i Invariants and contracts preserved? The restored invariant is that the reconstructed column has exactly the requested type. Offsets wrapping order and data_size are untouched; the new call is on the already built base type with no lifetime change; the dimension check precedes the subtraction it guards, so no unsigned wraparound is reachable. No concurrency, I/O or error-path change. The new internal check did not fire once across every arm, every carrier probe, 100 randomized test runs and a 412-test sweep.

Session id: cron:clickhouse-impl-slot-4:20260826-153500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @CurtizJ, could you review this? getBaseTypeOfArray stops descending at a wrapper such as Nullable between the array and the tuple, but its caller stripped the whole tuple-element path from the subcolumn name regardless, so the synthesized default column for a missing Nested member got the parent type and the block no longer matched its own header; the descent now reports how many names it consumed and the caller leaves the remainder to IDataType::getSubcolumn.

@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0be2fee]

Summary: ❌

job_name test_name status info comment
Docs examples FAIL
Documentation examples FAIL cidb

AI Review

Summary

This PR fixes default-column reconstruction for missing Nested member subcolumns under shared offsets when the member type contains a wrapper between the array and the tuple. I did not find a remaining code-level correctness issue in the current diff, but the changelog category still overstates the release scope of the fix.

PR Metadata
  • Changelog category: Bug Fix does not match the surface described in the PR. Every new reproducer here requires enable_nullable_tuple_type = 1, and Nullable(Tuple(...)) is still documented as a Beta feature rather than an official stable surface. Suggested replacement:
    - Improvement
  • Changelog entry: if the category is changed to Improvement, an entry is still required. The current entry is specific and user-readable enough to keep.
Final Verdict

✅ No blocking code issues found in the current diff. Change the changelog category to Improvement before merge.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.30% 87.30% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 25/31 (80.65%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Changelog entry: agreed, rewritten. It was past tense and described internals; the new one follows docs/changelog_entry_guidelines.md.

Changelog category: keeping Bug Fix. The reachability half of the finding is correct, and the PR body already says every shape needs enable_nullable_tuple_type. What I disagree with is the step from there to Improvement:

  • The setting is BETA, not EXPERIMENTAL (src/Core/Settings.cpp:8674; the two are distinct values at src/Core/SettingsTierType.h:21 and :23). docs/reference/settings/beta-and-experimental-features.mdx:13 says beta features "are officially supported by the ClickHouse team" while experimental ones "aren't officially supported", and :72 lists this setting under Beta settings.
  • Official release builds return the error to the user, so the misbehavior is in a stable release: 26.6.4.26, 26.7.6.17 and 26.8.1.2014 each answer the reproducer with Code: 49 ... Unexpected return type from materialize. 25.8.34.1 does not know the setting (Code: 115), so exposure begins at 26.1, where it was added.
  • CHANGELOG.md carries 16 Bug Fix entries mentioning Nullable(Tuple(...)), 11 of them not mine (7 by the feature's author, 4 by a senior maintainer). PR 97582 is this same class, a LOGICAL_ERROR on a subcolumn of Nullable(Tuple(...)), and it was categorized Bug Fix while the setting was still experimental.

Switching would also swap pr-bugfix for pr-improvement (ci/jobs/scripts/workflow_hooks/pr_labels_and_category.py:10, :31) and make the bugfix validation job skip (ci/jobs/unit_tests_bugfix_validation_job.py:712), dropping that gate.

Body updated; no code change in this round.

@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0be2fee9c with master 90edfe017 (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 711.21 MiB 708.17 MiB -3.05 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

10772 translation units recompiled, 12728 s compile time in total, 10297 of them have a recent master baseline.

Translation unit Master PR Δ vs median
contrib/grpc-cmake/__/grpc/src/core/resolver/xds/xds_resolver.cc 6.9 s 12.9 s +5.7 s (+80%)
contrib/grpc-cmake/__/grpc/src/core/ext/transport/chttp2/transport/http2_server_transport.cc 10.3 s 16.2 s +5.5 s (+52%)
contrib/grpc-cmake/__/grpc/src/core/client_channel/client_channel.cc 6.5 s 12.2 s +5.5 s (+82%)
contrib/grpc-cmake/__/grpc/src/core/server/xds_server_config_fetcher_legacy.cc 6.4 s 12.0 s +5.4 s (+81%)
contrib/wasmedge-cmake/__/wasmedge/lib/executor/instantiate/table.cpp 10.4 s 5.4 s -5.3 s (-49%)
contrib/grpc-cmake/__/grpc/src/core/client_channel/client_channel_filter.cc 5.7 s 10.9 s +5.1 s (+87%)
contrib/grpc-cmake/__/grpc/src/core/load_balancing/rls/rls.cc 6.4 s 11.6 s +5.0 s (+75%)

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 0be2fee

Every failure below has an owner: a fixing PR (ours 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
Docs examples / Documentation examples repo-wide stale allowlist entry, not this diff: after CatBoost was removed in #109710 (merged 14:36Z) the Function/catboostEvaluate#0 entry in the docs-examples known-failures list matches no entity, so the job exits with 1 known failure(s) no longer exist and must be removed #116566 (external, merged 20:09:12Z)
Mergeable Check aggregator verdict, driven solely by the row above #116566 (external, merged)
PR workflow status context, same single cause #116566 (external, merged)

Breadth places the cause off this branch: today that exact message produced 66 distinct PR carriers
plus 4 true-master runs (head_ref = 'master') between 16:29Z and 21:19Z. #116566 restored the
entity, and master's Docs examples has been green since 22:24Z on b37671338e67.

The fix is not an ancestor of this head (compare(b37671338e67...0be2fee9c3cd) = diverged), so this run
predates it. I am not merging master purely to pick it up: #116586 re-applies the CatBoost removal
and would restore the same red, and every push here costs a maintainer a manual workflow approval.
The next push on this branch re-runs the job with the fix present.

157 of the checks on this head are green and 20 are the usual skips; that one row and its two
aggregators are the only reds, so nothing else is outstanding.

Session id: cron:our-pr-ci-monitor:20260826-230000

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@groeneai
groeneai requested review from Avogar and nihalzp October 4, 2026 11:43
@clickhouse-gh clickhouse-gh Bot added comp-data-types Type system & core datatypes used across query planning/execution. and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026

This branch has not been deployed

No deployments
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-data-types Type system & core datatypes used across query planning/execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant