Repository navigation
Read a subcolumn of an ALIAS parent through a Merge table instead of a default - #114673
alexey-milovidov merged 2 commits into
Conversation
…a default Selecting arr.size0 from a Merge table returned the type default (0) when the underlying table declared arr as an ALIAS column, while the same read from that table returned the correct value. With the parent selected in the same query it could return the value of an unrelated column instead. ColumnsDescription::add intentionally registers no subcolumns for an ALIAS column, because the value has to be extracted after the alias expression is evaluated. As a result arr.size0 does not resolve against the child but does resolve against the Merge table, where arr is an ordinary column. ReadFromMerge::getModifiedQueryInfo read that asymmetry as "the child does not have this column" and took its differing-schemas path twice over: it substituted a constant default, and its with_aliases loop skipped the column, so the child was never asked for the data. When the parent was also selected, the alias expansion placed the alias's dependency column in the child read list and the misaligned read surfaced that value under the subcolumn's name. The analyzer already implements the extract-after-evaluation contract, turning such a name into getSubcolumn over the alias expression. Both guards now recognise a name that splits to a child ALIAS parent whose type has that subcolumn and route it to the existing alias branch with the full identifier, so no new carrier is introduced. That branch's resolution check has to accept two shapes now: an ALIAS column resolves to a ColumnNode carrying its expression, whereas a subcolumn of one resolves to a FunctionNode owning no expression. Array.size0, Tuple.a, String.size and Nullable.null were each affected, under optimize_functions_to_subcolumns 0 and 1, and a row policy on the child was mis-scoped. Map subcolumns raise NO_SUCH_COLUMN_IN_TABLE before and after. The old analyzer raises UNKNOWN_IDENTIFIER and is unchanged, hence the test's no-old-analyzer tag. MATERIALIZED and DEFAULT parents keep registered subcolumns and were already correct, and the default substitution for a child that genuinely lacks a column is preserved; both have test arms. A mistyped child, such as a String ALIAS under an Array(UInt8) Merge column, is left as it is: String has no size0, so nothing is derivable from the child's own type. That conversion case is a separate concern.
Every alias expression in 04738 was a constant, so no arm reached the case where the alias reads a physical column of the child. That is the case where a Merge read surfaced the alias's dependency value under the subcolumn's name, which is what the changelog entry describes, and it is also the only shape that puts the alias's dependencies into the read list the fix corrects: a constant contributes no ActionsDAG input. The new arms use ALIAS range(dep + 2) rather than range(dep) so that the size0 truth (9), dep (7) and first (11) are three distinct values. With range(dep) the truth equals dep, so a read landing on dep returns the correct number and the arm passes on a binary that still has the defect. Verified against a pre-fix binary: the three new arms fail there, and the with-parent arm returns 7, the value of dep, where 9 is correct.
Internal second-model reviewAn independent cold review plus two second-model gate rounds ran against this change before it
Both remaining objections share one core: a name the child can already resolve keeps its existing |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260813-170500 |
|
Workflow [PR], commit [cad3508] Summary: ✅
AI ReviewSummaryThis PR fixes the analyzer path in Final Verdict✅ No findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 40/40 (100.00%) · Uncovered code |
|
cc @Avogar @KochetovNicolai, could you review this? Reading a subcolumn like |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units8 translation units recompiled, 28 s compile time in total, 8 of them have a recent master baseline. |
CI finish ledger - cad3508CI is fully finished on this commit with no failing checks, so there is nothing to own.
Session id: cron:our-pr-ci-monitor:20260813-233000 |
b047697
…r-subcolumn-type-mismatch Three conflicts in src/Storages/StorageMerge.cpp, all with the merged sibling fix ClickHouse#114673 (subcolumn of an ALIAS parent), which landed on master. Both sides kept in every case: - The anonymous namespace gained isSubcolumnOfAliasColumn upstream and DerivableSubcolumn/tryGetDerivableSubcolumn/makeDerivedSubcolumnExpression here; the two are independent helpers. - storage_columns is now hoisted above the replacement loop upstream; the comment continuation here is unrelated to that move. - Both guards sit in the same replacement loop and are disjoint by the parent's default kind: isSubcolumnOfAliasColumn requires ColumnDefaultKind::Alias, while tryGetDerivableSubcolumn looks the parent up with GetColumnsOptions::AllPhysical (Ordinary | Materialized), which excludes aliases. Neither can shadow the other, so upstream's guard runs first and ours handles what falls through. Verified content-preserving: the added/removed line multisets of master..HEAD are identical to those of the pre-merge base..old-head (+133/-11 in StorageMerge.cpp, 0 lines lost, 0 invented), and the delta against master is the same 4 files, +770/-12, with no submodule movement.
ReproducerCREATE TABLE t (n UInt64, arr Array(UInt8) ALIAS [1,2,3,4,5]) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t (n) VALUES (77);
CREATE TABLE m (arr Array(UInt8), n UInt64) ENGINE = Merge(currentDatabase(), '^t$');
SELECT arr.size0 FROM m; -- returns 0; SELECT arr.size0 FROM t returns 5Results:
Backport the fix to CC component owner: @alexey-milovidov @CurtizJ Analysis metadata
Introducing change: not identified
|
|
Confirmed independently, and the request is correct: 26.7, 26.6, 26.5 and 26.3 still carry this. I measured each release build rather than relying on the report above, printing the
25.8 is clean because the defect postdates that branch, not because the fix is there, so it is out of scope. I do not hand-author release-branch PRs. The label that expands to exactly those four branches is
After resolution each branch carries the full fix (all 3 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix reading a subcolumn (
.size0,.null, a tuple element,String.size) through aMergetable when the underlying table declares the parent column asALIAS. Such a read returned the type default, and when the parent was selected in the same query it could return the value of an unrelated column.Description
Selecting
arr.size0from aMergetable returns0when the child declaresarras anALIAScolumn, while the same query against the child returns the correct5:Root cause:
ColumnsDescription::addregisters no subcolumns for anALIAScolumn, because the value has to be extracted after the expression is evaluated. Soarr.size0does not resolve against the child, but does against theMergetable, wherearris ordinary.ReadFromMerge::getModifiedQueryInforeads that as "the child does not have this column": it substitutes a constant default, and itswith_aliasesloop skips the column, so the child is never asked for the data. With the parent also selected, alias expansion put the alias's dependency column in the child read list, and the misaligned read surfaced that value under the subcolumn's name.The analyzer already implements the extract-after-evaluation contract, turning such a name into
getSubcolumnover the alias expression. This teaches both guards to recognise the case and route it to the existing alias branch with the full identifier, adding no new carrier.Also wrong for
Tuple.a,String.sizeandNullable.null(a NULL read back as non-NULL), underoptimize_functions_to_subcolumns0 and 1, and it mis-scoped a row policy.Mapsubcolumns raiseNO_SUCH_COLUMN_IN_TABLEbefore and after. The old analyzer raisesUNKNOWN_IDENTIFIERand is unchanged, hence theno-old-analyzertag.MATERIALIZEDandDEFAULTparents were already correct, and the default substitution for a child genuinely lacking a column is preserved; both have test arms.A mistyped child (
String ALIASunder anArray(UInt8)Merge column) stays as it is, becauseStringhas nosize0. That conversion case is #112975.Version info
26.8.1.1454(included in26.8and later)