Skip to content

Fix Parquet reads of .null and .size0 subcolumns when the filter runs as PREWHERE - #124685

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:parquet-prewhere-subcolumn-header
Oct 10, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:parquet-prewhere-subcolumn-header

Conversation

@groeneai

@groeneai groeneai commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122952

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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, 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.

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 > 5 fails with Not found column n.null in block (NOT_FOUND_COLUMN_IN_BLOCK), and returns the right count with optimize_move_to_prewhere = 0. Since #122952 the variant where the subcolumn is not used further, e.g. inside indexHint, became Logical 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 has n while the query asks for n.null. updateFormatPrewhereInfo replaced the query-level source header with the format header after PREWHERE, so n.null was no longer produced.

Change: build the post-PREWHERE source header from the query-level requested columns, as SourceStepWithFilter::updatePrewhereInfo does for other storages, keeping each column's storage mapping. When an explicit PREWHERE consumes 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, explicit PREWHERE, 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

  • Merged into: 26.10.1.2055-master (included in 26.10 and later)

groeneai and others added 2 commits October 8, 2026 13:31
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 8, 2026
@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 ⚠️ Explicit PREWHERE on an object-storage file whose format lacks PREWHERE (ORC file in a Parquet Iceberg table, schema-evolved file) still dropped the column a selected subcolumn is extracted from AGREE, fixed fallback filter keeps the inputs the format header lists; Iceberg ORC arm fails without it, passes with it
2 ⚠️ Result-only arms do not prove PREWHERE / lazy materialization run; add EXPLAIN checks DISAGREE the WHERE arms fail on master only through PREWHERE (correct with optimize_move_to_prewhere = 0 on 26.3/26.8/26.9); deciding settings pinned; EXPLAIN of the lazy arm shows LazilyReadFromFile with n.null; no EXPLAIN in the test
3 💡 Fallback still removes the filter column when it is the parent of a selected subcolumn (SELECT isNull(b) ... PREWHERE b) noted narrow, fails on master too, not changed here
4 💡 A subcolumn of a Hive partition column with PREWHERE fails at plan time noted fails on master without PREWHERE as well; handled by #124392

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT count(), sum(number) FROM file('x.parquet') WHERE indexHint(n.null) AND number > 5 aborts a master debug build every time with The header [number, greater(__table1.number, 5_UInt8), n] has a column for only 2 of the DAG's 3 inputs; the fuzzer's own query gives the CI message verbatim. Without indexHint (countIf(n.null)) it is NOT_FOUND_COLUMN_IN_BLOCK on master and on 26.3.42.3, 26.8.18.2, 26.9.9.28.
b Root cause explained? Parquet reads .null/.size0 subcolumns through their whole column, so the format header has n while the query asks for n.null. updateFormatPrewhereInfo set the source header to the format header after PREWHERE, so n.null was never produced: a later use fails NOT_FOUND, and an unused input dangles and trips the input check added in #122952.
c Fix matches root cause? Yes. The wrong header is fixed where it is built (query-level requested columns through the PREWHERE actions, the same formula as SourceStepWithFilter::updatePrewhereInfo); the check from #122952 is unchanged.
d Test intent preserved / new tests added? New 05339_parquet_prewhere_subcolumn_read_through_column (file, s3, Iceberg): indexHint forms, .null/.size0, optimizer and explicit PREWHERE, lazy materialization, tuple-element control, and an ORC data file of an Iceberg table read as Parquet (PREWHERE re-applied after the reader). PREWHERE is pinned on via Random settings limits, validated in system.query_log with a negative control.
e Both directions demonstrated? Master build: test FAIL (server abort with the STID message), 6 of 7 local arms fail. Without the object-storage fallback change, only the Iceberg ORC arm fails (NOT_FOUND_COLUMN_IN_BLOCK). Fixed build: test 50/50 with randomized settings, 20/20 with parallel replicas, every arm equals its PREWHERE-off result. Build IDs checked.
f Fix is general across code paths? The function is shared by file, url, s3/azure/hdfs and data lake reads (optimizer and explicit PREWHERE). Generic SourceStepWithFilter sources already use this formula; lazy materialization and plan serialization already handle query-level subcolumns. The object-storage fallback that re-applies PREWHERE for files whose format lacks it (ORC data files of an Iceberg table read as Parquet, schema-evolved Iceberg files) keeps those columns too. No regressions in ~100 related tests (Parquet, PREWHERE, Hive, lazy materialization, delta/iceberg local) nor in all 109 Iceberg stateless tests.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked Nullable .null, Array .size0, LowCardinality(Nullable) .null, tuple elements, virtual (_file) and Hive partition columns next to subcolumns, explicit PREWHERE consuming two parents, n and n.null together, WHERE n IS NULL; Iceberg: ORC-only and mixed ORC + Parquet tables, files written before ADD COLUMN / RENAME COLUMN.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or result change except that the failing queries now succeed.
i Invariants and contracts preserved? After PREWHERE the read step's source_header/requested_columns hold every query-level column it outputs, format_header holds each storage column they are extracted from, and Hive/virtual columns keep their position at the end.

Session id: cron:clickhouse-impl-slot-40:20261008-141948

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [45f2d65]

Summary: ✅


AI Review

Summary

This PR fixes the main source_header / format_header mismatch for Parquet subcolumns such as n.null and arr.size0, and the new regression test covers the file, s3, lazy-materialization, and unsupported-format fallback paths. The remaining problem is that the new object-storage fallback still drops the preserved parent column when the explicit PREWHERE is that direct input column itself, so I cannot approve it yet.

Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/StorageObjectStorageSource.cpp:1780] The object-storage fallback still loses a selected read-through subcolumn when the explicit PREWHERE is the parent column itself. In the unsupported-format path (for example, an ORC file read through IcebergLocal(..., 'Parquet')), SELECT n.null ... PREWHERE n adds n back to the fallback DAG outputs here, but FilterTransform still sees remove_prewhere_column = true and erases n before ExtractColumnsTransform can extract n.null.
  • Suggested fix: mirror the direct-input handling already used by the row-level fallback and force remove_prewhere_column = false when a preserved format-header input is also prewhere_column_name, or preserve that input under a separate output name before filtering.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: keep the preserved parent column alive through the unsupported-format PREWHERE fallback when the filter itself is that direct input column.

LLVM Coverage Report

Measured on commit 45f2d65.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 91.80% -0.30%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 29/29 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 8, 2026
@groeneai
groeneai requested review from al13n321 and kssenii October 8, 2026 17:07
auto & prewhere_outputs = prewhere_dag.getOutputs();
for (const auto * input : prewhere_dag.getInputs())
{
if (read_from_format_info.format_header.has(input->result_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Oct 8, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 10, 2026
Merged via the queue into ClickHouse:master with commit 1b1e13c Oct 10, 2026
152 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov The red Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) came from this PR's test fixture, not from the src/ change. The Iceberg block reads a session TEMPORARY TABLE inside the IcebergLocal arguments, and the replicated DDL worker that executes the CREATE TABLE cannot see it: Code: 60 ... Unknown table expression identifier 'iceberg_path' (master report). This PR's CI hit the same error in the coverage DBReplicated job, but that job reruns failures without --replicated-database and then marked the test OK (report). 05291_iceberg_optimize_explicit_metadata uses the same fixture and is tagged no-replicated-database for this reason (5c0ec01).

Should I open a re-land of this PR with only that tag added to the test, or will you re-land it yourself?

clickhouse-gh Bot pushed a commit that referenced this pull request Oct 11, 2026
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)).
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 11, 2026
…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]>
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 11, 2026
…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.
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 11, 2026
…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.
@groeneai

groeneai commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

I opened the re-land as #128326. It applies the source part of this PR on top of #126573, replaces the loop that #126573 added, and tags the test no-replicated-database.

opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 6, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants