Skip to content

Detect cyclic DEFAULT chains through tuple subcolumn references - #110435

Open
edugomz wants to merge 4 commits into
ClickHouse:masterfrom
edugomz:fix-cyclic-default-error-code
Open

edugomz wants to merge 4 commits into
ClickHouse:masterfrom
edugomz:fix-cyclic-default-error-code

Conversation

@edugomz

@edugomz edugomz commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #107987

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

A cyclic DEFAULT column chain that passes through a tuple subcolumn reference (e.g. a DEFAULT b.x, b DEFAULT c.x, c DEFAULT a.x) is now correctly detected and rejected with CYCLIC_ALIASES at CREATE TABLE time, instead of silently passing DDL validation and failing later at INSERT time with a confusing UNKNOWN_IDENTIFIER error.


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

@edugomz
edugomz marked this pull request as ready for review July 15, 2026 10:42
@evillique evillique added the can be tested Allows running workflows for external contributors label Aug 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3becabb]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
05473_default_reads_subcolumn_of_defaulted_column FAIL cidb
04279_array_join_nested_prefix_with_alias_column FAIL cidb
04040_defaults_dependency_order FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL
Code Review DROPPED
Build (amd_asan_ubsan) DROPPED
Build (arm_asan_ubsan) DROPPED
Integration tests (amd_asan_ubsan, db disk, targeted) DROPPED
Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 5, 2026
Comment thread src/Storages/ColumnsDescription.cpp Outdated
{
dependencies.insert(column_name);
}
else if (identifier->compound() && candidate_names.contains(identifier->name_parts.front()))

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.

identifier->compound() only catches the unquoted spelling b.x. ClickHouse also accepts full dotted paths as a single identifier token (existing tests already use forms like `c0.c2.null` and `m_ipv4.key_192.168.1.1`), and those are resolved elsewhere by splitting identifier->name() with Nested::getAllColumnAndSubcolumnPairs.

For a cyclic default written as `b.x` -> `c.x` -> `a.x`, column_name here is "b.x", candidate_names still only contains "b", and this branch is skipped because the identifier is no longer compound(). CREATE TABLE will still accept the cycle and the failure moves back to INSERT time. This needs to map subcolumn dependencies from the full identifier string (for example via Nested::tryGetColumnNameInStorage(column_name, candidate_names)) instead of only name_parts.front().

a Tuple(x Int32, y Int32) DEFAULT (b.x, b.x),
b Tuple(x Int32, y Int32) DEFAULT (c.x, 2),
c Tuple(x Int32, y Int32) DEFAULT (a.x, 2)
) ENGINE = Memory; -- {serverError CYCLIC_ALIASES}

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 regression test only exercises the default enable_analyzer = 1 branch. The new pre-check runs from validateDefaultsWithAnalyzer, but validateColumnsDefaultsAndGetSampleBlockImpl still goes straight to the legacy TreeRewriter / ExpressionAnalyzer path when enable_analyzer = 0, so the same tuple-subcolumn cycle still slips through in the old-analyzer compatibility mode and fails later at INSERT time with UNKNOWN_IDENTIFIER.

Please either run the same cycle detection before both branches or add an explicit SET enable_analyzer = 0 case here. As written, the PR looks fixed in the default profile while remaining broken for a still-supported setting.

@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 80.10% 85.90% +5.80%
Functions 91.80% 92.70% +0.90%
Branches 72.10% 78.00% +5.90%

Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). label Sep 4, 2026
A subcolumn written as one quoted token (`` `b.x` ``) is a non-compound
`ASTIdentifier`, so `collectAliasDependenciesFromAST` missed its dependency
on column `b` and `CREATE TABLE` accepted the cycle again. Map every
identifier to its storage column with `Nested::tryGetColumnNameInStorage`,
which covers both spellings and still prefers a column literally named `b.x`.

ClickHouse#110435 (comment)

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). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

INSERT that leaves a cyclic DEFAULT chain to defaults raises UNKNOWN_IDENTIFIER instead of CYCLIC_ALIASES

3 participants