Skip to content

Cherry pick #108128 to 26.6: Fix LOGICAL_ERROR in on-fly mutation read when an UPDATE keep-old fallback is read under a non-constant condition - #108389

Merged
robot-ch-test-poll3 merged 5 commits into
backport/26.6/108128from
cherrypick/26.6/108128
Jun 24, 2026
Merged

robot-ch-test-poll3 merged 5 commits into
backport/26.6/108128from
cherrypick/26.6/108128

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #108128

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 5 commits June 22, 2026 13:05
…s not constant-true

MutationsInterpreter lowers UPDATE col = expr WHERE cond to
_CAST(if(cond, _CAST(expr, type), col), type), where type is the post-MODIFY
column type. The if node is declared at that type, and its third argument is the
bare on-disk pre-MODIFY column (the value kept for unmatched rows).

collectColumnsConsumedByChainActions excluded that fallback edge from forced
conversion unconditionally, on the premise that the kept-old value is discarded
and never read. That holds only when cond is constant-true: FunctionIf then
returns the then-branch and never touches the fallback. For a non-constant or
constant-false cond, FunctionIf does read the fallback, but the on-disk col is
left in its pre-MODIFY type while the if node expects the post-MODIFY type, so
the executor aborts with LOGICAL_ERROR: Unexpected return type from if (or a
FunctionIf type-equality assertion). A minimal repro:

  CREATE TABLE t (id UInt64, v String, b UInt8) ENGINE = MergeTree ORDER BY id;
  INSERT INTO t SELECT number, toString(number * 10), number % 2 FROM numbers(10);
  SYSTEM STOP MERGES t;
  ALTER TABLE t UPDATE v = 100 WHERE id > 5 SETTINGS mutations_sync = 0, alter_sync = 0;
  ALTER TABLE t MODIFY COLUMN v UInt64 SETTINGS mutations_sync = 0, alter_sync = 0;
  SELECT v, b FROM t SETTINGS apply_mutations_on_fly = 1;

This crashes on-fly while the same operation materialized synchronously returns
correct results.

The fix ignores the keep-old fallback edge only when the if condition is a
compile-time constant-true (helper ifConditionIsConstantTrue, which descends the
_CAST(..., UInt8) wrapper the mutation builder adds). For a non-constant,
constant-false or NULL condition the fallback counts as a genuine consume and the
column is converted to the post-MODIFY type. The cross-step ordering and the
query PREWHERE skip (perform_alter_conversions) are unchanged, so the
already-covered cases that must stay skipped (an unconvertible on-disk value an
UPDATE replaces under a constant-true condition) remain skipped.

Extends 04338_on_fly_mutation_read_overwritten_lc_source with a regression case
(t_keep_old_nonconst_cond): a partial UPDATE under a non-constant condition that
aborts before this change and matches a synchronous UPDATE + MODIFY after it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…tant-true-only skip

The keep-old fallback edge of an UPDATE's if(cond, expr, col) is no longer
ignored unconditionally. After the constant-true gate added in this PR, the
fallback counts as a genuine consume except when cond is a compile-time
constant-true, so the member declaration's header comment in
MergeTreeReadersChain.h stated a stale invariant. This aligns the comment with
the code in collectColumnsConsumedByChainActions. Comment-only, no behavior
change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The amd_tsan flaky check on ea60fcf was cancelled at the 6h GitHub
Actions wall after the test harness wedged during MinIO docker setup
(Restarting clickminio), before any test ran. The prior commit
63bb1e1 ran the same flaky check green in ~10 min (04338 50x OK,
avg 5.6s). This empty commit re-triggers a fresh CI run.
…-if-return-type-keep-old-fallback

Fix LOGICAL_ERROR in on-fly mutation read when an UPDATE keep-old fallback is read under a non-constant condition
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 24, 2026
@robot-ch-test-poll3
robot-ch-test-poll3 merged commit 993200a into backport/26.6/108128 Jun 24, 2026
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.6/108128 branch June 24, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants