Repository navigation
Report a clean error when a table expression has no columns to read - #115716
Conversation
A query that reads no columns from a table expression made the planner
synthesise a cheapest column to count rows. For a table or table function
that goes through chooseSmallestColumnToReadFromStorage, which falls back
to ExpressionActions::getSmallestColumn when no column sizes are known,
and that function treats an empty column list as a logical error.
A table expression can legitimately resolve to no columns: an Alias table
whose target has been dropped reports column-less metadata by design and
StorageLoop copies that metadata onto itself, and a parameterized view has
no columns at all. So the empty list reached getSmallestColumn and aborted
the server in debug and sanitizer builds:
CREATE TABLE t (c0 Int32) ENGINE = Memory;
CREATE TABLE a ENGINE = Alias(currentDatabase(), t);
DROP TABLE t;
SELECT count() FROM loop(currentDatabase(), 'a');
The subquery branch of the same zero-columns-needed block already guards
its degenerate case with UNSUPPORTED_METHOD "Cannot read from subquery
with empty projection". This adds the missing counterpart for the storage
branch, so getSmallestColumn's assertion becomes unreachable from its only
caller and stays intact as an internal check.
The error is cause-neutral on purpose. A parameterized view has no columns
by design, so reporting a missing table would be a false claim. Three
sources of an empty list were measured to abort and are covered by the
tests: an Alias whose target was dropped, an Alias to a live parameterized
view, and a bare parameterized view.
Authorization is unaffected: checkAccessRights runs earlier in
buildJoinTreeQueryPlan than the branch that synthesises the column, so a
user without a grant still gets ACCESS_DENIED and the new error cannot be
used to observe table state. A test pins both cases.
Found by the BuzzHouse fuzzer in BuzzHouse (amd_msan), STID 3938-27bd.
The guard these tests assert lives in src/Planner/PlannerJoinTree.cpp, so it exists only under the new analyzer. Under enable_analyzer = 0 the query is interpreted by InterpreterSelectQuery, whose own cheapest-column selection in TreeRewriterResult::collectUsedColumns already guards its fallback with `else if (!source_columns.empty())`. An empty column list therefore falls through both branches, the planner frame is never reached, and the pre-existing UNKNOWN_TABLE surfaces instead of UNSUPPORTED_METHOD. Measured on one old-analyzer server and one binary, changing only the tag: both tests fail without it (Code: 60 instead of the expected code, and a missing UNSUPPORTED_METHOD line in the shell test's output) and are skipped with it. Under the default analyzer they still pass, 20/20 at --test-runs 10. CI reaches this configuration on every pull request through the "amd_llvm_coverage, old analyzer, ..." paramsets, which run tests/config/install.sh with --analyzer and symlink users.d/analyzer.xml. That job does not block a merge, which is precisely why an untagged test matters here: it would report green while failing permanently, hiding the signal rather than raising it. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewI ran an independent cold review of this diff plus a second-model review pass, over two rounds, and
Also verified, no findings: the guarded function has one caller today, so the storage branch of the One forward-looking note: #110180 moves this function into |
|
Workflow [PR], commit [bdf3495] Summary: ✅
AI ReviewSummaryThis PR adds a planner-side guard for zero-column table expressions so Final Verdict✅ No remaining findings on the current head. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260820-202200 |
|
cc @KochetovNicolai @novikd, could you review this? A query needing no columns from a table expression makes the planner pick a cheapest column to count rows, but a table function over a column-less table (an |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units8 translation units recompiled, 49 s compile time in total, 8 of them have a recent master baseline. |
The access test only covered an alias whose target had been dropped. On that carrier the target grant is not expressible, so the arms could not show whether loop() still requires SELECT on the target as a direct read does. Add a live-target alias and two arms measured identically on a build with and without the planner guard: SELECT on the alias alone gives ACCESS_DENIED naming the target, and SELECT on both reads rows. Both arms therefore document behaviour the guard does not change, and the dangling-alias arms keep pinning the ordering the guard depends on. The setup uses INSERT ... SELECT FROM numbers() rather than VALUES because a VALUES payload inside a multi-statement --query block reads the data section from stdin, which the test harness keeps open, and the block then blocks until the 600 second test timeout.
…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
26.3, 26.6 and 26.7 never received this fix, and 26.6 hit it in CI today@PedroTadim you merged this three weeks ago.
On those three the The 26.6 sighting, and the only two rows the signature has in 90 days: SELECT check_start_time, check_name, head_ref, substring(commit_sha, 1, 12) AS sha
FROM default.checks
WHERE test_name LIKE 'Logical error: No available columns%'
AND check_start_time > now() - INTERVAL 90 DAYThe cheapest lever is a single label on this PR: One porting note if the label goes on: 26.3's |
The two tests #115716 added build their column-less table expression with `ENGINE = Alias(...)`. On master `allow_experimental_alias_table_engine` is `MAKE_OBSOLETE` and the guard is gone from `StorageAlias.cpp` altogether, so no setting is needed there. On 26.3 the setting is still a live `Bool` defaulting to `false` and `registerStorageAlias` throws at `LoadingStrictnessLevel::CREATE`: Code: 344. DB::Exception: Experimental Alias table engine is not enabled (turn on setting 'allow_experimental_alias_table_engine'). (SUPPORT_IS_DISABLED) So both tests failed on their first `CREATE`, on the initial run and on the retry, in `Stateless tests (amd_asan, distributed plan, parallel, 1/2)` and `(2/2)`. Nothing else in those jobs failed. Enabling the setting is what every other alias test on this branch already does (`03636_storage_alias_basic.sql`, `03636_storage_alias_syntax.sql`, `03802_storage_alias_referential_check.sql`, `04055_storage_alias_bake_currentDatabase.sql`, `03636_storage_alias_access_rights.sh`). The guard fires only on `CREATE`, so the later sessions that grant on, select from and drop the aliases need nothing, and neither test echoes its input, so the reference files are unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…n has no columns to read
Backport #115716 to 26.6: Report a clean error when a table expression has no columns to read
…n has no columns to read
Backport #115716 to 26.7: Report a clean error when a table expression has no columns to read
Backport #115716 to 26.3: Report a clean error when a table expression has no columns to read
… expression has no columns to read
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
LOGICAL_ERROR: No available columnswhen a query reads no columns from a table expression that has no columns at all, for exampleSELECT count() FROM loop(db, tbl)wheretblis anAliastable whose target was dropped, or a parameterized view. Such a query now fails withUNSUPPORTED_METHODinstead of aborting the server in debug and sanitizer builds.Description
Found by the BuzzHouse fuzzer (
BuzzHouse (amd_msan), STID 3938-27bd, CI report). No related open issue.Reproducer, deterministic, no experimental settings:
Root cause. When a query needs no columns from a table expression, the planner synthesises a cheapest column to count rows. For a table or table function it calls
chooseSmallestColumnToReadFromStorage, which, with no column sizes available, falls through toExpressionActions::getSmallestColumn-- and that treats an empty column list as a logical error. AnAliaswhose target is gone reports column-less metadata by design,StorageLoopcopies it onto itself, and the planner hands the empty list down.The sibling branch of the same
if (columns_names.empty())block already guards its degenerate case withUNSUPPORTED_METHOD "Cannot read from subquery with empty projection". This adds the missing counterpart to the storage branch.getSmallestColumn'sLOGICAL_ERRORstays as an internal assertion and becomes unreachable from this caller.The message is cause-neutral because a parameterized view has no columns by design, so naming a missing table would be wrong. Two further carriers that also aborted are covered: a bare parameterized view, and an
Aliasto a live one.Validation. Both directions on builds of the same revision, all four carriers: unpatched aborts with the CI stack, patched returns
UNSUPPORTED_METHOD. The new test aborts an unpatched server, so it cannot pass vacuously. Authorization ordering is unchanged and pinned by a test: without a grant the query still failsACCESS_DENIEDon both builds. Reading the alias directly, enumerating it insystem.tables/system.columns, andDESCRIBEover the table function are unchanged; the existingAliastests pass unmodified. 50 randomized runs, plus a matched before/after run of 399 planner, alias and table-function tests, show no new failure.Workflow [PR]
Sync PR [sync-upstream/pr/115716]
Version info
26.7.7.89,26.6.5.117,26.3.33.67