Skip to content

refactor: split page index pruning into steps - #27975

Merged
adriangb merged 1 commit into
apache:mainfrom
adriangb:page-pruning-decompose
Dec 4, 2026
Merged

adriangb merged 1 commit into
apache:mainfrom
adriangb:page-pruning-decompose

Conversation

@adriangb

@adriangb adriangb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

PagePruningAccessPlanFilter::prune_plan_with_page_index_and_metrics is one function of about 250 lines with 11 mutable locals. It mixes four things:

prune_plan_with_page_index_and_metrics          about 250 lines
  guards (3 early returns)
  build inverse predicates                      only for LIMIT
  for each row group
    skip if fully matched
    for each predicate          -> selection, matched pages
    apply selection to the access plan, count rows
    for each inverse predicate  -> fully matched rows, only for LIMIT
    count pages
  write 4 metrics
  apply the LIMIT plan

The LIMIT path is the hardest part to follow, and it sits in the middle of ordinary pruning. The same four references to the file (arrow_schema, parquet_schema, parquet_metadata, file_metrics) go to every helper.

What changes are included in this PR?

PagePruner holds the file and the counts of one pass. Each step is one method:

prune_plan_with_page_index_and_metrics          about 100 lines
  guards
  inverted_predicates()                         only for LIMIT
  for each row group
    skip if fully matched
    pruner.prune_row_group()
    pruner.apply_selection()
    pruner.fully_matched_selection()            only for LIMIT
  pruner.counts.add_to(metrics)
  apply the LIMIT plan
New item Replaces
PagePruner::prune_row_group The loop over the predicates, and the page counters
PagePruner::apply_selection The update of the access plan, and the row counters
PagePruner::fully_matched_selection The loop over the inverse predicates, with its complete flag
PagePruner::prune_pages_for_predicate The free function of the same name with six arguments
PagePruner::page_count fully_matched_page_count, and an inline copy of the same expression
PagePruner::has_complete_page_index The inline check and its debug message
PagePruningCounts Four let mut total_* and the four metric writes
PagePruningAccessPlanFilter::inverted_predicates The inline closure

No behavior changes. The points that could change it, and that I checked against the old code:

  • The order of the early returns.
  • When the row and page counts are updated. Page counts are still added once per row group that is not fully matched.
  • The number of predicate evaluations on the LIMIT path. The test inverse_pruning_short_circuits counts them.
  • A row group whose inverse predicates give an empty selection is still recorded as an empty selection, and not as "unknown".

What is the testing strategy for this PR?

No new tests: this is a refactor, and the existing tests cover the code. They pass without changes:

  • The unit tests of datafusion-datasource-parquet (318), including the page filter tests for LIMIT pruning.
  • The Parquet integration tests in datafusion/core/tests/parquet (265), which assert the page index metrics.
  • The Parquet and LIMIT pruning sqllogictests.

I did not run benchmarks. The code runs the same steps in the same order, and it keeps the two page sets that the old code reuses across row groups.

Are there any user-facing changes?

No. Every new item is private.

🤖 Generated with Claude Code

PagePruningAccessPlanFilter::prune_plan_with_page_index_and_metrics is
one function of about 250 lines with 11 mutable locals. It mixes four
things: ordinary page pruning of a row group, the update of the access
plan, the search for fully matched rows that LIMIT pruning uses, and
the row and page counts. The same four references to the file go to
every helper that it calls.

Add PagePruner, which holds the file and the counts of one pass. Each
step is one method:

- prune_row_group applies the predicates to one row group
- apply_selection records the result in the access plan
- fully_matched_selection finds the rows that pass for certain
- prune_pages_for_predicate, which was a free function with six
  arguments

PagePruningCounts holds the four counters and writes them to the
metrics. inverted_predicates builds the inverse predicates.

The entry point is now about 100 lines and reads as the sequence of
those steps. No behavior changes: the order of the early returns, the
counts and the number of predicate evaluations are the same.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added the datasource Changes to the datasource crate label Dec 2, 2026
@adriangb

adriangb commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks folks!

@adriangb
adriangb added this pull request to the merge queue Dec 4, 2026
Merged via the queue into apache:main with commit 915c5b6 Dec 4, 2026
42 checks passed
@adriangb
adriangb deleted the page-pruning-decompose branch December 4, 2026 04:49
adriangb added a commit to adriangb/datafusion that referenced this pull request Dec 4, 2026
apache#27975 split page index pruning into `PagePruner` steps.
This merge keeps those steps and makes them read statistics by
`ParquetStatisticsTarget`. `PagePruner` no longer holds the Arrow schema,
because a target builds its statistics converter from the Parquet schema.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasource Changes to the datasource crate v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants