Repository navigation
Keep subcolumns extracted after reading when a condition moves to PREWHERE - #126573
Conversation
…WHERE A subcolumn the format does not read itself (`t.x` requested together with `t`, or `j.a` of a JSON column) is extracted from its column after reading. `updateFormatPrewhereInfo` rebuilt the requested columns and the source header from the format header alone, dropping such subcolumns, so the filter left after PREWHERE failed with `NOT_FOUND_COLUMN_IN_BLOCK`. Keep requesting them while their column is still read. Closes: ClickHouse#126420
|
Workflow [PR], commit [346e13a] Summary: ✅
AI ReviewSummaryThe PR preserves subcolumns extracted after format reading when Final VerdictStatus: ✅ Approve |
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, 11 s compile time in total, 7 of them have a recent master baseline. |
|
The red checks on bd6a97a are unrelated to this change, which only touches
|
|
🕵 Merged |
…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]>
Closes: #126420
Queries on
file,urland object storage that select a subcolumn and filter with another condition failed when that condition moved to PREWHERE:SELECT id, bbox FROM file('t.parquet') WHERE bbox.xmin > 5 AND c = '1'gaveNot found column bbox.xmin: in block ...(the Overture Maps pattern from the issue). All three queries in the issue work withoptimize_move_to_prewhere = 0.Some subcolumns are not read by the format itself but extracted from their column after reading by
ExtractColumnsTransform, which extractsReadFromFormatInfo::requested_columns. That coverst.xrequested together witht(filterTupleColumnsToReadreads onlytand pointst.xat it), and dynamic subcolumns such asj.aof a JSON column.updateFormatPrewhereInforebuiltrequested_columnsandsource_headerfrom the format header after PREWHERE, which has onlyt, so these subcolumns disappeared from the read step's output and the remaining filter could not find them.The fix keeps requesting each such subcolumn while its column is still in the format header after PREWHERE, and adds it to
source_headerright after the format columns, before the hive partition and virtual columns, which the source appends after extraction. All three failing queries from the issue keep their column after PREWHERE (it shows up in the error message's block), so this covers them.05413_file_prewhere_extracted_subcolumnruns the three queries from the issue with PREWHERE on (the default). The expected output is what the current master build returns for them withoptimize_move_to_prewhere = 0.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
NOT_FOUND_COLUMN_IN_BLOCKwhen a query onfile,urlor object storage selects a subcolumn together with its column (or a JSON subcolumn) and another condition is moved to PREWHERE.Workflow [PR]
Sync PR [sync-upstream/pr/126573]
Version info
26.11.1.679-master(included in26.11and later)