Skip to content

Reject ALIAS columns that read themselves through a subcolumn - #124850

Open
groeneai wants to merge 10 commits into
ClickHouse:masterfrom
groeneai:reject-cyclic-alias-subcolumn
Open

groeneai wants to merge 10 commits into
ClickHouse:masterfrom
groeneai:reject-cyclic-alias-subcolumn

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #109377
Related: #129640
Related: #110435

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

CREATE, ALTER, full ATTACH and table function structures now reject an ALIAS column that reads its own subcolumn, directly or through other ALIAS columns (for example c String ALIAS c.size), with CYCLIC_ALIASES. Before, such a definition was accepted and failed only when the column was read.

Description

On master, CREATE TABLE t (x UInt8, c0 Nullable(IPv6) ALIAS c0.null) ENGINE = Memory is accepted, and SELECT c0 FROM t fails with CYCLIC_ALIASES (#129640). On 26.10.2.103 the same read runs the server out of memory. Found by BuzzHouse: OOM in dmesg on #109377. Such a definition should fail at CREATE.

Root cause: the definition-time cycle check binds an identifier to a column only by its whole name, so c0.null is not seen as reading c0.

Change: ColumnsDescription::checkAliasColumnsAreNotCyclic builds the graph of ALIAS columns, with an edge when an expression (subqueries included) reads another ALIAS column by name, through a subcolumn (bound the way tryGetSubcolumnInfo binds it) or as a member of a Nested prefix, and rejects a cycle with the existing DFS (factored out of detectRecursiveDefaultCycles, whose DEFAULT rule is unchanged). It runs for column lists and table function structures, full ATTACH / AS / CLONE AS, and the post-ALTER metadata. 05546_alias_column_reads_itself (#129640) now expects CYCLIC_ALIASES at its cyclic ATTACH statements.

SQL UDF bodies are not followed: a cycle hidden in one fails with CYCLIC_ALIASES when the column is read. Metadata already stored with such a column still loads and fails the same way on read; further ALTERs on it are rejected until MODIFY COLUMN ... REMOVE ALIAS.

#127018 makes the existing DEFAULT cycle check follow compound subcolumn references such as c0.null; that check does not run for a full ATTACH, this one does.

Validation: the new test 05339_alias_column_cyclic_subcolumn and the adapted 05546 fail on master; 05339_alias_column_cyclic_subcolumn_udf checks the read of UDF-hidden cycles; randomized runs pass; stateless tests that use ALIAS or SQL UDFs show no new failures.


Workflow [PR]
Sync PR [sync-upstream/pr/124850]

groeneai and others added 2 commits October 9, 2026 03:36
An ALIAS column whose expression reads its own subcolumn, e.g.
`c5 String ALIAS c5.size` (or `` `c5.size` ``), was accepted by CREATE,
ALTER, full ATTACH and table function structures. The definition-time
cycle check (`detectRecursiveDefaultCycles`) binds an identifier to a
column only by its whole name, and the analyzer pass that validates the
defaults resolves `c5.size` over a dummy storage where `c5` is a plain
column.

On read, the analyzer resolves `c5.size` through `tryGetSubcolumnInfo` to
the ALIAS column node being resolved and wraps that node in
`getSubcolumn`, so the node becomes its own descendant. `validateTreeSize`
then walks the cycle forever and its stack grows through implicit
allocations that the memory limit does not refuse: `SELECT c0` from such a
table, or `SELECT c0 FROM format(CSV, 'c0 Int32, c5 String ALIAS c5.size',
'1')`, runs the server out of memory (found by BuzzHouse on PR ClickHouse#109377).
Through a second ALIAS column (`b String ALIAS a, a String ALIAS
toString(b.size)`) the same cycle overflows the stack in
`QueryExpressionsAliasVisitor`.

Add `ColumnsDescription::checkAliasColumnsAreNotCyclic`: the ALIAS columns
of a table, with an edge from ALIAS `X` to ALIAS `Y` when `X` reads `Y` by
name or through a subcolumn bound the way `tryGetSubcolumnInfo` binds it
(the column of that name, else the first `.`-prefix column whose type has
the rest as a subcolumn), must form no cycle. Only ALIAS expressions are
expanded into the query tree, so references to physical, DEFAULT and
MATERIALIZED columns are not edges, and the existing DEFAULT cycle rule is
unchanged. The DFS of `detectRecursiveDefaultCycles` is factored out and
shared.

The check runs where a user-supplied definition is accepted: column lists
and table function structures in `getColumnsDescription` (mode CREATE),
full ATTACH / `AS src` / `CLONE AS src` in the fresh-definition block of
`getTablePropertiesAndNormalizeCreateQuery`, and the whole post-ALTER
metadata in `validateCreateQuery`. Stored metadata is not screened on
replay; a table stored with such a column by an older version keeps
loading, rejects further ALTERs until the alias is removed
(`MODIFY COLUMN ... REMOVE ALIAS`), and still cannot be read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`RequiredSourceColumnsVisitor` masks a lambda parameter only by its exact
name, while the analyzer binds an identifier to a lambda argument by its
full name or by its first part, before table columns. With a dotted
parameter (`` `x.foo` -> `x.foo`.hash ``) the body reference leaked and was
bound to the table column `x`, so a valid definition was rejected as
`x -> x`.

The check now collects names with its own walk: an identifier whose name
or first part is a parameter of an enclosing lambda is not a table read,
subqueries are not descended into. In-expression aliases (`expr AS b`) are
deliberately not masked: under `prefer_column_name_to_alias = 1` the
analyzer reads the table column `b` first, and such a definition overflows
the stack on read (SIGSEGV on master with an ALIAS column `b` reading
`a.size`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-human PR origin: human review feedback on a groeneai PR labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 findings over a full pass and one delta recheck) plus my own review.

# Sev Finding Verdict Evidence / action
1 ❌ A dotted lambda parameter (`x.foo` -> `x.foo`.hash) was bound to the column x, so a valid definition was rejected AGREE, fixed @ 7b7562b Lambda parameters mask a name by its full name or first part, as the analyzer binds them. In-expression aliases do not mask, because prefer_column_name_to_alias = 1 reads the table column first.
2 ❌ A table qualifier hides the cycle (c String ALIAS dummy.c.size, or q.c.size through full ATTACH) DISAGREE A qualified name is bound through the reading query's join tree, which returns a copy of the column node (clone_is_needed in tryResolveIdentifierFromStorage), so no cyclic tree is built. Measured on master: the other columns read, and reading the column itself fails at once with UNSUPPORTED_METHOD.
3 💡 The error says "column DEFAULT expressions" for an ALIAS cycle DISAGREE ALIAS is a default kind (system.columns.default_kind), and master prints the same text for ALIAS c5.
4 💡 ReplicatedMergeTree column ALTERs run the post-ALTER validation only through the max_query_size check noted, not blocking An explicit max_query_size = 0 skips it there, as it skips every other check of that validation.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261009-065200

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE x (c0 Int32, c5 String ALIAS `c5.size`) ENGINE = Memory; SELECT c0 FROM x and SELECT c0 FROM format(CSV, 'c0 Int32, c5 String ALIAS c5.size', '1') are OOM-killed (exit 137) every run on master; b String ALIAS a, a String ALIAS toString(b.size) gives SIGSEGV.
b Root cause explained? The definition-time cycle check matches whole names only, so c5.size is not a read of c5; on read the analyzer binds c5.size to the ALIAS node being resolved and wraps it in getSubcolumn, creating a cyclic query tree that validateTreeSize walks forever.
c Fix matches root cause? Yes. The cyclic definition is rejected where definitions are accepted, with the same DFS as the existing DEFAULT cycle check; no read-side guard, no limit change.
d Test intent preserved / new tests added? New 05339_alias_column_cyclic_subcolumn: every rejected carrier plus non-cyclic controls (incl. a dotted lambda parameter and a full-name-precedence Tuple); no existing test changed.
e Both directions demonstrated? Master: 137 / 137 / ATTACH accepted / SIGSEGV, test FAIL. Fix: CYCLIC_ALIASES at the definition in all four, test OK, 50/50 randomized runs OK.
f Fix is general across code paths? CREATE (tables, views, MV column lists), table function structures, full ATTACH, AS, CLONE AS, every ALTER (incl. ReplicatedMergeTree). Replay of stored metadata is not screened.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked String .size (both spellings), Tuple, Map .keys, Array .size0, Nullable .null, Variant, JSON paths, Array(Tuple), overlapping dotted names, ALIAS-over-ALIAS subcolumn chains that are not cycles; lambda parameters bound by full name or first part like the analyzer (`x.foo` -> `x.foo`.hash is accepted, the same name read outside the lambda is a cycle); an in-expression alias does not hide a cycle (master: SIGSEGV on read with prefer_column_name_to_alias = 1).
h Backward compatible? (maintainer-approved exception only) Only cyclic ALIAS definitions are refused; reading one runs out of memory or crashes (for the in-expression-alias case, under prefer_column_name_to_alias = 1). DEFAULT semantics and stored tables load as before; no setting.
i Invariants and contracts preserved? The DEFAULT check keeps its roots, edges and message; the new check is const and throws before any metadata or data is changed.

Session id: cron:clickhouse-impl-slot-6:20261009-044400

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cfce14f]

Summary: ✅


AI Review

Summary

Reviewed cfce14f554363abbf166ec1b7d364769ca043f51. The PR rejects direct and indirect ALIAS dependency cycles at definition time, including subcolumn and reconstructed Nested reads, while retaining read-time checks for UDF-hidden cycles and legacy metadata. No actionable findings remain after considering the author's scope decisions. Eight focused probes against the head's Fast test binary matched expectations: five cyclic definitions raised CYCLIC_ALIASES, and three noncyclic controls returned the expected values. The previously reported Nested dependency gap is fixed and its thread is resolved.

Missing context / blind spots
  • ⚠️ The full stateless CI jobs were still pending; their completed results would provide broader regression validation beyond the focused probes.
Final Verdict

Status: ✅ Approve. No new inline findings.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 9, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). label Oct 9, 2026
NameSet dependencies;
if (auto it = alias_to_expression.find(vertex); it != alias_to_expression.end())
{
collectAliasDependenciesFromAST(it->second, alias_names, dependencies);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor of the DFS, but this still leaves the existing DEFAULT/MATERIALIZED cycle detector blind to subcolumn self-reads. collectAliasDependenciesFromAST only adds an edge when the identifier text exactly matches a column name, so cases like a DEFAULT a.size, a MATERIALIZED a.null, or b DEFAULT toString(a.size), a DEFAULT b still contribute no dependency back to a.

Nothing else in validateDefaultsWithAnalyzer repairs that: it analyzes against a fake table where a exists as a source column, and elsewhere we already normalize subcolumn reads back to their top-level column for dependency tracking (MaterializedColumnDependencies does this with replaceSubcolumnsToGetSubcolumnFunctionInQuery). Could we make detectRecursiveDefaultCycles use the same subcolumn-aware collection/binding as checkAliasColumnsAreNotCyclic, so the fix applies consistently to all column-expression kinds?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the DEFAULT/MATERIALIZED rule unchanged: such a cycle through subcolumns only makes an INSERT that omits every member fail with UNKNOWN_IDENTIFIER (same on master), and 04040_defaults_dependency_order expects that table (test_circ_tuple) to be created. #127018 extends that check to compound subcolumn references.

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 7b7562b

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (arm_tidy, 2/4) / Build ClickHouse master-side build break, not from this PR (which changes ColumnsDescription.cpp/.h, InterpreterCreateQuery.cpp, DatabasesCommon.cpp and one stateless test): src/Common/Scheduler/Nodes/tests/gtest_throttler_constraint.cpp:25:11: error: use of undeclared identifier 'FifoQueue', the only error in the shard, in a file this PR does not touch. 25 true-master commits and 103 PRs fail this shard since 2026-10-09 00:35Z #124798 (external, open)
Finish Workflow / Post Hooks (new_tests_check.py) Bugfix validation (functional tests, amd64/aarch64) was dropped behind the row above, so the new test was never measured; no independent failure #124798 (external, open)
Mergeable Check, PR praktika rollups of the rows above (Failed: Workflow Post Hook,Build (arm_tidy, 2/4), Dropped: 101) #124798 (external, open)
CH Inc sync - CH Inc sync (private, not actionable by me)

All 163 check runs completed. The other three arm_tidy shards passed. 101 jobs were dropped behind the shard 2/4 failure, so the functional test matrix and Bugfix validation have not run on this head yet.

Session id: cron:our-pr-ci-monitor:20261009-090003

…-subcolumn

# Conflicts:
#	src/Interpreters/InterpreterCreateQuery.cpp
Comment thread src/Storages/ColumnsDescription.cpp Resolved
CREATE and ALTER reject any subquery in a column default (`hasSubqueryInTree`),
but a full-definition `ATTACH`, `AS` and `CLONE AS` skip that validation, so the
ALIAS cycle check is the only screen there. Skipping subqueries let
`a String ALIAS toString((SELECT b.size)), b String ALIAS a` through, and reading
`a` then grows memory until the process is OOM-killed (also with a `FROM` in the
subquery, and for `a ALIAS toString((SELECT a.size))`).

Identifiers inside subqueries now count as reads of the table. This is stricter
than the analyzer only when the subquery reads a column of another table named
like an ALIAS column of this one, a definition CREATE rejects anyway.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Storages/ColumnsDescription.cpp Resolved
A table function structure is parsed without the SQL UDF substitution a
CREATE TABLE or a full-definition ATTACH applies, so an ALIAS that reads
itself inside a UDF body passed the cycle check. With
prefer_column_name_to_alias = 1 the default expression validation accepts
such a structure too, and a UDF whose body is a scalar subquery also hides
the subquery from that validation:

    CREATE FUNCTION h AS () -> (SELECT a.size);
    SET prefer_column_name_to_alias = 1;
    SELECT a FROM format(CSV, 'i Int32, a String ALIAS toString(h())', '1');

grows memory until the process is OOM-killed (master too). A plain
`() -> a.size` ends in TOO_DEEP_RECURSION.

The check now expands SQL UDFs in a copy of each ALIAS expression before
collecting the names it reads. The stored expression is unchanged, so
DESCRIBE still shows the UDF call, and a non-cyclic UDF alias (also one with
a subquery body) reads as before. As for a subquery in a full-definition
ATTACH, a UDF subquery that reads a same-named column of its own FROM now
counts as a read of the table; CREATE TABLE rejects that definition anyway
(a subquery in a default), and skipping such subqueries would let
`(SELECT a.size FROM numbers(1))` through, which is OOM-killed on read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Storages/ColumnsDescription.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing cfce14f55 with master be8872cd1 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

7 object files changed (+22.82 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ColumnsDescription.cpp.o 634.47 KiB 656.98 KiB +22.52 KiB (+3.55%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse-keeper ×1.16 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 8.2 s 18.2 s +10.0 s (+122%)
Compile time of recompiled translation units

1154 translation units recompiled, 8135 s compile time in total, 1154 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.93 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -654.0 s (-7%) in total before that adjustment.

Job report

Expanding SQL UDFs with UserDefinedSQLFunctionVisitor before collecting the
names an ALIAS reads substitutes whole-name parameters only, so a parameter
used with a subcolumn stayed behind as a name of its own:

- with `review_size = (x) -> x.size`, the structure
  `a String ALIAS toString(review_size(b)), b String ALIAS toString(a.size)`
  lost the edge from `a` to `b`, and `SELECT a FROM format(CSV, ...)` is
  OOM-killed (master too);
- with `f = (a) -> a.size`, `s String, a String ALIAS toString(f(s))` was
  rejected with CYCLIC_ALIASES, because `a.size` was bound to the column `a`.

The check now handles a SQL UDF call the way the analyzer resolves it, as a
lambda applied to the call arguments: the arguments are read in the calling
scope, and the body is read with the UDF parameters masked like lambda
parameters. A call of a parameter whose argument is a lambda calls that
lambda (already read where it is passed), not a registered UDF of the same
name; with any other argument the name is looked up as a UDF, as the analyzer
does. A UDF that is already being entered is not entered again. The check no
longer needs a context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

@KochetovNicolai a scope question, since the bot keeps finding UDF corners here. To catch cycles hidden in SQL UDFs of table function structures (OOM-killed on master too), the check follows UDF calls as lambdas. It still over-approximates the analyzer's binding in contrived cases: for example, a lambda argument that the UDF never calls, and that reads the ALIAS column itself, is rejected with CYCLIC_ALIASES. Keep this, or drop UDF bodies from the check (such cycles then behave as on master)?

}
}

for (const auto & child : node->children)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recursive walk flattens every identifier under a scalar subquery into an outer-table read, because it descends into the subquery AST without preserving the subquery's own alias / FROM scope. That makes fresh-definition ATTACH reject safe aliases whenever the inner query reuses the same name, for example:

ATTACH TABLE db.t
(
    a UInt64 ALIAS (SELECT a FROM (SELECT 1 AS a))
) ENGINE = Memory;

At read time the inner a resolves inside the subquery, but collectNamesReadFromTable records it here and checkAliasColumnsAreNotCyclic turns it into a self-edge on a, so the definition now fails with CYCLIC_ALIASES. Could we preserve subquery binding here (or at least stop counting names proven local to the subquery) instead of treating every nested identifier as an outer dependency?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed: the walk cannot see a subquery's FROM columns without the catalog, and skipping subqueries with a FROM would let a full ATTACH accept a String ALIAS toString((SELECT b.size FROM numbers(1))), b String ALIAS a again (master accepts it). The rejected shape cannot be created on master either (CREATE refuses a subquery in an ALIAS with Code 116), so only a hand-written full ATTACH reaches it.

PedroTadim pushed a commit to ylw510/ClickHouse that referenced this pull request Nov 6, 2026
…expression is resolved

An ALIAS column whose expression reads the column itself through a
subcolumn, e.g. `c0 Nullable(IPv6) ALIAS c0.null`, made a SELECT of it run
until the server was killed. On 26.10 such a column is accepted by CREATE
and ALTER; older releases reach it through ATTACH and table function
structures (format, remote). It was found by La Casa Del Dolor on master:
a read through clusterAllReplicas of a refreshable materialized view with
such a column OOM-killed the server.

ALIAS expressions are resolved lazily (ClickHouse#123926): tryGetColumnNode erases
the column from unresolved_alias_columns and calls the resolver, which
sets the node's expression and resolves it against the same table data.
Resolving `c0.null` calls tryGetSubcolumnInfo -> tryGetColumnNode("c0"),
which no longer finds the column unresolved and returns the node that is
being resolved; wrapExpressionNodeInSubcolumn then makes
getSubcolumn(<c0 node>, 'null') part of that node's own expression. The
query tree is cyclic, and validateTreeSize, an iterative DFS that
memoizes a node only after its children, grows its stack without bound.
Analysis is not cancellable, so max_execution_time, max_memory_usage,
max_server_memory_usage and KILL QUERY do not stop it. A direct cycle
(`c0 ALIAS c0`) overflows the stack in a recursive walker instead
(TOO_DEEP_RECURSION).

The resolver now pushes the column name to
AnalysisTableExpressionData::alias_columns_in_resolution before building
the expression and pops it on scope exit, and tryGetColumnNode throws
CYCLIC_ALIASES with the chain when a requested column is in that list.
The resolver captures the original data, which is also the alias
resolution data of every re-entrant lookup, so the check also works when
a copy of the data started the resolution (the JOIN USING projection
alias path); that is why it precedes the unresolved_alias_columns branch.
Every cycle (through subcolumns, other ALIAS columns, functions) comes
back through this lookup, so tables, Merge, remote/cluster*, format,
materialized views and stored definitions are all covered.

The definition-time check for such columns is ClickHouse#124850.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai and others added 3 commits November 10, 2026 14:14
…-subcolumn

# Conflicts:
#	src/Interpreters/InterpreterCreateQuery.cpp
ClickHouse#129640 added the analyzer read-side guard and created its cyclic tables
with a full-definition ATTACH, which did not validate ALIAS columns. This
PR screens a full ATTACH like CREATE, so those ATTACH statements now fail
with CYCLIC_ALIASES and the reads of tables that can no longer be created
are removed; the non-cycle guards (`t_ok`, `t_probe`) still attach and
read the same values. The read-side guard remains for definitions stored
by older versions, which a stateless test cannot create.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#129640 a read that closes an ALIAS cycle fails with CYCLIC_ALIASES
in the analyzer, including a cycle hidden in a SQL UDF of a table function
structure, which used to run the server out of memory. Following UDF
bodies at definition time therefore only moved that error earlier, and it
had to approximate the analyzer's binding of UDF parameters: a parameter
that receives a function composition (`negate | toString`) and shares its
name with a registered UDF was expanded as that UDF, so a valid structure
was rejected (master reads it).

Drop the UDF expansion and keep the subquery descent; `CREATE TABLE` and a
full `ATTACH` expand SQL UDFs before the check anyway. The UDF test now
checks that reading such a column fails with CYCLIC_ALIASES, and that the
composition case reads its value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Answering my own question above: I dropped UDF bodies from the check in 45a7ecf. Since #129640 such a cycle fails with CYCLIC_ALIASES when the column is read instead of running the server out of memory, so following UDFs only moved that error earlier and kept rejecting valid structures. I also merged master to resolve the conflict and adapted the ATTACH statements of #129640's test; the changelog category is now Improvement.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Nov 10, 2026
Comment thread src/Storages/ColumnsDescription.cpp Resolved
An identifier that is neither a column nor a subcolumn can still read
columns: the analyzer rebuilds `n` from every `Array` column `n.<suffix>`
(`IdentifierResolver::tryResolveIdentifierAsNestedPrefix`). The cycle check
ignored that, so `a Array(Tuple(x UInt64)) ALIAS n, n.x Array(UInt64) ALIAS a.x`
was accepted and failed only on read. Add the edges to the `ALIAS` columns
`n.<suffix>` when the name does not bind to a column or subcolumn, which keeps
the analyzer's precedence (an exact column `n` wins).

Compound suffixes (`n.b.c`) are followed as with the default
`analyzer_compatibility_allow_compound_identifiers_in_unflatten_nested = 1`:
a stored definition is read under any session's settings, and such a table
fails every default read with `CYCLIC_ALIASES`. Only a table function
structure of that shape queried with the setting disabled is now rejected
where master reads it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). groeneai-origin-review-human PR origin: human review feedback on a groeneai PR pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant