Repository navigation
Fix LOGICAL_ERROR in on-fly mutation read when an UPDATE keep-old fallback is read under a non-constant condition - #108128
Conversation
…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]>
Pre-PR validation gate
Found by serverfuzz on master after #107475 merged (first hit on the merge commit). Follow-up to #107475; same on-fly mutation family as #105947. Session id: cron:clickhouse-worker-slot-0:20260622-122600 |
|
cc @Algunenano @CurtizJ - this is the follow-up to #107475: that PR fixed the |
|
Workflow [PR], commit [2f2e802] Summary: ✅
AI ReviewSummaryThis PR fixes on-fly mutation reads after an Final VerdictStatus: ✅ Approve |
…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.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 16/17 (94.12%) | Lost baseline coverage: none · Uncovered code |
|
CI is finished green on 2f2e802: Finish Workflow, Mergeable Check, Style check, all builds, fuzzers, stateless (incl. the previously-canceled amd_tsan flaky check, now green), integration, and stress jobs all pass. No test failures. |
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
…hen an UPDATE keep-old fallback is read under a non-constant condition
Backport #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
…y-mutation-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
Add changelog entries for PRs that landed on the 26.6 release line after the first pass: ClickHouse#82414, ClickHouse#108042 (New Feature), ClickHouse#107428 (Improvement), and ClickHouse#108128, ClickHouse#108288, ClickHouse#100205, ClickHouse#108029 (Bug Fix). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERROR("Unexpected return type from if") when reading a column underapply_mutations_on_fly = 1after anALTER UPDATE col = ... WHERE <cond>with a non-constant or false condition followed byALTER MODIFY COLUMN col <new type>.Description
Follow-up to #107475, which fixed the
materializemanifestation of this on-fly mutation read bug but introduced anif-return-type manifestation. After #107475 merged (2026-06-17), serverfuzz started hittingUnexpected return type from if. Expected UInt64. Got Stringon master (first occurrence on the merge commit itself; report e.g. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108105&sha=06c39fa48d73772406026a2c33f5978583080896&name_0=PR forStress test (amd_msan)).Root cause:
MutationsInterpreterlowersUPDATE col = expr WHERE condto_CAST(if(cond, _CAST(expr, type), col), type), wheretypeis the post-MODIFYtype. Theifnode is declared attypeand its third argument is the bare on-disk pre-MODIFYcolumn (the value kept for unmatched rows).collectColumnsConsumedByChainActionsexcluded that keep-old fallback edge from forced conversion unconditionally. That is correct only whencondis constant-true:FunctionIfthen returns the then-branch and never reads the fallback. For a non-constant or constant-falsecond,FunctionIfdoes read the fallback, but the on-diskcolis left in its pre-MODIFYtype while theifexpects the post-MODIFYtype, so the executor aborts.Minimal repro (crashes on-fly, returns correct results synchronously):
The fix ignores the keep-old fallback edge only when the
ifcondition is a compile-time constant-true; for a non-constant, constant-false or NULL condition the fallback counts as a genuine consume and the column is converted to the post-MODIFYtype. The cross-step ordering and the query PREWHERE skip are unchanged, so the cases that must stay skipped (an unconvertible on-disk value an UPDATE replaces under a constant-true condition) remain skipped. Extends04338_on_fly_mutation_read_overwritten_lc_sourcewith a regression case that aborts before this change and matches a synchronousUPDATE+MODIFYafter it.Version info
26.7.1.2626.6.1.1188