Repository navigation
Fix Parquet reads of .null and .size0 subcolumns when the filter runs as PREWHERE - #124685
alexey-milovidov merged 2 commits into
Conversation
…runs as PREWHERE
`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 a subcolumn that the format cannot read on its own is
replaced by its whole column (`n`). After PREWHERE, `updateFormatPrewhereInfo`
set `source_header = format_header` and rebuilt `requested_columns` from it, on
the assumption that a format supporting PREWHERE reads every subcolumn directly.
Parquet reads tuple elements directly but not `.null`, `.size0` or dynamic
subcolumns, so the read step stopped producing `n.null`:
- a later step using it failed with NOT_FOUND_COLUMN_IN_BLOCK
(`SELECT countIf(n.null) FROM file('x.parquet') WHERE number > 5`, on released
26.3, 26.8 and 26.9; the explicit `PREWHERE n > 5` form too);
- an unused input (`indexHint(n.null)`) was left dangling, which the input check
added by ClickHouse#122952 reports as `The header [...] has a column for only 2 of the
DAG's 3 inputs` (STID 2728-4657, found by the AST fuzzer).
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.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a data file's format lacks PREWHERE (an ORC file of an Iceberg table read as Parquet, or a schema-evolved file), the PREWHERE actions run after the reader and dropped the column that a selected subcolumn such as `n.null` is extracted from. Keep every input listed in the format header among their outputs. 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; 2 rounds, 1 finding) plus my own cold review (2 rounds, 3 findings).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261008-141948 |
|
Workflow [PR], commit [45f2d65] Summary: ✅
AI ReviewSummaryThis PR fixes the main Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 45f2d65.
Changed lines: Changed C/C++ lines covered: 29/29 (100.00%) · Uncovered code |
| auto & prewhere_outputs = prewhere_dag.getOutputs(); | ||
| for (const auto * input : prewhere_dag.getInputs()) | ||
| { | ||
| if (read_from_format_info.format_header.has(input->result_name) |
There was a problem hiding this comment.
This still misses the case where the kept format-header column is also the PREWHERE filter column itself. In the ORC-fallback path, a query like SELECT n.null FROM t PREWHERE n still loses n: this patch adds n to prewhere_outputs, but FilterTransform below still runs with remove_prewhere_column = true, so it erases n before ExtractColumnsTransform can derive n.null from it.
The row-level fallback just above already special-cases direct-input filters for the same reason. The PREWHERE fallback needs equivalent handling here (or some other way to keep the preserved format-header input under a non-filter name).
|
@alexey-milovidov The red Should I open a re-land of this PR with only that tag added to the test, or will you re-land it yourself? |
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 125030 124678 Revert "Bump `aws` from 1.11.771 to 1.11.907" Changelog-revert: 125121 124685 Revert "Fix Parquet reads of `.null` and `.size0` subcolumns when the filter runs as PREWHERE" Changelog-deleted-entry: 124678 [Build/Testing/Packaging Improvement] [section] * Update `aws-sdk-cpp` to 1.11.907 and the AWS CRT libraries to the 0.43.8 release set. [#124678](#124678) ([Actuele AI](https://github.com/actueleai)). Changelog-deleted-entry: 124685 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed `Not found column ... (NOT_FOUND_COLUMN_IN_BLOCK)` when a query over Parquet data (`file`, `url`, `s3` and other object storages) selects a subcolumn such as `n.null` or `arr.size0` and its filter runs as PREWHERE, either moved there automatically or written as an explicit `PREWHERE`. [#124685](#124685) ([Groene AI](https://github.com/groeneai)).
…mber-missing-from-child Picks up ClickHouse#125121 (revert of ClickHouse#124685), which fixes the 05339_parquet_prewhere_subcolumn_read_through_column failure on this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lanes The diagnostics rerun on stateless jobs ran without the job's mode flags, so a failure that only happens under `DBReplicated` (or on the s3/azure/encrypted disk) passed every rerun, was labelled `flaky`, and the LLVM coverage lanes then set it to OK (rule from ClickHouse#95763). This hid `05339_parquet_prewhere_subcolumn_read_through_column` from ClickHouse#124685, which failed every first run under `DBReplicated`, and 218 tests in 30 days that failed 0 of 3 reruns in this way. Pass `--replicated-database`, `--s3-storage`, `--azure-blob-storage` and `--encrypted-storage` to the diagnostics rerun, and never downgrade a test that the PR adds or changes.
…rage downgrade A failure that passes the diagnostics reruns was labelled `flaky`, which reads as "not caused by this PR", and on LLVM coverage lanes it was turned into OK. Failures that a PR introduces under load, under one mode, or with one setting are exactly the ones that pass a rerun, so they were mislabelled or hidden (e.g. `05339_parquet_prewhere_subcolumn_read_through_column` from ClickHouse#124685 failed every first run under `DBReplicated` and was recorded as OK). Now every failed test in a PR gets `new_failure` if it is new or changed in the PR or did not fail on `master` in the last 14 days (CIDB), and `known_flaky` otherwise. The `flaky` label is dropped; the rerun outcome stays in the diagnosis text. The coverage downgrade from ClickHouse#95763 is removed.
…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]>
Related: #122952
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Not found column ... (NOT_FOUND_COLUMN_IN_BLOCK)when a query over Parquet data (file,url,s3and other object storages) selects a subcolumn such asn.nullorarr.size0and its filter runs as PREWHERE, either moved there automatically or written as an explicitPREWHERE.Description
On 26.8.18.2 (also 26.3.42.3 and 26.9.9.28),
SELECT countIf(n.null) FROM file('x.parquet') WHERE number > 5fails withNot found column n.null in block(NOT_FOUND_COLUMN_IN_BLOCK), and returns the right count withoptimize_move_to_prewhere = 0. Since #122952 the variant where the subcolumn is not used further, e.g. insideindexHint, becameLogical error: 'The header [...] has a column for only 2 of the DAG's 3 inputs'(STID 2728-4657), found by the AST fuzzer: PR #124285.Root cause: Parquet reads non-tuple-element subcolumns (
.null,.size0, dynamic subcolumns) through their whole column, so the format header hasnwhile the query asks forn.null.updateFormatPrewhereInforeplaced the query-level source header with the format header after PREWHERE, son.nullwas no longer produced.Change: build the post-PREWHERE source header from the query-level requested columns, as
SourceStepWithFilter::updatePrewhereInfodoes for other storages, keeping each column's storage mapping. When an explicitPREWHEREconsumes the column a selected subcolumn is extracted from, that column stays in the format header. The object-storage fallback that re-applies PREWHERE for files whose format lacks it (ORC files of an Iceberg table read as Parquet) keeps that column too.Validation: the new test covers file and s3,
indexHint,.null/.size0, explicitPREWHERE, lazy materialization, a tuple-element control and an ORC file of an Iceberg table read as Parquet. It fails on master and passes 50/50 with randomized settings; the fuzzer's own query no longer fails. Related tests show no new failures.Overlaps the same function: #114667 (DEFAULT columns, does not cover this case).
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124685]
Version info
26.10.1.2055-master(included in26.10and later)