Repository navigation
Conversation
…ngling `Alias`
When the regexp of a `Merge` table matches an `Alias` storage whose target
table has been dropped, the query aborted with the internal
`LOGICAL_ERROR` "Table has no columns." raised in
`ReadFromMerge::createChildrenPlans`.
Root cause:
* `StorageAlias::getInMemoryMetadataPtr` (`src/Storages/StorageAlias.h`)
returns the alias's own empty metadata when its target is missing
(`tryGetTargetTable` is null). This is necessary for metadata-only
operations such as `system.tables`/`system.columns` queries on a
dangling alias, exercised by the existing
`03636_storage_alias_basic` test.
* `ReadFromMerge::createChildrenPlans` (`src/Storages/StorageMerge.cpp`)
iterates the selected children, calls `getInMemoryMetadataPtr` on
each, and bails out with `LOGICAL_ERROR` "Table has no columns." if
the snapshot has no columns — assuming the only legitimate empty
case is a parameterized view.
In stress tests the path is reached via `ignore_drop_queries_probability`
leaking `alias_with_missing_target` from `03636_storage_alias_basic` into
later tests, where a `Merge(currentDatabase(), 'a')` regexp matches the
dangling alias. In regular workloads the same path is reachable via a
TOCTOU race: the target table is dropped between `getSelectedTables`
(which locks the alias storage, not its target) and the metadata
snapshot read in `createChildrenPlans`.
Fix: detect the `Alias` case in the empty-metadata branch and throw a
user-facing `UNKNOWN_TABLE` exception that names both the dangling alias
and the matching `Merge` table. This mirrors the analyzer-resolution
path, where `StorageMerge::isRemote` already surfaces `UNKNOWN_TABLE`
via `StorageAlias::isRemote` → `getTargetTable`.
A new regression test `04236_merge_with_alias_missing_target_104740`
locks down the user-visible contract: a `SELECT` through a `Merge`
whose regexp matches a dangling alias must throw `UNKNOWN_TABLE`, never
`LOGICAL_ERROR`.
Closes ClickHouse#104740 (STID 3593-560a / 3593-5990).
Pre-PR validation gate (per TASK.md)
Directive: @alexey-milovidov's comment on #100752 (2026-05-13T03:12:00Z). Session: |
|
cc @alexey-milovidov @azat — could you review this? Fixes the chronic STID 3593-560a / 3593-5990 |
|
Workflow [PR], commit [5b5c895] Summary: ✅ AI ReviewSummaryThis PR changes Missing context / blind spots
Final Verdict
|
|
Standing down — @azat's PR #104919 supersedes this one. Quick summary for future readers:
@azat's approach fixes the contract at the source (alias storage refuses to hand out empty metadata) and isolates the "tolerate dangling target" behavior to the four system-table call sites that actually need it. That's cleaner than guarding at one consumer (our approach). Closing this PR in favor of #104919. Thanks for the alternative @azat! Session: cron:clickhouse-ci-task-worker:20260514-091500 |
|
Superseded by #104919 (see above). |
LLVM Coverage Report
Changed lines: 33.33% (3/9) · Uncovered code |
|
Thanks for the review and approval, @azat — and thanks for applying the comment-wording suggestion directly (commit 5b5c895). The new comment is much cleaner. For context to anyone following this thread: I had earlier stood down in favor of #104919, but it looks like this PR's approach was kept after all. CI is currently rebuilding on the updated commit; will monitor for green and ping again if anything else surfaces. |
|
Hi — could this be a backport candidate for Affected code: Why this might apply: Fix for LOGICAL_ERROR that can occur in stress tests and TOCTOU race conditions. StorageAlias was introduced in 25.11, so the fix should be backported to all branches where the feature exists (26.2, 26.3, 26.4). Not needed for 25.8 since StorageAlias doesn't exist there. Other supported branches ( Caveat: I verified that the modified code exists in those branches, but not whether the bug is actually reachable there — a new caller in master may be what makes this newly observable. If older branches can't reach the affected path, please ignore this; otherwise consider |
…no columns
ReadFromMerge::createChildrenPlans classifies a matched table whose metadata
snapshot has no columns. It recognised a parameterized view and an Alias with a
missing target, and treated everything else as an internal invariant violation.
An Alias whose target is a live parameterized view falls through both checks. A
parameterized view registers no columns by design (StorageView.cpp), and
StorageAlias forwards its target's metadata, so the alias presents that empty
column list. But StorageAlias does not override isView(), so it inherits the
IStorage default of false and the parameterized-view check short-circuits; the
target exists, so the missing-target check is false too. The remaining branch
raised LOGICAL_ERROR, which aborts the server in debug and sanitizer builds.
Two CI runs reached it on 2026-08-21 through merge('^'), one on master and one
on a pull request, with identical stacks.
Two changes at that site. The parameterized-view diagnosis now looks one hop
through an Alias, so such a table reports STORAGE_REQUIRES_PARAMETER, the same
error the view itself reports. The remaining case reports UNSUPPORTED_METHOD
naming the table and the Merge table, which is what fixes the class rather than
this one carrier: any matched table that cannot supply columns now produces a
proper error instead of an assertion, longer Alias chains included. This mirrors
the change made at the planner's getSmallestColumn site in ClickHouse#115716.
The empty column list is not itself a bad state, so there is nothing to correct
upstream of this point; the defect was that plan construction treated a
user-reachable condition as an internal one. Both existing messages are left
byte-identical. Making StorageAlias forward isView() was rejected as far too
broad for this, since that predicate also gates DDL validation, system.tables,
replication and materialized-view logic, and the header records a deliberate
split between predicates that resolve the target and predicates that fail
closed.
No setting, serialization format or new feature is involved, and the block
always threw, so no query that previously succeeded changes behaviour.
The regression test covers the observed carrier through both a Merge table and
the merge() table function, with FINAL and SAMPLE, a two-hop Alias chain, the
two already-classified carriers, and two positive arms that must still return
rows. It aborts an unpatched server, so it cannot pass vacuously.
Related: ClickHouse#104740
Related: ClickHouse#104790
A
Mergetable whose regexp matches anAliasstorage whose target tablehas been dropped aborts the query with an internal
LOGICAL_ERROR"Table has no columns.". This shows up in CI as
STID 3593-560a / 3593-5990
and was flagged on #100752
("Enable snappy compression in HTTP interface") and
#102690
("Fix inserting into Time data type during JSON parsing") — both
unrelated to
StorageMerge/StorageAlias.Root cause
StorageAlias::getInMemoryMetadataPtrinsrc/Storages/StorageAlias.hreturns the alias's own (empty) metadata when its target is missing.
This is intentional so that metadata-only operations such as
system.tables/system.columnsqueries on a dangling alias work(exercised by the existing
03636_storage_alias_basictest).ReadFromMerge::createChildrenPlansinsrc/Storages/StorageMerge.cppiterates the selected children, calls
getInMemoryMetadataPtron each,and throws
LOGICAL_ERROR"Table has no columns." when the snapshothas no columns — assuming the only legitimate empty case is a
parameterized view.
In CI the path is reached two ways:
ignore_drop_queries_probabilityleaks thealias_with_missing_targettable from03636_storage_alias_basicinto a later test whose
Merge(currentDatabase(), 'a')regexpmatches it.
StorageMerge::getSelectedTables(which only locks the alias storage,not its target) and the metadata snapshot read in
createChildrenPlans.Fix
Detect the
Aliascase in the empty-metadata branch and throwUNKNOWN_TABLEwith an exception that names both the dangling aliasand the matching
Mergetable. This mirrors whatStorageMerge::isRemotealready surfaces during analyzer resolutionvia
StorageAlias::isRemote→getTargetTable.A new regression test
04236_merge_with_alias_missing_target_104740locks down the user-visible contract: a
SELECTthrough aMergewhose regexp matches a dangling alias must throw
UNKNOWN_TABLE,never
LOGICAL_ERROR.Closes #104740.
CI evidence: 30-day CIDB shows 6 hits across
arm_msan/arm_release/amd_tsanstress runs on master and 4 distinct unrelated PRs.
Changelog category (leave one):
Documentation entry for user-facing changes
Version info
26.5.1.789