Repository navigation
Conversation
A `DEFAULT` or `MATERIALIZED` expression such as `j.a` requires the column `j`; `addDefaultRequiredExpressionsRecursively` looked the name up only as a whole column and silently skipped it, so an `EPHEMERAL` or `ALIAS` parent was never computed and the `INSERT` failed with `UNKNOWN_IDENTIFIER`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… default reads `injectRequiredColumnsRecursively` resolved the subcolumn among physical columns only, so for an `ALIAS` parent the inputs of its expression were not read and the default of the column missing in the part either failed with `UNKNOWN_IDENTIFIER` or, with the parent now computed, used type defaults for the inputs. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ad them When an `INSERT` omits a column without a default, `addMissingDefaults` fills it with the type default inside its own DAG; a default such as `j.a` then needed a subcolumn input no stage of the `INSERT` chain could provide, and the `INSERT` failed with `NOT_FOUND_COLUMN_IN_BLOCK`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`RenameColumnVisitor` renamed an identifier only when its whole name was the column, so a default, `TTL`, skip index or constraint written as `j.a` kept the old name and the `ALTER` failed with `UNKNOWN_IDENTIFIER`; a column whose subcolumn is in a key is now refused like any key column instead of failing in the key re-analysis. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The "default default" of a missing dependency was a literal typed by the `Field` (a `Tuple(a Int64, b Int64)` default became `Tuple(Int8, Int8)`), so a `DEFAULT` expression reading `j.a` on a stored parent without a default could not resolve it while reading. Build `_CAST(<literal>, '<declared type>')` from the start. The test also pins the `MATERIALIZE COLUMN` and `EPHEMERAL`-parent read paths. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The reader and the read-size estimate shared a duplicated loop that follows a subcolumn to the column it belongs to; it is now the `StorageSnapshot` helper `getDefaultOfColumnOrSubcolumn`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
`05430_hyperloglog_corrupted_state` landed on master after this branch was cut. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [8a30072] Summary: ❌
AI ReviewSummaryThe PR fixes dependency collection and evaluation for defaults that read subcolumns of Findings❌ Blockers
Tests
Final Verdict❌ Block. Preserve exact-column precedence in both rename and default lookup, handle the remaining subcolumn representations, and add regression coverage for these cases. |
| identifier.name_parts.front() = rename_to; | ||
| identifier.resetFullName(); |
There was a problem hiding this comment.
[P1] Preserve references to ordinary dotted columns during rename
A dotted identifier is not necessarily a subcolumn of its first component: a real column named j.a takes precedence over the subcolumn of j. This valid example silently changes the materialized expression's input on the PR binary:
CREATE TABLE t
(
j Tuple(a Int64) ALIAS tuple(100),
`j.a` Int64,
x Int64 MATERIALIZED j.a
) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t (`j.a`) VALUES (7);
ALTER TABLE t RENAME COLUMN j TO jj;
INSERT INTO t (`j.a`) VALUES (8);
SELECT x FROM t ORDER BY x;The result is 7, 100, instead of 7, 8: this branch rewrites x to jj.a even though the ordinary j.a column was not renamed. This changes persisted values for subsequent inserts. Please resolve the identifier against the table's column metadata before deciding that it belongs to the renamed column, and add a regression test for this precedence rule.
| for (auto [name_in_storage, subcolumn_name] : Nested::getAllColumnAndSubcolumnPairs(column_name)) | ||
| { | ||
| auto column = tryGetColumn(GetColumnsOptions::All, String(name_in_storage)); | ||
| if (column && column->type->tryGetSubcolumnType(subcolumn_name)) | ||
| return getDefault(column->name); |
There was a problem hiding this comment.
[P1] Preserve an exact column's lack of a default
getDefault(column_name) returning nothing does not mean the exact column is absent. When an ordinary column named j.a exists without a default, this loop incorrectly borrows the default of an ALIAS column j. On the PR binary:
CREATE TABLE t (flag UInt8) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t VALUES (1);
ALTER TABLE t
ADD COLUMN j Tuple(a Int64) ALIAS tuple(`j.a`),
ADD COLUMN `j.a` Int64;
SELECT `j.a` FROM t;The read should return the ordinary column's type default, 0, but raises TOO_DEEP_RECURSION: injectRequiredColumnsRecursively looks up missing j.a, receives tuple(j.a), and recursively requests the same missing column. This also reproduces after CLEAR COLUMN j.a on a populated table. Please resolve the actual column/subcolumn with the normal metadata lookup, preserving exact-column precedence, and return that column's own default (including no default) rather than searching an unrelated parent. Cover the old-part read with a stateless test.
| } | ||
|
|
||
| /// `j.a` is the subcolumn `a` of the column `j`. | ||
| if (identifier.compound() && identifier.name_parts.front() == column_name) |
There was a problem hiding this comment.
[P2] Handle quoted subcolumns and dotted parent column names
Matching only name_parts.front misses two supported representations of the same dependency. In x Int64 MATERIALIZED `j.a` , the quoted identifier has one name part, so renaming j does not enter this branch. For a flattened Nested member, n.j.a belongs to the physical column n.j, but its first name part is n, so renaming n.j also misses the reference.
Both cases still fail with UNKNOWN_IDENTIFIER on the PR binary:
CREATE TABLE t1 (j Tuple(a Int64), x Int64 MATERIALIZED `j.a`)
ENGINE = MergeTree ORDER BY tuple();
ALTER TABLE t1 RENAME COLUMN j TO jj;
CREATE TABLE t2
(n Nested(j Tuple(a Int64, b Int64)), x Array(Int64) MATERIALIZED n.j.a)
ENGINE = MergeTree ORDER BY tuple();
ALTER TABLE t2 RENAME COLUMN `n.j` TO `n.k`;Please identify the owning column from the full resolved name and rewrite its prefix while preserving the subcolumn path. Add both forms to the rename regression coverage.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1048 translation units recompiled, 7011 s compile time in total, 928 of them have a recent master baseline. Translation units without a recent master baseline:
|
…until the stack or memory is exhausted Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ries the table's defaults as ALIAS columns Co-Authored-By: Claude Fable 5.1 <[email protected]>
… default columns Co-Authored-By: Claude Fable 5.1 <[email protected]>
… measure Co-Authored-By: Claude Fable 5.1 <[email protected]>
A
DEFAULTorMATERIALIZEDexpression may read a subcolumn of another column, for examplex Int64 MATERIALIZED j.awithj Tuple(a Int64, b Int64)(supported since #74403). Three places that collect the dependencies of such an expression looked the namej.aup only as a whole column, so the column it belongs to was never pulled in:INSERTinto a table whose parent column isEPHEMERALorALIASfailed withUNKNOWN_IDENTIFIER(Unknown expression or function identifier 'j.a'), whiletupleElement(j, 'a')worked. Fixed inaddDefaultRequiredExpressionsRecursively.ALTER TABLE t ADD COLUMN x Int64 DEFAULT j.a,j ALIAS ...) failed the same way, because the reader did not read the inputs of theALIASexpression. Fixed ininjectRequiredColumnsRecursivelyand its mirror inReadFromMergeTree, which now share aStorageSnapshothelper for the lookup.INSERTomitting a stored parent column without a default (INSERT INTO t (line)withj Tuple(...),x MATERIALIZED j.a) failed withNOT_FOUND_COLUMN_IN_BLOCK: the parent was synthesised inside the defaults DAG, where no stage of theINSERTchain could extract its subcolumn. Fixed inaddMissingDefaults.ALTER TABLE t ADD COLUMN j Tuple(a Int64, b Int64), ADD COLUMN x Int64 DEFAULT j.a), failed on read because the type default synthesised for the missing dependency carried the literal's type (Tuple(Int8, Int8)) instead of the declared one; it is now cast to the declared type.ALTER TABLE ... RENAME COLUMN j TO jjleftj.aunrenamed in defaults,TTL, skip indexes and constraints and failed; renaming a column whose subcolumn is part of a key is now refused withALTER_OF_COLUMN_IS_FORBIDDENlike any other key column.Each change comes with its own stateless test. The behaviour is the same on 26.4, 26.6, 26.8 and master (not a regression).
Closes: #127017
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
DEFAULTandMATERIALIZEDexpressions that read a subcolumn (for examplej.a) of anEPHEMERALorALIAScolumn, or of a column omitted from theINSERT, which failed withUNKNOWN_IDENTIFIERorNOT_FOUND_COLUMN_IN_BLOCK;ALTER TABLE ... RENAME COLUMNnow follows such references.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127018]