Skip to content

Do not raise a logical error when a Merge table matches a table with no columns - #115896

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/merge-empty-columns-alias-parameterized-view
Aug 24, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/merge-empty-columns-alias-parameterized-view

Conversation

@groeneai

@groeneai groeneai commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #104740
Related: #104790

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):

Reading through a Merge table that matches an Alias table whose target is a parameterized view no longer raises LOGICAL_ERROR: Table has no columns. (which aborts the server in debug and sanitizer builds). Such a table now reports STORAGE_REQUIRES_PARAMETER, the same error the parameterized view itself reports. Any other matched table that cannot supply columns now reports UNSUPPORTED_METHOD instead of an internal error.

Description

ReadFromMerge::createChildrenPlans classifies a matched table whose metadata snapshot has no columns. It recognised a parameterized view and an Alias with a missing target, treating everything else as an internal invariant violation.

An Alias whose target is a live parameterized view falls through both. A parameterized view registers no columns by design (StorageView.cpp), and StorageAlias forwards its target's metadata, so the alias presents that empty list. But StorageAlias does not override isView(), so the first check misses it, and its target exists, so the second misses it too. The result was LOGICAL_ERROR, aborting the server in debug and sanitizer builds. Two CI runs hit it on 2026-08-21 through merge('^'), one of them on master.

Two changes at that one site:

  • the parameterized-view diagnosis looks one hop through an Alias, so the alias reports the same STORAGE_REQUIRES_PARAMETER as the view it points at;
  • the remaining case becomes UNSUPPORTED_METHOD naming the table and the Merge table. That fixes the class, longer Alias chains included: any matched table that cannot supply columns gets a proper error rather than an assertion. It mirrors Report a clean error when a table expression has no columns to read #115716 at the planner's getSmallestColumn site.

The empty column list is not itself a bad state, so there is nothing to fix upstream; the defect was that plan construction treated a user-reachable condition as an internal one. Both existing messages are unchanged. Forwarding isView() from StorageAlias was rejected as far too broad, since that predicate also gates DDL validation, system.tables, replication and materialized-view logic.

No setting or serialization format is involved, and the path always threw, so no previously succeeding query changes.

The extended 04238_storage_alias_missing_target_merge aborts an unpatched server, so it cannot pass vacuously. 50 randomized runs pass, and every failure in an 82-test sweep of this area reproduces identically unpatched.


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

…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
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Aug 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (1 blocker raised, disagreed with evidence)

An independent model reviewed this diff cold against the pre-change revision.

❌ Blocker raised: "the new empty-column diagnosis bypasses the target table's SELECT authorization for Alias children"

Disagreed. Its four code citations are accurate, but the causal attribution is not: the ordering it describes is pre-existing and this diff does not change any authorization outcome.

At the base revision (dc2e0069) the same block sits in the same place (before createPlanForTable, the only path to StorageAlias::read), all three of its arms throw, and it resolves the alias with the same access-free tryGetTargetTable(). StorageAlias has no isView() override, so the pre-change branch 1 is always false for an Alias and branch 2 always evaluated that call — the resolution count is identical per storage kind (Alias 1/1, parameterized view 0/0, everything else 0/0). The diff contains no access-control line at all: grepping it for checkAccess, isGranted, AccessType or getSelectedTables returns nothing. Only the error code and text change (49 → 55, or 49 → 1).

No new disclosure either: neither message names the target. Both name the alias and the Merge table, on which the user must already hold SELECT to reach this code — filterTablesAndCreateChildrenPlans calls getSelectedTables before createChildrenPlans, and that performs the SELECT check the finding itself cites.

The comparison arm was a healthy alias, which has non-empty columns and so never enters this block — it proceeds to StorageAlias::read, a different path untouched here. That is a cross-fixture comparison rather than a before/after control on the same input.

The prescribed remedy would also regress two pinned carriers: an access-checking getTargetTable would turn the existing dangling-Alias case from UNKNOWN_TABLE into ACCESS_DENIED, and both messages are pinned byte-identical by 04236 and 04238.

Net direction is an improvement: before this change a user holding only SELECT on the Merge table could abort a debug or sanitizer server; now they get a catchable error.

💡 Noted, not blocking

  • The caller appends Child table: <name> to exceptions from this loop, so the new message names the table twice. The existing UNKNOWN_TABLE message at the same site has the identical redundancy; left consistent with it.
  • The two-hop fixture creates the outer Alias before its target exists, since the "cannot refer to another Alias" check is point-in-time. If that check were ever tightened, the fixture would fail loudly on the inner CREATE rather than pass vacuously.

Two pr-body nits were fixed here before publication (duplicated Related: lines, description length).

@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [808baad]

Summary: ✅


AI Review

Summary

This PR changes ReadFromMerge::createChildrenPlans so a Merge table matching an Alias to a parameterized view no longer reaches LOGICAL_ERROR, and so other empty-schema children now surface user-facing exceptions instead of internal assertions. I did not find a surviving correctness or compatibility issue in the current diff; the empty-column handling matches the stated contract, and the added stateless coverage exercises the important Merge, merge(), FINAL, and SAMPLE paths.

Missing context / blind spots
  • ⚠️ Most build-and-test checks for commit 808baad4c742d0aa4d669286ece30d08be8aed99 were still pending when I reviewed on 2026-08-23, so I could not use full CI results to validate cross-platform compilation or sanitizer behavior.
Final Verdict

✅ No review findings in the current diff.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.20% 79.20% +0.00%

Changed lines: Changed C/C++ lines covered: 14/19 (73.68%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 808baad4c with master f16824e50 (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
Binary Master PR Δ
programs/clickhouse-stripped 705.68 MiB 702.65 MiB -3.03 MiB (-0.43%)

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 units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger: 3a3aa02

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
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / 04510_not_has_function_explain pre-existing trunk bug in CAST of an Array(Map) constant sent to a remote server, not caused by this PR #115883 (external, open)

Not caused by this PR: the failing test file is not in this PR's diff, the cited frame is
FunctionCast::createArrayWrapper at src/Functions/FunctionsConversion.cpp:896 which runs in
the analyzer before any MergeTree code this PR touches, and the failure has 33 hits across 29
distinct pull requests including 3 hits on master in the last 7 days. #115883 patches exactly
that file.

@PedroTadim PedroTadim self-assigned this Aug 22, 2026
@alexey-milovidov alexey-milovidov self-assigned this Aug 23, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

26.3 and 26.7 do not contain this fix, but the backports of #115716 (#119654, #119657) brought its test 04945_loop_over_table_expression_without_columns there. That test creates an Alias of a live parameterized view, and in the stress run another test's Merge table matches it, so the server aborts with Logical error: 'Table has no columns.' (STID 3593-560a):

Could v26.3-must-backport be added here? Per ci/tools/cherry_pick.py it also reaches 26.7; 26.8 and newer already have the fix. One label is enough: on 26.3 this PR's block also covers the dangling-Alias case of #104790, which 26.3 lacks too.

A local 3-way merge is clean on 26.7. On 26.3 it conflicts, because 26.3 has an older version of this block and no 04238_storage_alias_missing_target_merge. If the robot's 26.3 cherry-pick conflicts, I will resolve it, push the result to my fork and link it on that PR.

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 groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants