Skip to content

Resolve the 26.3 cherry-pick of #110584: Fix IS NULL after metadata-only T to Nullable(T) ALTER with optimize_functions_to_subcolumns - #116837

Merged
PedroTadim merged 1 commit into
ClickHouse:26.3from
groeneai:groeneai/resolve-26.3-cherry-pick-110584
Sep 10, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:26.3from
groeneai:groeneai/resolve-26.3-cherry-pick-110584

Conversation

@groeneai

@groeneai groeneai commented Aug 28, 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):

Fix wrong IS NULL / IS NOT NULL / count() results with optimize_functions_to_subcolumns on a column that was made Nullable by a metadata-only ALTER MODIFY COLUMN T to Nullable(T). For parts written before the conversion, the .null subcolumn was filled from the storage-type default (NULL) instead of being derived from the physically-present parent column, so existing not-null rows were wrongly reported as NULL.

Description

Related: #110584 (the merged master fix), #112447 (the robot cherry-pick), #110555 (the reported bug).

26.3 is the only supported branch still missing #110584. That fix reached 26.5, 26.6 and 26.7 as #112448, #112449 and #112450, all merged by the robot, and #110584 carries pr-must-backport plus pr-backports-created. The 26.3 leg was closed by robot-ch-test-poll on a 7-day inactivity timer, not by a decision, so this PR only resolves the conflicts the automation could not apply.

What breaks on 26.3: a part written before a metadata-only ALTER TABLE t MODIFY COLUMN x T to Nullable(T) has no .null substream. With optimize_functions_to_subcolumns = 1, which is on by default, IS NULL is rewritten to read x.null, and that subcolumn is default-filled from the storage type instead of being derived from the physically-present parent column, so rows that hold real data are reported as NULL. Measured on official 26.3.25.1: SELECT count() FROM t WHERE id = 1 AND x IS NULL returns 1 where the answer is 0, and SELECT x, x.null returns 42 1 instead of 42 0. Official 26.6.4.30 matches the expected output byte for byte.

All three conflicts have one cause: fillMissingColumns gained a master-only bool share_nested_offsets parameter after the 26.3 cut, and this fix appends a further parameter after it, so both sides edit the same parameter list. share_nested has zero occurrences in src/ on 26.3, so that parameter is dropped and additional_available_columns is kept. Nothing else is adapted: the other eight files, all four test files included, land byte-identical to master.

Validation on 26.3: the ported test reproduces the wrong values without the change and matches its reference with it, and 04161_null_subcolumn_after_metadata_only_nullable_alter plus 02941_variant_type_alters each pass 50 of 50 runs under randomized settings.

Version info

  • Merged into: 26.3.33.41

Port the merged master fix "Fix IS NULL after metadata-only T to
Nullable(T) ALTER with optimize_functions_to_subcolumns" (ClickHouse#110584) onto
26.3, which is the only supported branch still missing it.

On 26.3, a part written before a metadata-only
ALTER TABLE t MODIFY COLUMN x T -> Nullable(T) has no .null substream.
With optimize_functions_to_subcolumns = 1 (on by default) IS NULL,
IS NOT NULL and count(x) are rewritten to read x.null, and that subcolumn
is default-filled from the storage type instead of being derived from the
present parent column, so rows that hold real data are reported as NULL.
Measured on official 26.3.25.1:
SELECT count() FROM t WHERE id = 1 AND x IS NULL returns 1 where the
answer is 0, and SELECT x, x.null returns "42 1" instead of "42 0".

The robot cherry-pick ClickHouse#112447 could not be applied and was closed by a
timer rather than by a decision. All three conflicts have one cause:
fillMissingColumns gained a master-only bool share_nested_offsets
parameter after the 26.3 cut, and this fix appends a further parameter
after it, so both sides edit the same parameter list. share_nested has
zero occurrences in src/ on 26.3, so that parameter is dropped and
additional_available_columns is kept. Nothing else is adapted: the guard
body, the evaluateMissingDefaults rewrite, both MergeTree call sites and
all four test files land byte-identical to master.

MergeTreeLazilyReader does not exist on 26.3, and MergeTreeReadersChain
runs fillMissingColumns before performRequiredConversions exactly as
master does, so the fix is exercised in the order it was designed against.

