Fix `LOGICAL_ERROR` "Table has no columns." on `Merge` over a dangling `Alias` by azat · Pull Request #104919 · ClickHouse/ClickHouse · GitHub
Skip to content

Fix LOGICAL_ERROR "Table has no columns." on Merge over a dangling Alias#104919

Closed
azat wants to merge 1 commit into
ClickHouse:masterfrom
azat:alias-metadata-no-fallback
Closed

Fix LOGICAL_ERROR "Table has no columns." on Merge over a dangling Alias#104919
azat wants to merge 1 commit into
ClickHouse:masterfrom
azat:alias-metadata-no-fallback

Conversation

@azat

@azat azat commented May 14, 2026

Copy link
Copy Markdown
Member

Alias table returns empty metadata if the target does not exists, which will lead to LOGICAL_ERROR in the Merge

Simply returning empty metadata does not looks safe, looks like the only place where we need it is system tables.

So introduce separate method for them
(tryGetInMemoryMetadataPtrForSystemTable()) and remove this "return emtpy metadata fallback" in the Alias storage

Closes #104740
Alternative to #104790

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Fix LOGICAL_ERROR "Table has no columns." on Merge over a dangling Alias

…g `Alias`

Alias table returns empty metadata if the target does not exists, which
will lead to LOGICAL_ERROR in the Merge

Simply returning empty metadata does not looks safe, looks like the only
place where we need it is system tables.

So introduce separate method for them
(tryGetInMemoryMetadataPtrForSystemTable()) and remove this "return
emtpy metadata fallback" in the Alias storage

Closes ClickHouse#104740
Alternative to ClickHouse#104790
@clickhouse-gh

clickhouse-gh Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 14, 2026
{
return storage->getInMemoryMetadataPtr(context, false);
}
catch (...)

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.

catch (...) here suppresses metadata errors for every storage, not only dangling Alias with UNKNOWN_TABLE. As a result, system.* can silently skip tables on unrelated exceptions (for example metadata corruption or other logical exceptions), which hides real problems.

Can we narrow this to catch (const Exception & e) and return nullptr only for the expected dangling-alias case (e.code() == ErrorCodes::UNKNOWN_TABLE, optionally also storage->getName() == "Alias"), while rethrowing everything else?

@clickhouse-gh

clickhouse-gh Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 72.50% (29/40) | lost baseline coverage: 2 line(s) · Uncovered code

Full report · Diff report

@azat

azat commented May 14, 2026

Copy link
Copy Markdown
Member Author

Not so easy, this breaks Replicated database - https://pastila.nl/?000a54ed/98f39c506155a9d6cf79db6c053c5ffc#m0agdNOIVWU14pvh/2YslQ==GCM

@azat

azat commented May 18, 2026

Copy link
Copy Markdown
Member Author

@azat azat closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: 'Table has no columns.' (STID: 3593-5990)

1 participant