Repository navigation
Conversation
With a pending ALTER TABLE ... UPDATE and apply_mutations_on_fly = 1, a subcolumn stored in the part answered from the part while its parent in the same SELECT answered post-mutation. On 26.8.10.6 and 26.3.33.24, SELECT a.size0 returns the pre-update length while SELECT a returns the updated array. optimize_functions_to_subcolumns defaults to 1, so length(), isNull() and tuple-element access reach this without the user naming a subcolumn, and in PREWHERE it selects the wrong rows. AlterConversions::buildMutationChainForRead collapses a requested subcolumn to its parent, so the UPDATE survives filterMutationCommands and the step really produces the post-mutation parent. getReadTaskColumns registers that step's ActionsDAG outputs into columns_from_previous_steps under their storage names, then filters the remaining read set using the names the query asked for. For a subcolumn read that name is a.size0, absent from a set that only holds storage-column names, so it lands in post_column_names and is read straight off disk, discarding the value the step just computed. Collect once per readers chain the storage names an on-fly mutation step recomputes (a DAG output that is not a pass-through INPUT node), and in executeActionsBeforePrewhere, before fillMissingColumns, drop the slot of any requested subcolumn whose parent is in that set and is advertised in previous_header. The derive path already exists from the metadata-only T -> Nullable(T) work: fillMissingColumns defers a subcolumn whose parent is available, and evaluateMissingDefaults extracts it with tryGetSubcolumnFromBlock, which casts a still-pre-MODIFY parent first. It did nothing before only because the reader had filled the slot with the stale stream. mutation_version is what identifies these steps; perform_alter_conversions is true for a mutation step too unless a pending ALTER MODIFY COLUMN precedes it, and columns_overwritten_by_chain is empty in that same common case. A mutation step is excluded from the seam on purpose. A materialized mutation feeds a chained command the pre-update subcolumn as well, so moving it only on the on-fly side would make an on-fly read disagree with the materialized result, which is the invariant apply_mutations_on_fly exists to preserve. Physical dotted columns of a Nested keep reading from the part, because the metadata isSubcolumn() test decides rather than the dot. Patch parts were measured and are already correct, so they are untouched. One seam covers the post-PREWHERE read and every query PREWHERE / row-level step, as both go through executeActionsBeforePrewhere. Closes: ClickHouse#118718 Co-Authored-By: Claude Opus 5 <[email protected]>
A column that a query PREWHERE step consumes and then projects out is absent from the next reader's previous_header and survives only in ReadResult::additional_columns, which MergeTreeRangeReader::executePrewhereActionsAndFilterColumns snapshots before executing the step's actions. The parent-availability test therefore accepts either source, and a slot nulled on the strength of additional_columns also names its parent in the set handed to fillMissingColumns: that set is the only channel through which isSubcolumnOfAvailableColumn learns the parent exists, so without it the slot would be default-filled with a fabricated value instead of being derived from the parent. Without this, SELECT id, a.size0 FROM t PREWHERE a = [7, 8, 9] with a pending UPDATE still returned the pre-update length, and optimize_move_to_prewhere brings a plain WHERE to the same shape by default. Resolve the requested name with AllPhysical so the null-out set is exactly the set the derive path's own predicate resolves, rather than a strict superset of it. Tests: add a PREWHERE-on-the-parent pair beside the existing PREWHERE-on-the- subcolumn one, so the contrast is visible; move the Nested physical-dotted-column control onto a wide part, where the shared Nested offsets exist as their own stream and the control can actually exercise that path; name the real part format in each matrix section title, since min_bytes_for_wide_part = '10G' selects Compact and both thresholds at 0 select Wide; and pin optimize_functions_to_subcolumns, optimize_move_to_prewhere and query_plan_optimize_prewhere with a per-setting clamp, because the runner randomizes all three and the assertions are a non-signal when they land at 0.
…its parent With skip_empty_columns_on_insert = 1 and serialization_info_version = 'with_missing_columns', a column that is entirely default at INSERT time is omitted from the part and recorded as a missing-column marker. IMergeTreeReader::fillMissingColumns handles those markers before it calls DB::fillMissingColumns, and it filled the frozen type-default into a subcolumn slot whose parent an earlier reader-chain step had already produced. The slot was then no longer null, so should_evaluate_missing_defaults stayed false and evaluateMissingDefaults never derived the subcolumn from that parent. With a pending UPDATE a = [7, 8, 9] on such a part and apply_mutations_on_fly = 1, SELECT a, a.size0 therefore returned [7,8,9] and 0 in the same row, and SELECT length(a) returned 0, while the materialized mutation gives 3. This predates the previous commits on this branch: the base commit returns the same 0. Skip the frozen fill for a subcolumn whose parent is in previous_step_columns. The marker is still recorded in missing_column_names unconditionally, so DB::fillMissingColumns keeps treating the parent as missing rather than as having a DEFAULT expression, and defers the slot to evaluateMissingDefaults through isSubcolumnOfAvailableColumn. The DROP/CLEAR and rename handling above it is unchanged. The blast radius is bounded by construction: IMergeTreeReader::fillMissingColumns receives a non-empty previous_step_columns only from MergeTreeReadersChain::executeActionsBeforePrewhere. The chain's other caller passes the default empty set, and the Memory engine calls DB::fillMissingColumns directly, so every other read is unchanged. Tests: add a section for a part that omits the parent, and one for a PREWHERE on a parent updated in only some rows, so the filter drops a row while the subcolumn's slot is deferred. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…parent lookup apart
The Nested section updated only `v`, so it passed whether the seam in
MergeTreeReadersChain::executeActionsBeforePrewhere resolved a subcolumn's
parent from the metadata or by splitting its name at the first dot: neither
lookup could reach a column that no pending UPDATE recomputes.
It now updates the Nested element itself (UPDATE `n.a` = [7, 8, 9, 10], a
length change from 3 to 4) and reads n.a.size0. The metadata parent of
n.a.size0 is n.a, while a first-dot split gives n, which is not a column and
can never be an UPDATE target, so that implementation would keep answering
from the part's stale shared offsets. The section therefore also covers a
Nested element's own subcolumn as a regression case: the base commit returns
3 there.
Proven with a throwaway mutation arm, never committed, that replaces the
metadata lookup with name.substr(0, name.find('.')) for every dotted name:
exactly this section's pending line goes red (n.a.size0 = 3 instead of 4) and
no other line of the file changes. length(n.a) in the same SELECT reads 4
under the arm too, because it is not rewritten onto n.a.size0 while n.a is
also selected.
A physical column literally named `a.size0` beside an updated `a` does not
discriminate: with on-fly steps present every physical column the query reads
is read and forwarded by the first mutation stage, so only subcolumns reach
the seam, and both lookups return the stored value.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lumn, drop a dead exclusion A mutation step is now recognised by PrewhereExprStep::is_mutation_step, set where AlterConversions::getMutationSteps builds it, instead of by mutation_version: not every command getMutationSteps turns into a step carries a mutation_version, and the columns such a step recomputes were missing from columns_computed_by_mutation_steps. getMaxPatchVersionForStep and every other reader of mutation_version are unchanged. A subcolumn derived from its parent already carries the parent's patches, applied in version order around the mutation step. The step that reads the subcolumn applied every patch again with no minimum version, so a lightweight UPDATE older than a pending ALTER UPDATE won over the mutation: a.size0 = 4 beside a = [7,8,9], where the materialized mutation gives 3 (the base commit returns the same 4). The derived slot is now left out of that step's patch list, so it keeps its parent's result; a newer lightweight UPDATE still wins, through the parent. Covered by a new test section with one older and one newer lightweight UPDATE. The mutation-step exclusion in executeActionsBeforePrewhere never fired: the first on-fly step reads every mutation input together with its parent, later mutation steps read no column, and only the lightweight-delete step, which reads _row_exists, can precede them. Remove it together with its only control, the chained-command test section; the chained shapes answer identically with and without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Delete design rationale, a duplicated member doc and an imprecise INPUT-output comment; condense the remaining blocks to one-line invariants. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own cold read, five rounds, 17 findings; bounded: one full pass, fix rounds and a delta recheck per round.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20260926-022500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260925-233800 |
|
Workflow [PR], commit [8899a4f] Summary: ❌
AI ReviewSummaryThe change derives subcolumns from parents updated by pending mutations, including after Findings
Missing context / blind spots
Tests
Final VerdictStatus: |
…stale-subcolumn # Conflicts: # src/Storages/MergeTree/MergeTreeRangeReader.h # src/Storages/MergeTree/MergeTreeReadersChain.cpp
|
Dear @CurtizJ, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
🕵 A related case for this fix comes from #118630 (comment). A lightweight SET allow_experimental_lightweight_update = 1;
CREATE TABLE t (id UInt32, b Tuple(x UInt32, y UInt32)) ENGINE = MergeTree ORDER BY id
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1, apply_patches_on_merge = 0;
INSERT INTO t VALUES (0, (100, 200)), (1, (101, 201));
SYSTEM STOP MERGES t;
UPDATE t SET b = tuple(900, 901) WHERE id = 0;
ALTER TABLE t UPDATE b = tuple(500, 501) WHERE id = 0 SETTINGS mutations_sync = 0;
SELECT id, b, b.x FROM t ORDER BY id SETTINGS apply_mutations_on_fly = 1;
-- master: 0 (500,501) 900; expected 0 (500,501) 500It would be good to cover it, for both |
…stale-subcolumn # Conflicts: # src/Storages/MergeTree/MergeTreeReadersChain.h
… part versions A lightweight UPDATE patches the tuple `b`, then a pending ALTER UPDATE overwrites it. With `apply_mutations_on_fly = 1`, `b.x` must return the mutation's value, not the patch's. On master it returns the patch's value (900 instead of 500) for `patch_parts_version` v1 and v2. Case from ClickHouse#122372 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Added this case to No code change was needed. On master ( |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1800 translation units recompiled, 5018 s compile time in total, 1800 of them have a recent master baseline. |
CI finish ledger - 8899a4fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261119-143020 |
Closes: #118718
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a bug where a subcolumn read (
a.size0,n.null, aTupleelement,Map.keys/.values, aJSONdotted path) returned the value stored in the part instead of the value produced by a pendingALTER TABLE ... UPDATEwhenapply_mutations_on_fly = 1. Sinceoptimize_functions_to_subcolumnsis enabled by default,SELECT length(a)could disagree withSELECT ain the same query, andPREWHERE length(a) = 3could return the wrong rows.Description
On 26.8, with a pending
ALTER TABLE ... UPDATE a = [7, 8, 9]andapply_mutations_on_fly = 1,SELECT a.size0returns the pre-update length2whileSELECT ain the same query returns the updated[7,8,9]. Measured on26.8.10.6and26.3.33.24.optimize_functions_to_subcolumnsdefaults to1, solength(),isNull()and tuple-element access reach this without naming a subcolumn; inPREWHEREit selects the wrong rows.Root cause: the chain collapses a requested subcolumn to its parent, so the mutation step produces the updated parent.
getReadTaskColumnsthen registers the step's output under the storage name (a) but filters the remaining read set by the name the query asked for (a.size0), so the subcolumn is read from its own stream in the part.Fix: in
MergeTreeReadersChain, collect once the storage names an on-fly mutation step recomputes, and beforefillMissingColumnsdrop the slot of any requested subcolumn whose parent is in that set. The existing derive path (isSubcolumnOfAvailableColumn->tryGetSubcolumnFromBlock) then extracts it from the parent, casting as needed. Two neighbouring stages no longer override the derived value: a missing-column marker's frozen default (skip_empty_columns_on_insert,IMergeTreeReader::fillMissingColumns), and the step's own patch application, which let a lightweightUPDATEolder than the pendingALTER UPDATEwin (the parent already carries its patches).This covers the post-PREWHERE read and every query
PREWHERE/row-level step. The metadata, not the dot, names the parent:n.a.size0follows an update of theNestedelementn.a; a physicaln.akeeps its own data.Validation: the new test asserts pending == materialized per subcolumn kind on wide and compact parts, and fails in 10 places on master. A 609-test sweep (subcolumns, on-fly mutations, lightweight updates, metadata-only
ALTER,skip_empty_columns_on_insert) shows no other status change.The subcolumn's own stream is still read, then discarded; eliding it needs a per-position check in the hottest read loop.
Workflow [PR]
Sync PR [sync-upstream/pr/122372]