This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new b0566c57cc fix: update filter predicates for min/max aggregates only
if bounds change (#20380)
b0566c57cc is described below
commit b0566c57cc0b9ee2db8465f53fbd0d6e9e08798c
Author: notashes <[email protected]>
AuthorDate: Mon Feb 16 20:48:09 2026 +0530
fix: update filter predicates for min/max aggregates only if bounds change
(#20380)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Part of #20324 (dynamic filter update overhead for aggregates)
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
Right now `AggregateStream::maybe_update_dyn_filter()` unconditionally
updates filter predicates after every batch even without any change.
Which triggers predicate rebuilds for file pruners even though we
converge towards the bounds quite early on.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
We only conditionally update filter predicates if the bounds change.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
The existing test suits pass. The existing clickbench regression shows
virtually no change.
<details>
<summary>Benchmark Results</summary>
The existing benchmarks don't reproduce this as it gets the data from
stats. So we can use a trick like `"EventDate" + 0` to force full table
scan.
```sql
SET datafusion.execution.parquet.binary_as_string = true;
SET datafusion.execution.parquet.pushdown_filters = false;
CREATE EXTERNAL TABLE hits STORED AS PARQUET LOCATION
'benchmarks/data/hits_partitioned';
CREATE VIEW hits_view AS SELECT "EventDate" + 0 AS "EventDate" FROM
hits;
-- Warmup
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view;
-- dyn_off x5: hard-coded filter, dynamic filter disabled
SET datafusion.optimizer.enable_aggregate_dynamic_filter_pushdown =
false;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view WHERE
"EventDate" > 0 AND "EventDate" < 99999999;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view WHERE
"EventDate" > 0 AND "EventDate" < 99999999;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view WHERE
"EventDate" > 0 AND "EventDate" < 99999999;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view WHERE
"EventDate" > 0 AND "EventDate" < 99999999;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view WHERE
"EventDate" > 0 AND "EventDate" < 99999999;
-- dyn_on x5: dynamic filter enabled
SET datafusion.optimizer.enable_aggregate_dynamic_filter_pushdown =
true;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits_view;
```
### Before (baseline)
| Iteration | dyn_off | dyn_on |
|-----------|---------|--------|
| 1 | 39ms | 44ms |
| 2 | 39ms | 44ms |
| 3 | 40ms | 44ms |
| 4 | 39ms | 45ms |
| 5 | 38ms | 45ms |
| **Avg** | **39.0ms** | **44.4ms** |
We can see that that it's a little slow to execute with dynamic filters
on.
### After (this PR)
| Iteration | dyn_off | dyn_on |
|-----------|---------|--------|
| 1 | 40ms | 33ms |
| 2 | 41ms | 32ms |
| 3 | 40ms | 32ms |
| 4 | 42ms | 32ms |
| 5 | 39ms | 31ms |
| **Avg** | **40.4ms** | **32.0ms** |
And we get approx 20% boost with the patch (in my local setup)
</details>
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
---------
Co-authored-by: Adrian Garcia Badaracco
<[email protected]>
---
.../physical-plan/src/aggregates/no_grouping.rs | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/datafusion/physical-plan/src/aggregates/no_grouping.rs
b/datafusion/physical-plan/src/aggregates/no_grouping.rs
index fe8942097a..a7dd7c9a66 100644
--- a/datafusion/physical-plan/src/aggregates/no_grouping.rs
+++ b/datafusion/physical-plan/src/aggregates/no_grouping.rs
@@ -161,6 +161,8 @@ impl AggregateStreamInner {
return Ok(());
};
+ let mut bounds_changed = false;
+
for acc_info in &filter_state.supported_accumulators_info {
let acc =
self.accumulators
@@ -176,20 +178,27 @@ impl AggregateStreamInner {
let current_bound = acc.evaluate()?;
{
let mut bound = acc_info.shared_bound.lock();
- match acc_info.aggr_type {
+ let new_bound = match acc_info.aggr_type {
DynamicFilterAggregateType::Max => {
- *bound = scalar_max(&bound, ¤t_bound)?;
+ scalar_max(&bound, ¤t_bound)?
}
DynamicFilterAggregateType::Min => {
- *bound = scalar_min(&bound, ¤t_bound)?;
+ scalar_min(&bound, ¤t_bound)?
}
+ };
+ if new_bound != *bound {
+ *bound = new_bound;
+ bounds_changed = true;
}
}
}
- // Step 2: Sync the dynamic filter physical expression with reader
- let predicate = self.build_dynamic_filter_from_accumulator_bounds()?;
- filter_state.filter.update(predicate)?;
+ // Step 2: Sync the dynamic filter physical expression with reader,
+ // but only if any bound actually changed.
+ if bounds_changed {
+ let predicate =
self.build_dynamic_filter_from_accumulator_bounds()?;
+ filter_state.filter.update(predicate)?;
+ }
Ok(())
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]