Skip to content

Fix NOT_FOUND_COLUMN_IN_BLOCK for IS NOT NULL on Iceberg/S3 with the Parquet V3 reader - #106443

Merged
alesapin merged 1 commit into
ClickHouse:masterfrom
tiandiwonder:fix-iceberg-v3-prewhere-subcolumn
Jun 19, 2026
Merged

alesapin merged 1 commit into
ClickHouse:masterfrom
tiandiwonder:fix-iceberg-v3-prewhere-subcolumn

Conversation

@tiandiwonder

@tiandiwonder tiandiwonder commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A compound WHERE containing IS NOT NULL over an Iceberg/S3 (object-storage) table throws NOT_FOUND_COLUMN_IN_BLOCK when using the Parquet V3 native reader (the default since 25.8), but only when the nullable column is referenced only in the predicate and not in the SELECT list:

SELECT bar FROM iceberg.tbl WHERE key = 'X' AND foo IS NOT NULL;
-- Code: 10. DB::Exception: Not found column foo.null: in block ... (NOT_FOUND_COLUMN_IN_BLOCK)

Consequences:

  • The query fails outright instead of returning the matching rows.
  • Reproduces on Iceberg/S3/Azure/HDFS tables; works on file() and on the V2 reader.
  • Known workarounds: optimize_move_to_prewhere = 0, input_format_parquet_use_native_reader_v3 = 0, adding the column to SELECT, or rewriting foo IS NOT NULL as foo = foo.

This is a regression between v26.1 and v26.2.

Root cause

optimize_functions_to_subcolumns (analyzer pass FunctionToSubcolumnsPass) rewrites isNotNull(foo) into not(foo.null), reading the .null subcolumn — but only when the storage reports supportsOptimizationToSubcolumns == true. optimizePrewhere then moves the predicate into PREWHERE and builds a FilterStep whose input references foo.null. The Parquet V3 reader's output header exposes the full foo column but not the foo.null subcolumn as a standalone input, so FilterStep construction (ActionsDAG::updateHeader → evaluatePartialResult) throws NOT_FOUND_COLUMN_IN_BLOCK. Parquet V3 PREWHERE support was added in #93542, which is why this regressed once that path could accept the pushed-down predicate.

Commit 0c9926a (fixes for optimize_functions_to_subcolumns, 2024-01) deliberately disabled this optimization for every file-reading storage: StorageFile, StorageURL, StorageS3, StorageAzureBlob, StorageHDFS, S3Queue, and the Cluster variants all override supportsOptimizationToSubcolumns to return false.

The root-cause PR is #59767 (Unite s3/hdfs/azure storage implementations into a single class working with IObjectStorage, commit 3cca8410385, 2024-02): when StorageS3/StorageAzureBlob/StorageHDFS were unified into StorageObjectStorage, that supportsOptimizationToSubcolumns override was not carried over (StorageObjectStorage has never had it), so object-storage tables (S3/Iceberg/Delta/...) inherited the default true and silently re-enabled the optimization the original author had turned off. The defect stayed latent until #93542 added Parquet V3 PREWHERE push-down in v26.2 — only then could the bad FilterStep referencing foo.null be built against the V3 reader, which is the v26.1 → v26.2 regression the bisect points to.

Fix

Restore the missing override on StorageObjectStorage, consistent with StorageFile/StorageURL:

bool supportsOptimizationToSubcolumns() const override { return false; }

IS NOT NULL then stays a function over the full foo column (as it already does for file()), so nothing references a non-existent foo.null input and PREWHERE push-down works.

Regression test tests/queries/0_stateless/04303_object_storage_prewhere_isnotnull_subcolumn.sql reproduces the exact failure over an S3-engine table and pins every trigger (enable_analyzer, optimize_functions_to_subcolumns, query_plan_enable_optimizations, query_plan_optimize_prewhere, input_format_parquet_use_native_reader_v3) so random-settings variants keep covering the bug. Existing parquet-PREWHERE tests (04001, 03914, 03596, 03633, 04024) still pass.

Closes #106147.

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 a NOT_FOUND_COLUMN_IN_BLOCK exception when querying an Iceberg or S3 table with a compound WHERE containing IS NOT NULL on a column that is not in the SELECT list, using the Parquet V3 native reader.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.1041

…s with Parquet V3 reader

A compound `WHERE` containing `IS NOT NULL` over an Iceberg/S3 table, with the
column referenced only in the predicate and not in `SELECT`, threw
`NOT_FOUND_COLUMN_IN_BLOCK` when using the Parquet V3 native reader (default
since 25.8).

`optimize_functions_to_subcolumns` rewrites `isNotNull(foo)` into `not(foo.null)`,
reading the `.null` subcolumn, but only when the storage reports
`supportsOptimizationToSubcolumns == true`. `optimizePrewhere` then moves the
predicate into `PREWHERE` and builds a `FilterStep` whose input references
`foo.null`; the Parquet V3 reader exposes the full `foo` column but not the
`foo.null` subcolumn as a standalone input, so `FilterStep` construction
(`ActionsDAG::updateHeader`) throws.

Commit 0c9926a deliberately disabled this optimization for every file-reading
storage (`StorageFile`, `StorageURL`, `StorageS3`, `StorageAzureBlob`,
`StorageHDFS`, ...). When S3/Azure/HDFS were unified into `StorageObjectStorage`,
the `supportsOptimizationToSubcolumns` override (returning false) was lost, so
object-storage tables re-enabled the optimization and hit the exception. This is
why it regressed between v26.1 and v26.2, after Parquet V3 `PREWHERE` support was
added in ClickHouse#93542.

Restore the missing override on `StorageObjectStorage`, like `StorageFile` and
`StorageURL`, so `IS NOT NULL` stays a function over the full column.

Closes ClickHouse#106147.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a909969]

Summary: ✅


AI Review

Summary

