Repository navigation
Fix Parquet reads of subcolumns like n.null when PREWHERE consumes their column - #128326
Conversation
…RE read header `prepareReadingFromFormat` keeps query-level `requested_columns` / `source_header`, which can hold subcolumns such as `n.null` or `arr.size0`, and a format-level `format_header`, where Parquet reads such a subcolumn through its whole column (`n`). After PREWHERE, `updateFormatPrewhereInfo` set `source_header` to the post-PREWHERE `format_header`, and ClickHouse#126573 then re-requested a subcolumn only when its column was still read. Two shapes stayed broken: - an explicit PREWHERE that consumes the column a selected subcolumn is read through drops the subcolumn: `SELECT countIf(n.null), count() FROM file('x.parquet') PREWHERE n > 5` fails with NOT_FOUND_COLUMN_IN_BLOCK, also on released 26.3, 26.8, 26.9 and 26.10; - when the column survives an optimizer PREWHERE, the read step outputs the whole column `n` that no step requested, and lazy materialization over it trips `chassert(header.columns() == required_inputs.size())` in `splitExpressionStep` with default settings: `SELECT n.null, number FROM file('x.parquet') WHERE number > 5 ORDER BY number LIMIT 3`. Compute the post-PREWHERE source header by applying the PREWHERE actions to the query-level requested block, as `SourceStepWithFilter::updatePrewhereInfo` does, keep each requested column with its storage mapping, and keep a storage column in `format_header` when an explicit PREWHERE consumes the column a selected subcolumn is extracted from. This replaces the ClickHouse#126573 loop, whose cases the new construction covers (05413 passes unchanged). The object-storage fallback that re-applies PREWHERE after the reader, for a data file whose format has no PREWHERE (ORC files of an Iceberg table read as Parquet, schema-evolved files), now keeps the inputs listed in the format header among the PREWHERE outputs, so the column survives the filter there too. This re-lands the source part of ClickHouse#124685 (reverted in ClickHouse#125121 because its test failed under DatabaseReplicated: the replicated DDL worker does not see the `TEMPORARY TABLE` that the Iceberg block passes to `IcebergLocal`). The test now carries `no-replicated-database` with the reason line of `05291_iceberg_optimize_explicit_metadata`. Its explicit-PREWHERE `s3` arm pins `parallel_replicas_for_cluster_engines = 0`, because under parallel replicas `s3` is read through its `-Cluster` storage, which rejects PREWHERE. 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; 1 finding) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261030-235000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261030-231000 |
|
cc @al13n321 @kssenii, could you review this and add the |
|
Workflow [PR], commit [3787f16] Summary: ✅
AI ReviewSummaryThe change preserves requested subcolumns through Missing context / blind spots
Final VerdictStatus: ✅ Approve. The focused regression coverage and documented before/after results support the fix; no code changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 29 s compile time in total, 8 of them have a recent master baseline. |
|
This also fixes a INSERT INTO FUNCTION file('x.parquet') SELECT number, if(number % 3 = 0, NULL, number) AS n FROM numbers(20);
SELECT count() FROM file('x.parquet') AS f INNER JOIN numbers(20) AS t ON f.number = t.number WHERE f.n.null AND f.number > 5;With the CI release binaries: master |
d52267d
…-variant-support Resolve the conflict in `updateFormatPrewhereInfo` by keeping the PR's construction: it retains all `PREWHERE` inputs in `format_header` and builds `source_header` from the requested columns, which covers the case fixed on master in ClickHouse#128326 (`05339_parquet_prewhere_subcolumn_read_through_column`).
Related: #124685
Related: #126573
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_FOUND_COLUMN_IN_BLOCKwhen a query over Parquet data (file,url,s3and other object storages) selects a subcolumn such asn.nullorarr.size0and an explicitPREWHEREconsumes its column, for exampleSELECT countIf(n.null) FROM file('x.parquet') PREWHERE n > 5. The same fix applies to ORC data files in an Iceberg table with the Parquet format.Description
On 26.10.2.103 (also 26.9, 26.8 and 26.3),
SELECT countIf(n.null), count() FROM file('x.parquet') PREWHERE n > 5fails withNot found column __table1.n.null in block.Parquet reads
.null,.size0and dynamic subcolumns through their whole column. After PREWHERE,updateFormatPrewhereInfobuilt the read step's header from the format header, so when PREWHERE consumedn,n.nullwas lost. #126573 re-requests the subcolumn when its column survives PREWHERE, but that leaves the whole columnnin the header. On master, lazy materialization then aborts a debug build with default settings:SELECT n.null, number FROM file('x.parquet') WHERE number > 5 ORDER BY number LIMIT 3->chassert(header.columns() == required_inputs.size())insplitExpressionStep.Change: build the post-PREWHERE header from the query-level requested columns, as
SourceStepWithFilter::updatePrewhereInfodoes, and keep in the format header any column an explicit PREWHERE consumed if a selected subcolumn is extracted from it. This replaces the loop from #126573. The object-storage fallback that applies PREWHERE after the reader (ORC data files of an Iceberg table read as Parquet) keeps that column too.This is the source part of #124685, reverted in #125121 because its test failed under
DatabaseReplicated. The test now hasno-replicated-database.Validation: the new test (file, s3, Iceberg) fails on master and passes 50/50 with randomized settings, 20/20 with parallel replicas. Found by the AST fuzzer (report, STID 2728-4657; that query passes since #126573). Overlaps #126099.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128326]
Version info
26.11.1.1571-master(included in26.11and later)