feat: preserve bitmap-backed RowSelection through ParquetAccessPlan - #24186
feat: preserve bitmap-backed RowSelection through ParquetAccessPlan#24186haohuaijin wants to merge 4 commits into
Conversation
Parquet 59 added a bitmap (BooleanBuffer) backing for RowSelection in addition to the RLE selector form. Previously ParquetAccessPlan always materialized selectors, so a caller-provided bitmap selection was converted to RLE before reaching the parquet reader, which is wasteful for fragmented selections. This change keeps bitmap-backed selections bitmap-backed end to end: * `try_new_from_overall_row_selection` splits a mask-backed selection per row group with `split_off`, which slices the BooleanBuffer instead of materializing selectors. * `into_overall_row_selection` builds a bitmap-backed overall selection when any row group selection is bitmap-backed, promoting selector-backed groups (e.g. ones page index pruning intersected). * `scan_selection` promotes the incoming selection to a bitmap when intersecting with an existing bitmap-backed selection, so the intersection is a bitwise AND and stays mask-backed. * `reverse_row_selection` slices and re-concatenates the bitmap for reverse scans, with a debug_assert guarding the row-count contract.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24186 +/- ##
==========================================
+ Coverage 81.02% 81.07% +0.04%
==========================================
Files 1105 1106 +1
Lines 380671 382067 +1396
Branches 380671 382067 +1396
==========================================
+ Hits 308436 309756 +1320
- Misses 54002 54038 +36
- Partials 18233 18273 +40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
run benchmark clickbench_partitioned clickbench_pushdown |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing preserve-bitmap-row-selection (605d2fb) to 0ef844e (merge-base) diff Run configurationrun benchmark clickbench_partitionedResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing preserve-bitmap-row-selection (605d2fb) to 0ef844e (merge-base) diff Run configurationrun benchmark clickbench_pushdownResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing preserve-bitmap-row-selection (605d2fb) to 0ef844e (merge-base) diff Run configurationrun benchmark clickbench_pushdownCPU Details (lscpu)Details
Resource Usageclickbench_pushdown — base (merge-base)
clickbench_pushdown — branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing preserve-bitmap-row-selection (605d2fb) to 0ef844e (merge-base) diff Run configurationrun benchmark clickbench_partitionedCPU Details (lscpu)Details
Resource Usageclickbench_partitioned — base (merge-base)
clickbench_partitioned — branch
File an issue against this benchmark runner |
|
🤔 the clickbench results look good -- let's see if I can reproduce them |
|
run benchmark clickbench_partitioned |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing preserve-bitmap-row-selection (605d2fb) to 0ef844e (merge-base) diff Run configurationrun benchmark clickbench_partitionedResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing preserve-bitmap-row-selection (605d2fb) to 0ef844e (merge-base) diff Run configurationrun benchmark clickbench_partitionedCPU Details (lscpu)Details
Resource Usageclickbench_partitioned — base (merge-base)
clickbench_partitioned — branch
File an issue against this benchmark runner |
Which issue does this PR close?
RowSelectioninParquetAccessPlan#23883Rationale for this change
Parquet 59 added a bitmap (
BooleanBuffer) backing forRowSelectionalongside the RLE selector form. However,ParquetAccessPlanalways materialized selectors, so a caller-provided bitmap selection (via theParquetRowSelectionextension or an externalParquetAccessPlan) was converted to RLE before reaching the parquet reader. For highly fragmented selections the bitmap form is significantly cheaper to build, slice, and intersect, so it should survive the trip through the access plan.What changes are included in this PR?
ParquetAccessPlan::try_new_from_overall_row_selectionsplits a mask-backed selection per row group withRowSelection::split_off, which slices theBooleanBuffer(O(bitmap) overall) instead of materializing selectors. The selector path is unchanged.ParquetAccessPlan::into_overall_row_selectionproduces a bitmap-backed overall selection when any row group selection is bitmap-backed, promoting selector-backed groups (e.g. groups that page index pruning intersected back to selectors). When no group is bitmap-backed, the existing selector path is preserved.ParquetAccessPlan::scan_selectionpromotes the incoming selection to a bitmap when the existing selection is bitmap-backed, sinceRowSelection::intersectiononly stays mask-backed when both sides are masks; the intersection is then a bitwise AND instead of a selector merge.reverse_row_selection(reverse scans for TopK) slices the bitmap per scanned row group and re-concatenates in reverse, keeping the mask backing; adebug_assertguards the "selection covers exactly the scanned row groups" contract.row_count() + skipped_row_count(), which avoids materializing selectors from a mask just to count rows.Are these changes tested?
Yes:
try_new_from_overall_row_selection(round trip + invalid row count), mixed-backing promotion ininto_overall_row_selection, mask preservation inscan_selection, and bitmap preservation throughPreparedAccessPlan::reverse(including a fully scanned row group).external_access_plan.rs: a bitmapParquetRowSelectionspanning row groups, and a bitmap selection combined with a predicate that prunes a row group via statistics.datafusion-datasource-parquetunit tests and theparquet_integrationsuite).Are there any user-facing changes?
No API changes. Behavior change: when any per-row-group selection is bitmap-backed, the overall
RowSelectionhanded to the parquet reader is now bitmap-backed instead of selector-backed (semantically identical selection).