This PR restores StorageObjectStorage to the same subcolumn-optimization contract as StorageFile, StorageURL, cluster file/object-storage wrappers, and StorageObjectStorageQueue: object-storage tables can expose subcolumns for explicit reads, but the analyzer must not rewrite functions such as isNotNull into standalone .null subcolumn reads that Parquet V3 PREWHERE cannot supply. The added S3/Parquet regression test covers the reported object-storage failure path. I found no blocking issues in the scoped change.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 4, 2026
@tiandiwonder tiandiwonder added the can be tested Allows running workflows for external contributors label Jun 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Jun 15, 2026
`StorageObjectStorage::supportsTrivialCountOptimization` lets the planner serve
`SELECT count()` from Iceberg/Delta manifest metadata (a `ReadFromPreparedSource
(Optimized trivial count)` step) instead of scanning data. That override has no
regression coverage on object storage, and it was nearly lost the same way
`supportsOptimizationToSubcolumns` was dropped in the storage unification (ClickHouse#59767,
fixed in ClickHouse#106443).

Add `test_iceberg_trivial_count_optimization` (local + s3 backends): write a
100-row Iceberg table, create an `ENGINE = Iceberg(...)` table, and assert the
`EXPLAIN` contains the trivial-count step and `count()` returns 100. Verified the
assertion is load-bearing: dropping the override makes both cases fail.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 18, 2026
…re intermediate

A PREWHERE whose conjuncts share an intermediate expression threw
NOT_FOUND_COLUMN_IN_BLOCK with the native Parquet V3 reader. For example a
runtime join filter on multiIf(a='foo','bar',NULL) combined with
isNotNull(multiIf(a='foo',b,NULL)): both conjuncts depend on the common
subexpression equals(a,'foo').

tryBuildPrewhereSteps (the MergeTree prewhere splitter, reused by the V3 reader
since ClickHouse#93542) splits an AND into multiple read steps when the conjuncts read
different column sets. When two conjuncts share an intermediate node, that node
is promoted to an output of the earlier step and an input of the later step.

The V3 reader's multistage consumer (Reader::preparePrewhere) addresses every
column flowing between steps by its index in extended_sample_block, which only
contains query outputs plus the leaf prewhere inputs. A promoted intermediate is
neither, so it has no slot and Block::getPositionByName threw. The MergeTree
range reader does not hit this because it carries intermediate columns by name
in a growing block; only the V3 reader's fixed-slot model is affected. The
splitter itself is correct.

Guard the multistage path: after tryBuildPrewhereSteps succeeds, verify every
step's required columns have a slot in extended_sample_block, and fall back to a
single step otherwise. Single-step execution keeps the shared expression as an
internal DAG node that is never looked up by index, which is the same
always-correct path already used for non-conjunction prewhere. Multistage is
preserved for the common case where conjuncts only share leaf columns.

This is a distinct root cause from ClickHouse#106443, which fixes the isNotNull -> .null
subcolumn rewrite on object-storage tables; that path does not reach the
File(Parquet) reproducer here (StorageFile already disables the subcolumn
optimization).

Closes ClickHouse#106147.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alesapin alesapin self-assigned this Jun 19, 2026
@alesapin

Copy link
Copy Markdown
Member
image What is this check?

@alesapin
alesapin added this pull request to the merge queue Jun 19, 2026
Merged via the queue into ClickHouse:master with commit 994f9d3 Jun 19, 2026
326 of 329 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 Jun 19, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Fix NOT_FOUND_COLUMN_IN_BLOCK for IS NOT NULL on Iceberg/S3 with the Parquet V3 reader

ClickGap verified: reproduced it with the script below on 26.5; tested 6 version(s) — 5 affected, 1 clean (see Affects); bisected to a candidate range — a single introducing PR could not be pinned (see Bisect).

Reproduction

-- Object-storage (S3/Iceberg) table; `foo` is nullable and referenced ONLY in WHERE.
CREATE TABLE t_04303 (key String, foo Nullable(Decimal(38, 3)), bar String)
  ENGINE = S3('http://<minio>/root/test.parquet', 'minio', 'minio123', 'Parquet');
INSERT INTO t_04303 SETTINGS s3_truncate_on_insert = 1
  VALUES ('X', 1.5, 'baz'), ('Y', NULL, 'qux'), ('X', NULL, 'skip');
-- Throws: Code: 10. Not found column foo.null: in block ... (NOT_FOUND_COLUMN_IN_BLOCK)
SELECT bar FROM t_04303
WHERE key = 'X' AND foo IS NOT NULL
SETTINGS input_format_parquet_use_native_reader_v3 = 1, optimize_move_to_prewhere = 1,
         optimize_functions_to_subcolumns = 1, enable_analyzer = 1,
         query_plan_enable_optimizations = 1, query_plan_optimize_prewhere = 1;

Bisect

  • Bisected on master in 11 steps (confidence: LOW); a single introducing PR could not be pinned (culprit confirmation was inconclusive).

Affects

  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.5, 26.4, 26.3, 26.2, 26.1
  • Does NOT reproduce on: master
  • Backport needed: 26.5, 26.4, 26.3, 26.2, 26.1

Suggested next step

The bisect boundary above narrows the search in comp-object-storage — treat the candidate range as the starting point; the single introducing PR is unconfirmed.

Component: comp-object-storage
Severity: P2

cc fix PR author: @tiandiwonder


ClickGap · Finding: phase_d_pr106443

Triage metadata

  • Primary component: comp-object-storage
  • Secondary components: comp-testing
  • Component owners (comp-object-storage): @scanhex12 @kssenii

@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.2, 26.3, 26.4, 26.5. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

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

IS NOT NULL on Iceberg with V3 parquet reader throws NOT_FOUND_COLUMN_IN_BLOCK

4 participants