Skip to content

Geoparquet rowgroup pruning - #104435

Merged
alexey-milovidov merged 12 commits into
ClickHouse:masterfrom
bacek:bacek/geoparquet-rowgroup-pruning
Aug 4, 2026
Merged

alexey-milovidov merged 12 commits into
ClickHouse:masterfrom
bacek:bacek/geoparquet-rowgroup-pruning

Conversation

@bacek

@bacek bacek commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Part of making ClickHouse fastest spatial analytical engine on Earth https://github.com/bacek/chgeos/blob/main/BENCHMARK.md ;)

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Adds GeoParquet spatial pruning at row group and page levels to the Parquet reader. Row group pruning skips entire row groups whose bounding box
doesn't overlap the query geometry. Page-level pruning uses the covering.bbox column index to skip irrelevant pages within row groups. Also
generalizes spatial predicate pushdown through IFunctionBase::isSpatialPredicate() and adds a GeoFilter that evaluates spatial predicates
during Parquet row reading.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Changes Parquet read-time pruning logic by adding spatial predicate extraction and bbox-based skipping at row-group and page granularity, which can impact query correctness if predicate/bbox handling is wrong. Also adjusts Iceberg manifest min/max serialization/pruning behavior and adds new settings/events that need validation across varied Parquet/GeoParquet metadata.

Overview
Adds GeoParquet spatial filter pushdown to the Parquet reader, gated by new input_format_parquet_spatial_filter_push_down, to skip row groups (and optionally pages) when WHERE contains conjunctive-only spatial predicates whose constant-geometry bbox is disjoint from bbox statistics (via covering.bbox columns or geospatial_statistics.bbox). This introduces a new Parquet::GeoFilter extractor/bbox utilities, injects covering bbox columns for stats-only evaluation, wires spatial KeyConditions into row-group/page pruning, and tracks pruned pages via new ProfileEvents::ParquetPrunedPages.

Generalizes spatial predicate identification by adding IFunction*::isSpatialPredicate() (propagated through adaptors), marking built-in spatial predicates and enabling WebAssembly UDFs to opt in via is_spatial_predicate setting; also improves GeoParquet metadata parsing to capture covering.bbox column paths and exposes this flag in FunctionNode dumps.

Extends Iceberg min/max handling to support Float32/Float64 stats correctly and to filter out only non-serializable columns instead of disabling bounds entirely, and adds Iceberg manifest pruning based on bbox column bounds for spatial predicates. New integration/stateless tests cover spatial row-group/page pruning, OR-safety, and Float32 stats round-tripping.

Reviewed by Cursor Bugbot for commit 135fb22. Bugbot is set up for automated code reviews on this repo. Configure here.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a6f4678]

Summary: ✅


AI Review

Summary

This PR adds GeoParquet row-group and page-level pruning to the Parquet reader, plus the supporting spatial-predicate plumbing. The main safety issues from earlier revisions look addressed, but one row-group error path still breaks the "performance-only" contract for user-visible covering.bbox columns.

Findings

⚠️ Majors

  • [src/Processors/Formats/Impl/Parquet/Reader.cpp:350] getHyperrectangleForRowGroup now suppresses malformed-stats exceptions for every covering.bbox primitive whenever a spatial predicate is active. Because pc.is_spatial_bbox_column is also set on user-visible bbox columns, a query like WHERE pointInPolygon(geometry, poly) AND bbox_xmin > 0 stops surfacing corrupted bbox_xmin stats and silently disables the ordinary min/max filter instead. Gate this fail-closed path to pruning-only injected helper columns, or mirror the page-level only_spatial_conditions check before swallowing the exception.
Tests

⚠️ Add a focused stateless repro that combines a spatial predicate with a direct predicate on a malformed covering.bbox column, reusing the 04515 fixture. The expected behavior should stay the generic one for the user-visible bbox predicate: throw, or require input_format_parquet_filter_push_down=0 to ignore the bad stats.

Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.40% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.60% -0.10%

