Skip to content

Prune Parquet Bloom filters column by column via batched byte-range reads - #234

Draft
aman-ddog wants to merge 1 commit into
aman/parquet-pageindex-after-bloomfrom
aman/parquet-bloom-column-by-column
Draft

aman-ddog wants to merge 1 commit into
aman/parquet-pageindex-after-bloomfrom
aman/parquet-bloom-column-by-column

Conversation

@aman-ddog

Copy link
Copy Markdown

Why

The Parquet opener currently loads every Bloom filter for every literal column across all surviving row groups up front, one get_row_group_column_bloom_filter call at a time, and only then evaluates the predicate. That has three costs. Columns that only appear in != / NOT IN are fetched even though a Bloom filter can never prune them. For a = 1 AND b = 2, b's filters are fetched for row groups that a already pruned. Each filter is a separate small read (header, then body), done in series. The opener also builds a second file reader with create_reader() on every file just for this step.

What changed

  • Only Guarantee::In literals are Bloom candidates.
    • Bloom filters have no false negatives, so they can prove a value is absent (=, IN) but never that a row group holds only excluded values. Columns that appear only in != / NOT IN are no longer fetched.
    • Columns with no Bloom filter in any surviving row group are dropped before any I/O. If no candidates remain, the Bloom step is skipped.
  • Deterministic column-by-column pruning.
    • Candidates are ordered by fewest literals, then smallest total Bloom filter size across survivors, then column index.
    • Each column is fetched only for row groups still alive after the previous columns, and the loop stops once nothing survives.
    • Each pass evaluates the full predicate against a single column's filter. Other columns are unknown there, so cross-column OR stays sound.
  • Exact-range batched reads replace per-filter reads.
    • When bloom_filter_length is present, the opener requests the exact [offset, offset + length) ranges with get_byte_ranges and decodes them with Sbbf::from_bytes. It no longer builds a second reader for each file.
    • Ranges are grouped into batches of at most 8 MiB per column (accounting for coalescing gaps up to 1 MiB, with oversized singletons fetched solo). Each batch is evaluated and dropped before the next one is fetched.
    • ParquetFileReader::get_byte_ranges now uses its own bounds-checked coalescer (1 MiB gap, 8 MiB max coalesced span, 10 concurrent fetches). Zero-length ranges return empty bytes without storage reads, inverted or overflowing totals return ParquetError::General before updating metrics, and short reads return ParquetError::EOF instead of panicking.
    • Legacy fallback: when the length is missing or the file is encrypted, the existing get_row_group_column_bloom_filter path is used. Its reader is created lazily, at most once per file.
    • Fail-open: invalid ranges, short buffers, decode errors, and empty filters keep the row group and increment predicate_evaluation_errors.
  • Metrics are counted once per row group entering the Bloom step.
    • New RowGroupAccessPlanFilter::prune_subset_by_bloom_filters records only pruned. matched is added once after the last pass, so pruned + matched equals the number of row groups that entered. The existing prune_by_bloom_filters keeps its behavior.
  • Diff breakdown (~68% tests).
    • Production: +716 / −139 lines (opener Bloom state and candidate selection, bounds-checked reader coalescing, row-group filter subset helper).
    • Tests: +1,508 / −12 lines, including an I/O-recording store that asserts exact Bloom byte ranges, backing-store fetch bounds, and single-reader counts.

Scope & caveats

  • Stacked on Load Parquet page indexes after Bloom filter pruning #233 (load the page index after Bloom filter pruning). Review only the incremental diff.
  • Query results are unchanged. No new configuration, and bloom_filter_on_read still controls the whole step.
  • The reader change affects all ParquetFileReader range reads, not just Bloom filters. Merging behavior matches the previous defaults, and a short read now returns an error instead of panicking. Custom ParquetFileReaderFactory readers keep their own get_byte_ranges.
  • Encrypted files and files written without bloom_filter_length use the legacy per-filter path, which is still column-by-column but not batched.
  • The 8 MiB batch budget is a fixed constant, applied per column. A single filter larger than the budget is fetched by itself.
  • No benchmark numbers are included. The gains depend on Bloom filter coverage, predicate shape, and object store latency.
Verification
  • New tests cover: NOT IN / != fetching no Bloom filters; AND stopping before the second column when the first prunes everything; the second column fetched only for surviving row groups; matched counted once when both columns survive; ordering by literal count with size tie-break; cross-column OR / DNF soundness; multiple row groups in a single get_byte_ranges call with no extra reader; bounded multi-batch splitting with the same result as unbatched; missing-length fallback; malformed metadata, corrupted payloads, and a truncated object all failing open without panics; coalescer ordering, duplicates, gaps, short reads, and inverted ranges.
  • cargo fmt --all -- --check: passed.
  • cargo clippy -p datafusion-datasource-parquet --all-targets --all-features -- -D warnings: passed.
  • cargo test -p datafusion-datasource-parquet --all-features (with PARQUET_TEST_DATA): 243/243 unit tests passed, 4/4 doctests passed (5 pre-existing ignored doctests).
  • Full workspace extended tests: CI only (not run locally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant