Skip to content

Pin the dotted Nested .null subcolumn read after a metadata-only Nullable ALTER - #113646

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/pin-dotted-nested-null-subcolumn
Aug 7, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/pin-dotted-nested-null-subcolumn

Conversation

@groeneai

@groeneai groeneai commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Add a regression test for reading the .null subcolumn of a dotted Nested member on a part written before a metadata-only T to Nullable(T) ALTER.

Description

Test-only, no src/ change.

A part written before a metadata-only T -> Nullable(T) MODIFY COLUMN has no .null
substream, so the null map must be derived from the parent column that is in the part. For a
dotted Nested member the parent has to be resolved from metadata:
Nested::convertToSubcolumns (on by default via share_nested_offsets) rebuilds the requested
arr.n.null as a subcolumn n.null of arr, so its getNameInStorage() becomes arr while
the part supplies arr.n. Comparing that remapped spelling directly does not find the parent, and
the column is default-filled to all-NULL: wrong results at default settings.

Master resolves the parent from metadata and is correct; the gap is that no test pinned it.
Restoring the inline spelling and running every plausible pinner, all pass: the four stateless
tests holding both a MODIFY COLUMN ... Nullable and a dotted or declared-Nested column
(03210, 04161, 04338, 04697), plus 03742 and 04770. So a "this predicate looks dead,
remove it" change reintroduces the wrong results with every check green.

The test asserts the .null value (not just its length, which is what makes an existing
neighbour blind here) on an unrewritten Wide and Compact part, plus two controls that must read the
same either way: share_nested_offsets = 0 and an undotted column. It also asserts the part is
still the pre-ALTER one, since a synchronous ALTER would rewrite it.

On that same binary both witness rows go [0,0] -> [1,1] while all five control lines are
unchanged, which is what makes the failure attributable. 100/100 runs pass on master (50
randomized, 50 off). Untagged: share_nested_offsets is not randomized, and the randomized
settings the test needs are pinned in its CREATE TABLE ... SETTINGS.

The release branches still carry the inline spelling, so this class may be live there. This test is
master-only.

Version info

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

…data-only Nullable ALTER

A part written before a metadata-only `T` -> `Nullable(T)` `MODIFY COLUMN` still holds
non-nullable data and has no `.null` substream, so the null map has to be derived from
the parent column that is present in the part. For a dotted `Nested` member that requires
resolving the parent from metadata: `Nested::convertToSubcolumns`, reached whenever
`share_nested_offsets` is on (default true), rebuilds the requested `arr.n.null` as a
subcolumn `n.null` of `arr`, so `getNameInStorage()` returns `arr` while the part supplies
`arr.n`. `NamesAndTypesList::contains` is an exact-name compare, so comparing the remapped
spelling directly does not find the parent and the column falls through to
`createColumnWithDefaultValue`, giving an all-NULL null map where all-zero is correct.

Master resolves the parent from metadata and is correct. Nothing pinned that, which is what
this test adds. Restoring the older inline spelling and running every plausible pinner shows
all of them pass: `03210`, `04161`, `04338` and `04697` (the stateless tests holding both a
`MODIFY COLUMN ... Nullable` and a dotted or declared-`Nested` column), plus `03742` and
`04770`. The uniform reason is that a read of `.null` on a dotted column occurs zero times
in all six, and that read is exactly what the remap rewrites.

The test keeps the part unrewritten (`SYSTEM STOP MERGES` before an `alter_sync = 0` ALTER,
asserted via `system.parts_columns`), since a synchronous ALTER materialises the substream
and would turn every row into a control. Two witnesses cover a Wide and a Compact part,
which are different readers: Nested is collected into `part_columns` only for wide parts,
while `fillMissingColumns` receives the remapped list unconditionally. Two controls must
read the same either way: `share_nested_offsets = 0`, where no remap happens, and an
undotted column.

With the inline spelling restored, both witnesses move from `[0,0]` to `[1,1]` while all
four control lines stay unchanged. 100 runs pass on master, 50 randomized and 50 with
randomization off. The test is untagged: `share_nested_offsets` is not randomized, and the
randomized MergeTree settings it depends on are pinned in `CREATE TABLE ... SETTINGS`, which
wins over runner injection.
@groeneai

groeneai commented Aug 6, 2026

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

An independent cold review plus a second-model gate ran over this change before it was opened.
Six items were raised, all agreed, none disputed. Nothing here is a behaviour claim about
ClickHouse: the diff is two new test files and no src/ line.