Changed lines: Changed C/C++ lines covered: 498/654 (76.15%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label May 8, 2026
@bacek
bacek force-pushed the bacek/geoparquet-rowgroup-pruning branch from 812ce2f to ef5a127 Compare May 10, 2026 07:45
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@bacek
bacek force-pushed the bacek/geoparquet-rowgroup-pruning branch from 0c3afe1 to 6dd343e Compare May 13, 2026 06:03
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
bacek added a commit to bacek/ClickHouse that referenced this pull request May 13, 2026
`extractSpatialFilters` and `extractSpatialPredicatesFromDag` previously
walked all DAG nodes and collected spatial predicates regardless of their
position in the boolean expression. Downstream pruning then treated them
as conjunctions, which is incorrect when a spatial predicate appears under
`OR` with a non-spatial branch.

Example of wrong-result case that is now fixed:
  WHERE user_id = 42 OR pointInPolygon(geometry, poly)
If bbox stats make the spatial branch impossible, the old code would prune
the row group / manifest file even though `user_id = 42` could match rows.

Fix: replace flat `getNodes()` iteration with a DAG walk from `getOutputs()`
that only recurses into `and` function children. Spatial predicates reachable
via `or` (or any non-`and` node) are skipped, ensuring pruning is only applied
when the spatial predicate is provably in a conjunctive-only context.

Refs: ClickHouse#104435

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Comment thread src/Common/ProfileEvents.cpp Resolved
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
…wgroup-pruning

# Conflicts:
#	src/Processors/Formats/Impl/Parquet/Reader.cpp
#	src/Processors/Formats/Impl/Parquet/Reader.h
#	src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
#	tests/queries/0_stateless/00900_long_parquet_load_2.sh
…ning

Page-level GeoParquet spatial pruning only checked the `null_count` of the bbox
column currently being scanned, while the row-group path already required all
four `covering.bbox` columns of a spatial predicate to report a known
`null_count` of zero. Page boundaries are per column, so a sibling bbox column
can hold NULLs on the very rows a null-free page of another bbox column covers,
and that page could then be pruned even though a NULL bbox means the row's
spatial extent is unknown and must be kept.

Each single-column condition wired into `PrimitiveColumnInfo` now remembers the
spatial predicate it was extracted from, and `applyColumnIndex` lets such a
condition prune only when `spatialBboxStatsHaveNoNulls` holds for that
predicate's four bbox columns in the row group, in addition to this page's own
null counts. The row-group path uses the same helper.

Because the guard is now per condition rather than per column, the range for a
bbox column is again computed from its page statistics, so an ordinary
(non-spatial) `WHERE` condition on a column that also backs a `covering.bbox`
keeps its full pruning precision.

Malformed page statistics for a bbox column that only carries spatial
conditions now disable page pruning for that column instead of failing the
read, matching the existing fail-closed behaviour of
`getHyperrectangleForRowGroup`: those columns are injected for this
optimization alone and are neither query outputs nor query filters.

Test `04691_parquet_geo_page_pruning_null_bbox` covers the case: rows 13-18 of
the fixture are south Texas points whose `bbox_xmin` is NULL while the three
sibling bbox columns describe a point in the Atlantic, and `bbox_ymax` has no
NULLs at all, so its third page would otherwise rule those rows out for a south
Texas filter.
`input_format_parquet_spatial_filter_push_down` was recorded under `26.7`,
which has since been released, so `compatibility` set to `26.7` would not turn
the new default off. Move it to the current `26.8` block and mention page-level
pruning in the setting description.
Master added a `MultiPoint` alternative to the WKB geometry variant, which the
`std::visit` in `extractBboxFromFieldValue` did not cover, so the catch-all
`static_assert` fired and `GeoBbox.h` no longer compiled after merging master.
A `MultiPoint` is a container of points, so its bounding box comes from the
same `addAll` the other cases use.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thank you!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 4, 2026
@alexey-milovidov alexey-milovidov removed the submodule changed At least one submodule changed in this PR. label Aug 4, 2026
…box column

The row-group stats error path in `getHyperrectangleForRowGroup` swallowed
decode exceptions for every `covering.bbox` primitive. But such a column can
also be referenced by the query's own `KeyCondition` (e.g.
`WHERE pointInPolygon(geometry, poly) AND bbox_xmin > 0`), where the generic
min/max path would have decoded the same statistics and thrown, with
`input_format_parquet_filter_push_down=0` as the escape hatch.

Track `used_by_user_key_condition` separately from the spatial marking and
swallow the exception only when the stats were read for spatial pruning alone
(mirroring the page-level `only_spatial_conditions` check). With
`input_format_parquet_filter_push_down=0` (`only_spatial_bbox`), all bbox
stats reads are spatial-only and keep failing closed.

Adds `04759_parquet_geo_pruning_malformed_bbox_user_filter` reusing the
04515 fixture: the combined spatial + direct `bbox_xmin` predicate now
throws on the malformed stats, and succeeds with
`input_format_parquet_filter_push_down=0`.

Co-Authored-By: Claude Fable 5 <[email protected]>
Merged via the queue into ClickHouse:master with commit 30936c7 Aug 4, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 4, 2026
bacek added a commit to bacek/ClickHouse that referenced this pull request Aug 7, 2026
`extractSpatialFilters` and `extractSpatialPredicatesFromDag` previously
walked all DAG nodes and collected spatial predicates regardless of their
position in the boolean expression. Downstream pruning then treated them
as conjunctions, which is incorrect when a spatial predicate appears under
`OR` with a non-spatial branch.

Example of wrong-result case that is now fixed:
  WHERE user_id = 42 OR pointInPolygon(geometry, poly)
If bbox stats make the spatial branch impossible, the old code would prune
the row group / manifest file even though `user_id = 42` could match rows.

Fix: replace flat `getNodes()` iteration with a DAG walk from `getOutputs()`
that only recurses into `and` function children. Spatial predicates reachable
via `or` (or any non-`and` node) are skipped, ensuring pruning is only applied
when the spatial predicate is provably in a conjunctive-only context.

Refs: ClickHouse#104435

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@bacek
bacek deleted the bacek/geoparquet-rowgroup-pruning branch August 9, 2026 08:53
@zlareb1

zlareb1 commented Aug 10, 2026

Copy link
Copy Markdown
Member

@bacek can you plz add tests to validate if rowpruning is actually happening?

@bacek

bacek commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@bacek can you plz add tests to validate if rowpruning is actually happening?

There are plenty of tests in that PR already. What is missing?

@zlareb1

zlareb1 commented Aug 13, 2026

Copy link
Copy Markdown
Member

@bacek can you plz add tests to validate if rowpruning is actually happening?

There are plenty of tests in that PR already. What is missing?
maybe add EXPLAIN, check logs etc.?

@bacek

bacek commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@bacek can you plz add tests to validate if rowpruning is actually happening?

There are plenty of tests in that PR already. What is missing?
maybe add EXPLAIN, check logs etc.?

I still don't understand. Every single test out of 10 in this PR validates pruning logic via ParquetPrunedRowGroups statistics.

Algunenano pushed a commit to Algunenano/ClickHouse that referenced this pull request Oct 9, 2026
…t the data file

A Hive partition column and a requested virtual column are added by the source
after the format produced the chunk, but the read steps of `file`, `url` and
object storage passed the whole pushed-down filter to the format. Since ClickHouse#104435
`FormatFilterInfo::initKeyConditionOnce` adds every filter input missing from
the format header to the KeyCondition, so the Parquet reader resolved such a
column to the data file's own column of the same name and pruned row groups,
pages and dictionaries by the file's values. When the file stores other values
than the path (or a physical `_file` column), `WHERE key = 9` on `key=9/` and a
row policy on the partition column returned no rows, while `SELECT key` showed
9 for every row. Regression since 26.8.

`ReadFromFormatInfo::getFormatFilter` now gives the format the filter without
the conjuncts that reference a Hive partition column or a requested virtual
column (`splitFilterDagForAllowedInputs` with a partial result, so `key = 9 AND
v < 10` still prunes on `v`). The files iterator keeps the full filter, and the
`Filter` step above still applies all of it. It replaces the
`formatReadsHivePartitionColumns() ? nullptr : filter_actions_dag` rule of
ClickHouse#123381, which covered only the structure with partition columns alone. Data
lakes keep their virtual-column conjuncts, because Iceberg reads its row
lineage columns from the data file; they have no Hive partition columns, so
their filter is unchanged.

Closes ClickHouse#123717

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Nov 16, 2026
… reads

An explicit PREWHERE leaves its PREWHERE-only columns out of the format
header, so `FormatFilterInfo::buildKeyConditionInputs` adds them to
`additional_columns`, the extra columns the reader produces. Since ClickHouse#104435
(GeoParquet pruning) its `add_required` lambda skipped a name when
`isColumnCovered` found any dot-prefix of it in the header. For
`SELECT v ... PREWHERE `v.tag` = 1`, `v` is in the header, so `v.tag` was
taken for a subcolumn of `v`, never requested, and the Parquet reader threw
NOT_FOUND_COLUMN_IN_BLOCK when it evaluated PREWHERE. 26.7 checked the exact
name there and returned the rows.

PREWHERE and pushed-down row policy inputs are storage columns for every
storage that builds a `FormatFilterInfo` with them: File, URL and
ObjectStorage return top-level names from `supportedPrewhereColumns()` and
do not admit subcolumns (`supportedPrewhereColumnsIncludeSubcolumns()` is
false), so explicit PREWHERE, the move to PREWHERE and the row policy
pushdown never pass a subcolumn. Match them by exact name again. Keep
`isColumnCovered` for the `filter_actions_dag` (WHERE) loop in
`initKeyConditionOnce`: WHERE can name a real subcolumn (`t.a` with `t` in
the header), and requesting both from the Parquet reader is rejected as
COLUMN_QUERIED_MORE_THAN_ONCE.

This also covers stored columns whose names are valid subcolumn names of
the prefix column (`n.null` next to a Nullable `n`, `j.x` next to a JSON
`j`), which a type-aware prefix check would still misread.

Related: ClickHouse#124392 (comment)

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-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-performance Pull request with some performance improvements 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.

6 participants