Repository navigation
Fix count() and other queries reading no column from a Buffer table over a Distributed table - #129143
Conversation
When the destination of a `Buffer` table is processed past `FetchColumns` (a `Distributed` destination), `StorageBuffer::read` re-analyzes the query against a `StorageValues` that holds the rows still in the buffers. That storage was built from `StorageSnapshot::getAllColumnsDescription`, which lists ALIAS and EPHEMERAL columns and the `_table` virtual column as ordinary physical columns. The inner analysis then saw a different table than the outer one: for a query that reads no column (`count()`) it picked the smallest of a different set of physical columns, an ALIAS or EPHEMERAL column or `_table`, which the buffers pipe does not contain. Debug builds abort with `Column <name> is not found in the data of table`; releases reject the query with `NOT_FOUND_COLUMN_IN_BLOCK` (26.3, 26.9, 26.10). Build the `StorageValues` from the table's own `ColumnsDescription` with the virtual columns passed separately, so both analyses read the same columns. The same is done for the materialized view source in `InsertDependenciesBuilder` and for `INSERT ... RETURNING`. Found by the AST fuzzer (STID 2127-25d8). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261104-010200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261104-000600 |
|
cc @azat @KochetovNicolai, could you review this and add the |
|
Workflow [PR], commit [7180e71] Summary: ✅
AI ReviewSummaryPR #129143 preserves the original column kinds when Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; normal CI completion remains pending. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
2305001
…s Distributed
A `Distributed` destination plans the query it ships: after inlining `ALIAS`
columns, `buildQueryTreeForShard` replaces every constant whose name is longer
than `optimize_const_name_size` (256 by default) with `__getScalar('<hash>')`.
So `SELECT countIf(s = repeat('x', 1000)), count() FROM buf` named the column
`countIf(equals(__table1.s, __getScalar('...')))` on the destination side and
`countIf(equals(__table1.s, _CAST(<value>, 'String')))` on the buffers side, and
the by-name union conversion in `StorageBuffer::read` threw THERE_IS_NO_COLUMN.
The buffers replan, which already mirrors `inlineAliasColumns`, now also mirrors
the scalar rewrite: it is exposed from `buildQueryTreeForShard.cpp` as
`replaceLongConstantsWithScalars` and used by both callers, so the guard and the
threshold stay in one place. The replanned shipped query is analyzed with
`ignoreASTOptimizations`, as `createLocalPlan` analyzes the local shard of the
same query: an initiator names a folded `__getScalar` constant by its value,
a shard by its source expression, and the destination header uses the latter.
The gate, the adopt-only-if-covered fallback and the access exemption are unchanged.
Also merged master to resolve the conflict with ClickHouse#129143 and ClickHouse#125990 in
`StorageBuffer::read` (master's column kinds and `view_source_in_subqueries`
are kept inside the `plan_buffers` lambda).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_FOUND_COLUMN_IN_BLOCKfor a query that reads no column, such asSELECT count(), from aBuffertable whose destination is aDistributedtable, when theBuffertable has anALIASorEPHEMERALcolumn or only columns larger than its_tablevirtual column.Description
On 26.10.2.103 (also 26.9 and 26.3),
SELECT count() FROM bufover aBuffertable with aDistributeddestination and anALIASorEPHEMERALcolumn is rejected withNot found column a in block. There are only columns: s. (NOT_FOUND_COLUMN_IN_BLOCK). On master (since #126476) the same path is aLOGICAL_ERROR(Column a is not found in the data of table ...), found by the AST fuzzer, STID 2127-25d8 (AST fuzzer (amd_debug, targeted, old_compatibility)report 1,AST fuzzer (amd_debug, targeted)report 2). No related open issue found.Root cause: when the destination is processed past
FetchColumns,StorageBuffer::readre-analyzes the query against aStorageValuesholding the buffered rows. That storage was built fromgetAllColumnsDescription(), which turnsALIAS/EPHEMERALcolumns and_tableinto ordinary columns. For a query that reads no column, the inner analysis then picks a different "smallest column" than the outer one, one the buffers never provide.Change: build that
StorageValuesfrom the table's ownColumnsDescription(column kinds preserved, virtual columns passed separately), asInsertDependenciesBuilderandINSERT ... RETURNINGalready do.Validation: the new test fails on master (debug server aborts) and passes with the fix, 50/50 with randomized settings; the 159
Buffertests have identical results with and without the fix.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129143]
Version info
26.11.1.2233-master(included in26.11and later)