Skip to content

Resolve the 25.8 cherry-pick conflicts of #110584 - #112990

Closed
groeneai wants to merge 1 commit into
ClickHouse:25.8from
groeneai:backport-110584-25.8
Closed

groeneai wants to merge 1 commit into
ClickHouse:25.8from
groeneai:backport-110584-25.8

Conversation

@groeneai

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

Fixed IS NULL, IS NOT NULL and count returning wrong results with optimize_functions_to_subcolumns = 1 when reading a part written before a metadata-only ALTER TABLE ... MODIFY COLUMN T -> Nullable(T). The .null subcolumn is now derived from the present parent column instead of being filled with the storage-type default.

Description

The robot cherry-pick of #110584 to 25.8 (#112446) is CONFLICTING in 5 files, so the automation cannot merge it. This is the resolved tree as a single commit on the current 25.8 tip, so it can be merged here or built on directly. Reported bug: #110555.

All five conflicts have one cause: fillMissingColumns's signature evolved on master after the 25.8 branch cut, and the fix appends a parameter to it. The resolution keeps 25.8's API shape: StorageMetadataPtr is kept and share_nested_offsets dropped (absent here); getColumnFromBlock.cpp keeps hasDynamicSubcolumns, since hasDynamicStructure is not in 25.8's IDataType; and in MergeTreeBlockReadUtils.cpp the parent injection is open-coded, because the add_column lambda and isTextIndexVirtualColumn branch in the conflict markers are master-only and would not compile. The test drops auto_statistics_types, also absent here.

One change is 25.8-specific rather than a port. MergeTreeLazilyReader::readLazyColumns ran fillMissingColumns before performRequiredConversions, the reverse of MergeTreeReadersChain; that file exists only on this branch, so the upstream fix was never exercised against it. With the new guard the evolved subcolumn is left unfilled, and evaluateMissingDefaults then publishes the still part-typed parent under its requested Nullable type, so SerializationNullable hits Bad cast from ColumnVector<...> to ColumnNullable. Untreated, the backport would turn a wrong-results bug into a logical error on a path that is on by default. Running the conversions first restores the order the fix was designed against, and 04161 grows a lazy-materialization arm that kills the server when the reorder is reverted.