Related: ClickHouse#110584
Related: ClickHouse#112447

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work labels Aug 28, 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; 3 findings; reviewed
against base aa7169458e59f446, 11 files, +267/-60).

# Sev Finding Verdict Evidence / action
1 ❌ After RENAME COLUMN y TO x followed by the metadata-only MODIFY COLUMN x Nullable(UInt8), the new availability guard misses the injected parent, so x.null is still default-filled (src/Interpreters/inplaceBlockConversions.cpp:449-456) DISAGREE for this PR, fact agreed Mechanism confirmed: IMergeTreeReader::getStorageAndSubcolumnNameInPart rewrites the parent to its old on-disk name, so available_columns holds y while converted_requested_columns holds x. But every line on that path is byte-identical to the merged master fix, so the gap is identical on master, 26.5, 26.6 and 26.7, and it is not a regression: before the fix the same subcolumn was never read and was default-filled to the same wrong value. Fixing it only here would put a new fix on a release branch ahead of master. It needs a master PR, then the usual backport label.
2 ⚠️ The two sections labelled compact do not pin min_bytes_for_wide_part, so randomization can run them through the wide reader DISAGREE True and quantified: tests/clickhouse-test:1411 uses threshold_generator(0.3, 0.3, 0, ...), which returns 0 in about 30% of runs. The arms assert values and never the part format, so this can never produce a false failure; it only costs compact coverage in those runs, and the wide section pins the threshold itself. The file is byte-identical to master's, so a 26.3-only pin would de-sync it and guarantee a conflict on the next backport touching it.
3 💡 Some comments do not backtick literal names, and one says not crash where the project asks for exception DISAGREE The rules do bind (.claude/CLAUDE.md), but all 18 added comment lines are byte-identical to text already merged on master, 26.5, 26.6 and 26.7. Rewording only the 26.3 copy would de-sync four branches and break the blob-identity check that makes this resolution auditable. Any change belongs on master first.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Why fidelity is the standard applied to all three: the resolution's whole claim is that it is
master's merged fix unchanged. Normalizing the hunks against master's own diff leaves exactly
three differing lines, each the mechanical consequence of share_nested_offsets not existing
on 26.3, where git grep share_nested -- src/ returns 0. The other eight files, all four test
files included, land byte-identical to master.

Session id: cron:clickhouse-review-slot-10:20260828-071300

@clickhouse-gh clickhouse-gh Bot closed this Aug 28, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [ea5e291]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan, db disk, distributed plan, sequential) failure
02916_another_move_partition_inactive_replica FAIL cidb

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, deterministic rather than a rate: clickhouse local --queries-file tests/queries/0_stateless/04161_null_subcolumn_after_metadata_only_nullable_alter.sql on a 26.3 build. No server, no concurrency, no randomization needed.
b Root cause explained? Yes. A part written before a metadata-only ALTER TABLE t MODIFY COLUMN x T to Nullable(T) has no .null substream. optimize_functions_to_subcolumns rewrites IS NULL to read x.null, and that subcolumn was default-filled from the storage type instead of being derived from the physically-present parent column, so not-null rows read as NULL.
c Fix matches root cause? Yes. This is the merged master fix #110584 ported verbatim, minus one parameter that does not exist on 26.3. No widened bound, no no-random-* tag, no reduced dataset, no defensive guard.
d Test intent preserved / new tests added? Yes. All four test files land byte-identical to master, asserted against master's blobs. No 04161* file existed on 26.3, so the regression test is new coverage here; the 02941_variant_type_alters reference change turns \N cells into real values, which tightens the test rather than weakening it.
e Both directions demonstrated? Yes, on binaries with different Build IDs. Pristine 26.3 returns 1 for SELECT count() FROM t WHERE id = 1 AND x IS NULL where the answer is 0, and 42 1 for SELECT x, x.null instead of 42 0; with the change the test output matches its reference byte for byte. Both arms checked for a mid-file abort.
f Fix is general across code paths? Yes. Both callers of DB::fillMissingColumns on 26.3 are enumerated (one passes nullptr, so the guard short-circuits by design) and the single caller of the member function is the site changed here. MergeTreeLazilyReader does not exist on 26.3, and MergeTreeReadersChain runs fillMissingColumns before performRequiredConversions exactly as master does.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, and the ported test exercises it: UInt256, String, Tuple and Variant parents, Compact and Wide parts, the Memory engine, apply_mutations_on_fly, and both DEFAULT NULL and plain MODIFY COLUMN. The guard keys on isSubcolumn() and getNameInStorage() rather than on a type predicate, so there is no wrapper-stripping hazard.
h Backward compatible? (maintainer-approved exception only) Yes. No setting default, serialization format or validation changes. One internal function gains a defaulted parameter, so no SettingsChangesHistory.cpp row applies and no existing call site can break.
i Invariants and contracts preserved? Yes. The invariant is that a requested subcolumn whose parent is available must be derived from that parent and never default-filled from the storage type. It holds on every path: the guard short-circuits when storage_snapshot is absent, and it defers to evaluateMissingDefaults, which runs after performRequiredConversions in the same relative order as on master at this fix's own base.

Known limitation, unchanged by this port and identical on master and every other branch that carries #110584: when the parent was renamed by ALTER TABLE ... RENAME COLUMN before the metadata-only MODIFY, the availability guard compares the current metadata name against the on-disk part name, misses, and x.null is still default-filled. Behaviour before the fix is the same wrong value for that case, so it is uncovered ground rather than a regression, and it belongs on master rather than on a release branch. See the adjudication log for the trace.

Validation on 26.3: 04161_null_subcolumn_after_metadata_only_nullable_alter 50 of 50 runs OK, and 02941_variant_type_alters 50 of 50 runs OK with --long-test-runs-ratio 1 so the long tag does not silently reduce 50 to 5.

Session id: cron:clickhouse-impl-slot-6:20260828-054600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ @CheSema, could you review this? It is the 26.3 leg of #110584, which the robot cherry-pick could not apply: all three conflicts are the same parameter list, because fillMissingColumns gained a master-only share_nested_offsets argument after the 26.3 cut and this fix appends another one after it. That argument has zero occurrences in src/ on 26.3 so it is dropped, and everything else, all four test files included, lands byte-identical to master.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ea5e291d0c29c5b92cbfe62357204ca9040a8bf6

CI is fully finished on this head. Two concurrent BackportPR workflow runs were created 10 s apart
against this identical tree, 33 jobs each, Config Workflow and Finish Workflow success in both:
run 33153728291 is completed/success with 31 success and 2 skipped, run 33153739422 is
completed/failure with 30 success, 2 skipped and the one failure below. The failure has an owner
and is not caused by this cherry-pick.

Check / test Reason Owner / fixing PR
Stateless tests (amd_asan, db disk, distributed plan, sequential) / 02916_another_move_partition_inactive_replica the 26.3 copy of this test asserts the exact part NAMES left after two OPTIMIZE statements (all_0_1_1, all_2_3_1), and which adjacent pairs a racing merge assignment picks is not deterministic on this shape. This run produced all_0_0_0 and all_1_3_2, i.e. the same TWO active parts under different names fixing PR #100924 (external, merged 2026-03-31), absent from 26.3

The owner is exact rather than same-area: #100924 "Fix flaky test
02916_another_move_partition_inactive_replica" replaces that assertion with
select count() from system.parts ... and active against a reference of 2, so this run's output
satisfies the fixed test and fails only the pre-fix one. The 26.3 blob still carries the old
select name, active form, so the fix is not on this branch. It is a test-only change on master;
bringing it to 26.3 is a v26.3-must-backport label on #100924, which is a maintainer action, so I
am not hand-authoring it here and it is deliberately not folded into this cherry-pick.

Independently of that, the tree is exonerated by a control this head supplies for free: the two
concurrent runs executed the same commit and the same leg, and disagreed. A verdict that flips
between two runs of one tree is state or timing dependent, not tree dependent. This PR's diff is the
read-path column materialization for a metadata-only Nullable ALTER plus its two tests, and it
touches nothing that selects parts for merging.

Session id: cron:our-pr-ci-monitor:20260828-100000

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@PedroTadim

Copy link
Copy Markdown
Member

backporting the PR that fixes the CI failure

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-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants