Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK for IS NOT NULL on Iceberg/S3 with the Parquet V3 reader - #106443
Conversation
…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]>
|
Workflow [PR], commit [a909969] Summary: ✅
AI ReviewSummaryThis PR restores Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage: none · Uncovered code |
`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]>
…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]>
994f9d3
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix 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 ReproductionBisect
Affects
Suggested next stepThe bisect boundary above narrows the search in Component: cc fix PR author: @tiandiwonder ClickGap · Finding: Triage metadata
|
|
Hi — this looks like a backport candidate for |

Problem
A compound
WHEREcontainingIS NOT NULLover an Iceberg/S3 (object-storage) table throwsNOT_FOUND_COLUMN_IN_BLOCKwhen 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 theSELECTlist:Consequences:
file()and on the V2 reader.optimize_move_to_prewhere = 0,input_format_parquet_use_native_reader_v3 = 0, adding the column toSELECT, or rewritingfoo IS NOT NULLasfoo = foo.This is a regression between v26.1 and v26.2.
Root cause
optimize_functions_to_subcolumns(analyzer passFunctionToSubcolumnsPass) rewritesisNotNull(foo)intonot(foo.null), reading the.nullsubcolumn — but only when the storage reportssupportsOptimizationToSubcolumns == true.optimizePrewherethen moves the predicate intoPREWHEREand builds aFilterStepwhose input referencesfoo.null. The Parquet V3 reader's output header exposes the fullfoocolumn but not thefoo.nullsubcolumn as a standalone input, soFilterStepconstruction (ActionsDAG::updateHeader→evaluatePartialResult) throwsNOT_FOUND_COLUMN_IN_BLOCK. Parquet V3PREWHEREsupport 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 overridesupportsOptimizationToSubcolumnsto returnfalse.The root-cause PR is #59767 (
Unite s3/hdfs/azure storage implementations into a single class working with IObjectStorage, commit3cca8410385, 2024-02): whenStorageS3/StorageAzureBlob/StorageHDFSwere unified intoStorageObjectStorage, thatsupportsOptimizationToSubcolumnsoverride was not carried over (StorageObjectStoragehas never had it), so object-storage tables (S3/Iceberg/Delta/...) inherited the defaulttrueand silently re-enabled the optimization the original author had turned off. The defect stayed latent until #93542 added Parquet V3PREWHEREpush-down in v26.2 — only then could the badFilterStepreferencingfoo.nullbe 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 withStorageFile/StorageURL:IS NOT NULLthen stays a function over the fullfoocolumn (as it already does forfile()), so nothing references a non-existentfoo.nullinput andPREWHEREpush-down works.Regression test
tests/queries/0_stateless/04303_object_storage_prewhere_isnotnull_subcolumn.sqlreproduces the exact failure over anS3-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):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
NOT_FOUND_COLUMN_IN_BLOCKexception when querying an Iceberg or S3 table with a compoundWHEREcontainingIS NOT NULLon a column that is not in theSELECTlist, using the Parquet V3 native reader.Documentation entry for user-facing changes
Version info
26.6.1.1041