Repository navigation
Conversation
xudong963
marked this pull request as ready for review
November 12, 2026 02:26
Evaluate an aggregate FILTER to All, Empty, or Rows, folding arrays that select every row or none into the same cases as scalar predicates. The ungrouped, compacting, and skip-partial paths share this representation, and the ungrouped path now also skips argument evaluation for arrays that reject every row. Cover literal, constant-folded, and prepared statement predicates in SQLLogicTest. Check array_agg, which keeps NULL arguments, so skip-partial conversion must still pass a rejecting filter when no row is selected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Follow-up to #27119, specifically the scalar FILTER review discussion.
Rationale for this change
An aggregate FILTER that evaluates to a scalar boolean currently expands that value into a batch-sized BooleanArray before deciding which rows to evaluate. Scalar predicates are common: literal and constant-folded predicates (such as
FILTER (WHERE 1 = 2)) and prepared statement parameters (FILTER (WHERE $1)) remain in the physical plan as literals, and scalar-returning UDFs return scalars at runtime. They can avoid this allocation and bitmap scanning.What changes are included in this PR?
GroupsAccumulator::convert_to_stateneeds it to produce empty states, because aggregates such asarray_aggkeep NULL arguments.What is the testing strategy for this PR?
cargo fmt --alland every./dev/rust_lint.shstep passed on the latest commit, including Clippy with all targets/features and-D warnings, dependency checks, Rust documentation, and the documentation website build. The exception iscargo audit, which could not load the advisory database locally because the installed cargo-audit does not support CVSS 4.0 entries; it passed for the first commit.release-nonlto.AGENTS.mdpassed for the first commit: 13,630 Rust tests, zero failures, eight ignored; all 548 SQLLogicTest files passed. With the latest commit merged into current main, alldatafusion-physical-planunit tests, the core aggregate integration tests, and all SQLLogicTest files pass.array_agg, multiple partitions, and skip-partial conversion. It checksskipped_aggregation_rowsto verify that conversion was exercised.Compared with main
34eb6dc5b, using the same benchmark source andrelease-nonltobuilds (65,536 rows, batches of 8,192):These are medians of three runs per build in alternating order, with 30 Criterion samples, 0.5 s warm-up, and 1 s measurement per case. The suite also covers grouped and skip-partial execution, shuffled 50%-selective array filters, and unfiltered controls.
Grouped and skip-partial timings did not change beyond run-to-run variation, about ±4% on this shared macOS machine: those paths already skipped batches with no selected rows. In three longer runs per build (60 samples, 1 s warm-up, 3 s measurement, alternating order), the array-filter, unfiltered, and scalar-true controls changed by -2.4% to +2.6% (table below). These local microbenchmarks are not end-to-end query speedup claims.
Benchmark code and reproduction commands
The following optional benchmark exercises scalar
true,false,NULL, andbatch-varying predicates in ungrouped, grouped, and skip-partial aggregation.
A shuffled 50%-selective array predicate and an unfiltered aggregate serve as
controls. It uses the existing in-memory
AggregateExecbenchmark helpers toexclude SQL planning and file I/O.
To run it locally, paste the function below into
datafusion/physical-plan/benches/aggregate_filter.rs, immediately beforeaggregate_filter_benchmark. Inaggregate_filter_benchmark, add this callimmediately after
let runtime = Runtime::new().unwrap();:Run from the repository root:
cargo bench --profile release-nonlto -p datafusion-physical-plan \ --features test_utils --bench aggregate_filter -- \ scalar_aggregate_filter --warm-up-time 0.5 --measurement-time 1 \ --sample-size 30 --noplotFor comparisons, apply the same snippet and registration call to both revisions,
use separate
CARGO_TARGET_DIRdirectories, and alternate the run order. Thebenchmark uses 65,536 rows in batches of 8,192, with 16 groups for grouped
aggregation and one group per row for skip-partial aggregation. The latter sets
both skip-partial probe thresholds to zero. The varying predicate returns the
first shuffled filter value in each batch as a scalar.
To repeat the longer control measurements:
cargo bench --profile release-nonlto -p datafusion-physical-plan \ --features test_utils --bench aggregate_filter -- \ 'scalar_aggregate_filter/(grouped|skip_partial)/(array_50_percent|unfiltered|true)$' \ --warm-up-time 1 --measurement-time 3 --sample-size 60 --noplotAre there any user-facing changes?
Lower overhead for aggregate FILTER predicates that evaluate to a scalar. SQL results and public APIs are unchanged.
🤖 Generated with Claude Code