⚠️ Publication contract was wrong and is corrected. The frozen PR body on disk still held a
retired draft from an earlier, abandoned attempt in this same work stream, which argued that
isSubcolumnOfAvailableColumn was redundant. That conclusion was retracted publicly in #112997
before this PR existed. Publishing it would have opened a PR whose title and description
contradicted both its own diff and that correction. The retired draft was archived rather than
deleted, and the gate below ran against the body actually published (its hash is recorded in the
gate ledger, so the reviewed contract and the posted one are provably the same file).

⚠️ A countable claim did not reproduce. The description said "all four control lines are
unchanged" under the mutant. Counting the shipped file gives no reading equal to four: 18 SELECT
statements are 6 label lines, 2 witness lines, 5 part-state probes and 5 remaining assertions, and
the quoted diff annotates five lines as unchanged. Corrected to five. The other count in the
description was re-derived and is exact: intersecting the stateless tests that carry a
MODIFY COLUMN ... Nullable (35 files) with those declaring a dotted or Nested( column (473)
yields exactly 03210, 04161, 04338, 04697.

💡 Asymmetry noted, deliberately not changed. The Wide arm proves the part is still the
pre-ALTER one with a pair of probes, system.parts_columns.type (the on-disk, non-nullable type)
next to system.columns.type (the new nullable one). The Compact arm omits the second. That is
gratuitous, but the Wide arm already pins the mechanism and both witness rows move under the
mutant, so there is no liveness consequence; adding a probe now would discard a clean gate pass and
a 100-run randomized verification for a cosmetic improvement.

Verified independently while reviewing, rather than taken from the author's notes: the remap is
reached at default settings (share_nested_offsets defaults true); every active release branch
still carries the pre-remap inline spelling, which is why this test is master-only and carries no
backport label; the runner does not randomize share_nested_offsets, and the randomized settings
the fixture depends on are pinned in CREATE TABLE ... SETTINGS, which takes precedence over
runner injection, so leaving the test untagged is measured rather than assumed. The test number is
free on master, the style gap check passes with an injected positive control, and the branch was
absent from the fork before this push.

The second-model gate returned no findings, having read the complete new SQL and reference, the
Nested and Nullable fill and read paths, both the wide and compact readers, the random-setting
machinery, and the analogous existing tests. It ran without access to my own review notes, so its
silence is independent rather than an echo.

Session id: cron:clickhouse-review-slot-11:20260806-100300

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, in the form a test-only PR needs: the new test FAILS on demand when the metadata-resolving predicate is replaced by the pre-#112769 inline spelling. Deterministic, one command, no randomization or concurrency involved. The mutant's source is byte-identical (md5 8e00f21ebbf060cc) to a locally committed revert of that predicate, so the mutation is the exact regression being guarded, not an approximation of it.
b Root cause explained? A part written before a metadata-only T -> Nullable(T) MODIFY COLUMN has no .null substream, so the null map must be derived from the parent that is in the part. Nested::convertToSubcolumns (reached whenever share_nested_offsets is on, default true at MergeTreeSettings.cpp:280) rebuilds arr.n.null as a subcolumn n.null of arr, so getNameInStorage() returns arr while the injected parent is keyed arr.n. NamesAndTypesList::contains is an exact-name compare, so the remapped spelling does not find the parent and the column falls through to createColumnWithDefaultValue: an all-NULL null map where all-zero is correct.
c Fix matches root cause? Tests only, no src/ change, so there is no fix to match. The measured question is whether anything already pins this, and the answer is empirical rather than by grep: on the mutant binary 6 of 6 candidate pinners pass and only the new test fails. The six are the four stateless tests holding both a MODIFY COLUMN ... Nullable and a dotted or declared-Nested column (03210, 04161, 04338, 04697) plus 03742 and 04770. The uniform reason: a read of .null on a dotted column occurs 0 times in all six (03742 and 04770 read a .null, but of an undotted column; 04161's two dotted hits are comment lines; 03210 executes no ALTER at all, it only formats query text), and that read is exactly what the remap rewrites.
d Test intent preserved / new tests added? New test added; no existing test touched. Every expected value was produced by running the fixture on pristine origin/master and then shown to move under the mutant, so no reference line was written to make a red line green.
e Both directions demonstrated? Yes. Passes on pristine origin/master (Build ID 43a456adb8095cb2, server buildId asserted equal to readelf -n before every verdict); fails on the mutant (Build ID dbcc2b99927118ce). Both witness rows move [0,0] -> [1,1] and all five control lines are unchanged, which is what makes the failure attributable to the predicate rather than to the fixture. After the mutation the tree was restored and rebuilt to Build ID 43a456adb8095cb2 byte-exactly, so the shipping binary is the one every number here describes.
f Fix is general across code paths? Tests only. The two witness rows are the same shape on a Wide and a Compact part, which are different readers: part_columns is collected for Nested only when isWidePart() (IMergeTreeReader.cpp:55-57) while fillMissingColumns receives the remapped list unconditionally (:190-196). Four further carriers (a sibling member, a declared Nested(...), a nested-Tuple element's nullability, and the apply_mutations_on_fly route) were measured and deliberately not shipped: all reach the identical decision and would add spellings rather than decisions.
g Fix generalizes across inputs (params/datatypes/wrappers)? Randomization is left ON and the test is untagged: share_nested_offsets is not randomized by the runner (0 hits in tests/clickhouse-test; control min_bytes_for_wide_part = 2), and the randomized MergeTree settings the fixture depends on are pinned in CREATE TABLE ... SETTINGS, which wins over runner injection. 100/100 runs pass (50 randomized, 50 with randomization off). A 120-test nested/subcolumn slice was run on the shipping tree and on the same tree with these two files removed: identical 8-failure sets, 0 only-in-fix, 0 only-in-base.
h Backward compatible? (maintainer-approved exception only) Yes, trivially: two new files under tests/queries/0_stateless/, no source change, no setting, no format, no SettingsChangesHistory entry owed. The test is master-only and carries no backport label, so it cannot redden the release branches, which lack the corresponding fix.
i Invariants and contracts preserved? No source contract is touched. Test number 04773 was re-verified free on all three dimensions at handoff: absent from live origin/master by git ls-tree (positive control 04770 returns 2), no open PR adds a 04773_* path (1888 open PRs swept, batched GraphQL 0 errors, control 1211 touching tests/queries/0_stateless/, and the 61 page-capped PRs re-probed individually via REST with #112990 as a positive control), and 0 matches across live fleet worktrees (control 04770 returns 72). check_gaps_in_tests_numbers returns [] on this tree's CI file list, with an injected 99999_probe.sql correctly reporting Gap (4811, 99999) > 100 as the positive control.

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ, could you review this? It is test-only: nothing in the suite pinned reading the .null subcolumn of a dotted Nested member on a part written before a metadata-only T to Nullable(T) ALTER, where Nested::convertToSubcolumns remaps the requested name so the parent must be resolved from metadata rather than from getNameInStorage.

@PedroTadim PedroTadim self-assigned this Aug 6, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 6, 2026
@PedroTadim
PedroTadim enabled auto-merge August 6, 2026 10:59
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0d61c6]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR adds a stateless regression test for reading the .null subcolumn of a dotted Nested member after a metadata-only Array(T) to Array(Nullable(T)) MODIFY COLUMN. I traced the current read path through injectRequiredColumns, IMergeTreeReader, and fillMissingColumns, checked the new wide/compact/control cases against the implementation, and did not find actionable review findings.

Final Verdict

✅ No blocking issues found.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 6, 2026
@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — c0d61c6

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
Stress test (amd_tsan) / Hung check failed, possible deadlock found deadlock (a cancelled odbc() query stuck 422 s in an uninterruptible Poco HTTP read inside the XDBC bridge) #112144 (ours, open)

Not caused by this PR: the diff is two stateless test files
(04773_dotted_nested_null_subcolumn_metadata_alter.{sql,reference}) and greps 0 for
odbc / xdbc / ReadWriteBufferFromHTTP / HTTPClientSession / StorageURL
(positive control: 17 hits for its own nested-subcolumn symbols).

The hung row read from the hung_check.log artifact, not from a truncated context field:
elapsed 422.099392, is_cancelled: 1, read_rows: 0,
query: SELECT count() > 1 AS ok FROM (SELECT * FROM odbc('[HIDDEN]', 'system', 'tables')).
The running thread is blocked in poll under Poco::Net::SocketImpl::pollImpl <-
HTTPClientSession::receiveResponse <- EndpointConnectionPool <-
ReadWriteBufferFromHTTP::callImpl <- doWithRetries <- initialize <-
BinaryRowInputFormat <- StorageURLSource::generate <- PullingPipelineExecutor::pull.
All nine frames match the signature #112144 fixes, and that fix is not on this head:
src/IO/ReadWriteBufferFromHTTP.cpp at this sha has 0 occurrences of the cancellation check
while the control string doWithRetries appears 4 times.

The remaining 174 check-runs are 57 success and 116 skipped, with Config Workflow and
Finish Workflow both green and 41 real test jobs green.

Session id: cron:our-pr-ci-monitor:20260806-143000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 7, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 7, 2026
Merged via the queue into ClickHouse:master with commit e5c489c Aug 7, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 7, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci 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.

3 participants