Repository navigation
Geoparquet rowgroup pruning - #104435
Geoparquet rowgroup pruning#104435alexey-milovidov merged 12 commits into
Conversation
|
Workflow [PR], commit [a6f4678] Summary: ✅
AI ReviewSummaryThis 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 Findings
Tests
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 498/654 (76.15%) · Uncovered code |
812ce2f to
ef5a127
Compare
0c3afe1 to
6dd343e
Compare
`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]>
…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
left a comment
There was a problem hiding this comment.
Looks good, thank you!
…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]>
`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 can you plz add tests to validate if rowpruning is actually happening? |
There are plenty of tests in that PR already. What is missing? |
|
I still don't understand. Every single test out of 10 in this PR validates pruning logic via |
…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]>
… 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]>
Part of making ClickHouse fastest spatial analytical engine on Earth https://github.com/bacek/chgeos/blob/main/BENCHMARK.md ;)
Changelog category (leave one):
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.bboxcolumn index to skip irrelevant pages within row groups. Alsogeneralizes spatial predicate pushdown through
IFunctionBase::isSpatialPredicate()and adds aGeoFilterthat evaluates spatial predicatesduring Parquet row reading.
Documentation entry for user-facing changes
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 (viacovering.bboxcolumns orgeospatial_statistics.bbox). This introduces a newParquet::GeoFilterextractor/bbox utilities, injects covering bbox columns for stats-only evaluation, wires spatialKeyConditions into row-group/page pruning, and tracks pruned pages via newProfileEvents::ParquetPrunedPages.Generalizes spatial predicate identification by adding
IFunction*::isSpatialPredicate()(propagated through adaptors), marking built-in spatial predicates and enabling WebAssembly UDFs to opt in viais_spatial_predicatesetting; also improves GeoParquet metadata parsing to capturecovering.bboxcolumn paths and exposes this flag inFunctionNodedumps.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.