Validated in both directions with a clang-19 Debug build (25.8's pin): the official 25.8.29.42 binary gives the pre-fix wrong answer for every subtest of 04161_null_subcolumn_after_metadata_only_nullable_alter, a local build of the pristine branch reproduces that byte-for-byte, and this tree matches the reference exactly. 50 randomized runs of 04161 and 02941_variant_type_alters: 0 failures.

The robot cherry-pick of ClickHouse#110584 (backport/25.8/110584, PR ClickHouse#112446) conflicts
in 5 files because fillMissingColumns's signature evolved on master after the
25.8 branch cut, and the fix appends a parameter to that same signature.

Per-file resolution, keeping 25.8's own API shape:

- inplaceBlockConversions.{cpp,h}: keep 25.8's StorageMetadataPtr parameter and
  append additional_available_columns. share_nested_offsets is dropped: that
  MergeTree setting does not exist on 25.8 and is not part of this fix.
- IMergeTreeReader.cpp: keep 25.8's body, which has no if (!missing) early-out,
  no converted_requested_columns and no storage_settings member, and thread
  previous_step_columns through its own unconditional convertToSubcolumns call.
- getColumnFromBlock.cpp: keep 25.8's hasDynamicSubcolumns spelling.
  hasDynamicStructure does not exist in 25.8's IDataType, so the narrower
  master predicate is not available here.
- MergeTreeBlockReadUtils.cpp: keep 25.8's inlined required_columns block and
  add the parent-injection fall-through open-coded. The add_column lambda and
  the isTextIndexVirtualColumn / hasMaterializedTextIndex branch that appear in
  the conflict markers are master-only (0 occurrences anywhere in 25.8's src/),
  so taking the master side would not compile.

The test also drops auto_statistics_types, which does not exist on 25.8.

This branch additionally fixes a conversion-order defect that exists only on
25.8. MergeTreeLazilyReader::readLazyColumns ran fillMissingColumns ->
evaluateMissingDefaults -> performRequiredConversions, the reverse of
MergeTreeReadersChain. That file exists only on 25.8 (master and 26.3 read
lazily through LazilyReadFromMergeTree.cpp), so the upstream fix was never
exercised against it.

With the backported fillMissingColumns guard, an evolved subcolumn slot is
left unfilled, and evaluateMissingDefaults then publishes the still
part-typed parent under its requested Nullable type. getColumnFromBlock
therefore skips the cast and SerializationNullable::enumerateStreams
assert_casts a non-nullable column: 'Bad cast from type
ColumnVector<wide::integer<256ul, unsigned int>> to ColumnNullable',
aborting in debug and sanitizer builds. Pristine 25.8 default-filled
instead, so the backport alone would have escalated a wrong-results bug into
an abort on a path enabled by default
(query_plan_optimize_lazy_materialization = true).

Running the conversions first restores the contract the upstream fix was
designed against. performRequiredConversions already skips null entries, so
the still-unfilled subcolumn slot is unaffected.

The 04161 test grows a lazy-materialization arm with a pinned ORDER BY /
LIMIT to reach the optimizer; with that change reverted the arm kills the
server, so it is a live guard rather than a passing formality.

Verified in both directions with a clang-19 Debug build of this tree
(25.8 pins clang-19 in ci/defs/defs.py): the official 25.8.29.42 binary
produces the pre-fix wrong answers for every subtest of
04161_null_subcolumn_after_metadata_only_nullable_alter, and this tree
reproduces the reference output exactly.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (3 rounds, all findings resolved)

This tree went through three review rounds before I opened the PR. Summary of what was
found and what changed, so the resolution is auditable.

Round 1 — ❌ blocker, this backport would have escalated a wrong-results bug into a
logical error.
MergeTreeLazilyReader::readLazyColumns runs fillMissingColumns before
performRequiredConversions, the reverse of MergeTreeReadersChain. That file exists only
on 25.8 (0 files on master and on every newer release branch), so the upstream fix was
never exercised against it. With the new guard the evolved subcolumn is left unfilled, and
evaluateMissingDefaults then publishes the still part-typed parent under its requested
Nullable type, so SerializationNullable hits
Bad cast from ColumnVector<wide::integer<256ul, unsigned int>> to ColumnNullable.
Reproduced at exit 134 on the pre-fix head, with the frame chain
assert_cast.h:48 → SerializationNullable.cpp:34 → getColumnFromBlock.cpp:68 → IMergeTreeReader.cpp:225 → MergeTreeLazilyReader.cpp:195. Pristine 25.8 default-fills
instead: wrong value, no abort. The path is on by default
(query_plan_optimize_lazy_materialization = 1). Fixed by running the conversions first,
restoring the order the upstream fix was designed against.

⚠️ major — the test could not reach that carrier. No MergeTree select in 04161 had a
LIMIT, and the lazy optimizer requires a LimitStep above sorting, which is why 50
randomized runs were green while the defect was live. 04161 now has a lazy-materialization
arm; with only the reorder reverted it kills the server, so the arm is proven live rather
than asserted.

💡 nit — the tuple arm's comment overclaimed. It takes the pre-existing
direct-extraction path and cannot redden on revert. Kept as a no-regression guard for the
narrowed cast condition, with the comment corrected to say so.

Round 2 — ❌ blocker in the branch's history, not its code. The robot's backport commit
is a merge -s ours with a second parent on master, so the branch base was genuinely
ambiguous (merge-base --all returned two oids, neither an ancestor of the other). Re-rooted
as a single commit on the current 25.8 tip; the tree is byte-identical, so the validated
binary still corresponds to this source.

Round 3 — clean. 0 findings.

Backport-specific checks, since a master-side review cannot cover them: every master-only
construct absent here was confirmed to be pre-PR master code rather than a dropped part
of the fix, and getColumnFromBlock.cpp keeps hasDynamicSubcolumns because pre-PR master
already used hasDynamicStructure in the same expression while 25.8 has no such
predicate, so the substitution is behaviour-preserving relative to 25.8's own pre-fix code.
02941's two files are byte-identical to the merged versions, and 25.8's pristine copies
matched pre-PR master's, so nothing unrelated came along.

Validation: official 25.8.29.42 gives the pre-fix wrong answer on every subtest, a local
build of the pristine branch reproduces that byte-for-byte, this tree matches the reference
exactly, and 50 randomized runs of 04161 plus 02941_variant_type_alters gave 0 failures.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [7020630]

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 7020630

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.

CI is fully finished on this head: 32 check-runs, 0 queued or in progress, Config Workflow
and Finish Workflow both green. One check failed, and its six reported rows are a single
event: the abort, plus the killed-by-signal, gdb-log, fatal-message and hung-check
consequences of it.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / 03716_multiple_joins_using_top_level_identifier: Logical error: 'Unexpected return type from concat. Expected Nullable(String). Got String.' 25.8 backport gap, not PR-caused a fix task is created (investigating at full effort, fixing-PR link to follow here)
Stress test (amd_tsan) / Server died, Killed by signal (in clickhouse-server.log), Killed by signal (output files), Found signal in gdb.log, Fatal message in clickhouse-server.log, Hung check failed consequences of the same abort as the row above a fix task is created (investigating at full effort, fixing-PR link to follow here)

Why this is not caused by this cherry-pick. The failing query is
SELECT t2.id || '_1' ... LEFT JOIN t2 ON ... LEFT JOIN t3 USING (id), where t2.id is
Nullable(String) from the LEFT JOIN. Under multi-join USING with join_use_nulls the
analyzer mis-derives the USING column type, so the declared result type of concat disagrees
with the type re-derived at execution time. Stress reaches it because it randomizes
join_use_nulls; the same test passes as an ordinary stateless run on 25.8.

That is fixed on master by #92251, whose squash commit b3cf84f4f2b5 is an ancestor of
master but not of 25.8 (verified this run), so 25.8 still runs the query without the fix.
I am not linking #92251 as the owner here, because it is merged and cannot be linked into a
25.8 branch, and I do not hand-author backport PRs. The fix task pursues the label route.

This diff touches none of the analyzer files #92251 changed; it is subcolumn and
metadata-only-nullable-ALTER reader code. The signature is also pre-existing on the 25.8
branch itself: over the last 30 days CIDB records 12 hits on 25.8 branch runs
(pull_request_number = 0) across amd_tsan, amd_msan, amd_ubsan and arm_asan, the earliest on
2026-07-05, plus one hit each on four unrelated 25.8 backport PRs. Zero on master.

Session id: cron:our-pr-ci-monitor:20260802-153000

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up on the Unexpected return type from concat row in the ledger above. This one has a
deliverable, and it needs a label I cannot apply.

Ask: please apply v25.8-must-backport to #91128. @alexey-milovidov, you asked me on
#111910 to keep using the label route via you, so I am asking here rather than hand-authoring
anything.

25.8 is missing two commits, and it is their combination that leaves the branch failing:

Neither is an ancestor of 25.8; both are ancestors of master and of 26.3 / 26.5 / 26.6 /
26.7. So 25.8 runs that test unmuted and unfixed, which is a state master was never in: master
carried the mute from 2025-12-01 until #92251 landed on 2025-12-19 and replaced it with
join_use_nulls = 1 plus RIGHT and FULL JOIN variants.

The trigger is not random, which is why this recurs steadily rather than intermittently:
tests/ci/stress.py:48 sets join_use_nulls=1 as a client option on every stress thread where
i % 3 == 1, and a query-level SETTINGS clause overrides that (I checked). Correcting my own
ledger above, which said stress "randomizes" the setting: it does not, and join_use_nulls is
not in the settings randomizer at all.

Why #91128 rather than the engine fix #92251:

  1. fixing multiple joins with using and join_use_nulls #92251's line is makeNullableOrLowCardinalityNullable(current_type). Master later
    replaced exactly that line with ...NullableSafe(result_type) in Fix Bad cast crash for an explicit JOIN USING key with a Dynamic supertype #107289, to fix a
    Bad cast from type DB::ColumnDynamic to DB::ColumnNullable abort. A fixing multiple joins with using and join_use_nulls #92251-only port would
    land the superseded form on an LTS branch.
  2. fixing multiple joins with using and join_use_nulls #92251 does not port cleanly. 25.8 received Fix qualified column resolution for multiple JOINs with USING #95157 before fixing multiple joins with using and join_use_nulls #92251, master received it after,
    so the block evolved in a different order and the merge conflicts in
    src/Analyzer/Resolve/IdentifierResolver.cpp plus the test file. That means a
    pr-cherrypick PR and hand-resolved analyzer nullability code, most likely by @ vdimir.
  3. Disable join_use_nulls for 03716_multiple_joins_using_top_level #91128 applies clean: 1 file changed, 7 insertions, .reference untouched.

The label expands to 25.8 plus every newer active release, but c96030144ed9 is already an
ancestor of all four 26.x branches, so those resolve to "already up to date" and produce no PR.
Exactly one backport PR results, against 25.8.

To be clear about what this buys: the mute stops 25.8 stress from reporting this, but it does
not fix the branch. 25.8 keeps the underlying join_use_nulls plus multiple-USING defect that
#92251 fixed on master, recorded in #92173 and closed there when master was fixed. Whether that
is worth a hand-resolved 25.8 port is your call, not mine to propose, and I will do whatever you
prefer here. I will post the resulting backport PR link on this PR once it opens.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, all findings resolved)

This deliverable went through the fleet's plan / implement / review pipeline. Gate A passed the
approach clean. Gate B was correctly skipped: there is no code change to score (0 commits,
clean tree, HEAD at plain origin/master), and the deliverable is the comment text above.
The review round below is my own cold review plus adjudication.

Round 0 - 1 blocker, 1 major, 1 nit. All AGREE.

Round 1 - 4 nits, all AGREE, none requiring an implementation round.

  • 💡 The #107289 abort was quoted as Bad cast from ColumnDynamic to ColumnNullable; the
    real message is Bad cast from type DB::ColumnDynamic to DB::ColumnNullable. Corrected, so
    the quoted string is greppable.
  • 💡 A stale self-measured length in review scaffolding. Corrected.
  • 💡 The implement phase deviated from my fix plan on one word and flagged it instead of
    complying: I had written "tracked in Wrong type with multiple joins with using and join_use_nulls #92173", it wrote "recorded in Wrong type with multiple joins with using and join_use_nulls #92173 and closed there".
    I adopted the deviation - Wrong type with multiple joins with using and join_use_nulls #92173 is CLOSED (2025-12-19, one second after fixing multiple joins with using and join_use_nulls #92251 merged), so
    "tracked" would have implied an open issue, which is the same class of inaccuracy the
    blocker existed to remove. My fix plan was wrong on that point.
  • 💡 Sole-carrier check, added at review because the whole ask rests on it and neither
    earlier phase had made it.
    Over 60 days CIDB holds 28 rows with this signature on 25.8
    heads; aggregating the (query: ...) text out of every fatal context yields exactly one
    normalized query, which is query 2 of 03716. Extracting every distinct
    Unexpected return type from X message on 25.8 likewise returns one string. So muting that
    test removes the whole signature from the branch, rather than part of it.

Every mechanical claim in the comment was re-measured independently at review: ancestry on all
six branches, the unmuted 25.8 test blob, #92251's own test diff, the #91128 body quote,
#92173's state and close timing, the deterministic i % 3 == 1 stress trigger and the
randomizer's absence on both branches, both backport simulations against the current 25.8 tip,
the git log -S supersession, #95157's ordering divergence, the label expansion via
select_backport_branches with the real caller constants, the 90-day discovery-window
arithmetic, and the active release branch list.

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-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.

3 participants