You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "petern48 (via GitHub)" <gi...@apache.org> on 2025/11/03 01:02:28 UTC
[PR] feat: Add `reduction_factor` metric to `AggregateExec` for EXPLAIN ANALYZE [datafusion]
petern48 opened a new pull request, #18455:
URL: https://github.com/apache/datafusion/pull/18455
## 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.
-->
- Closes #18410
## 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.
-->
## 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.
-->
e.g from the issue
```
create table t1(a int, b int);
insert into t1 values (1,10), (1, 20), (2,10), (2,30);
explain analyze select a, sum(b) from t1 group by a;
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Plan with Metrics | AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[sum(t1.b)], metrics=[output_rows=2, elapsed_compute=7.856539ms, output_bytes=544.0 B] |
| | CoalesceBatchesExec: target_batch_size=8192, metrics=[output_rows=2, elapsed_compute=192.334µs, output_bytes=96.0 KB] |
| | RepartitionExec: partitioning=Hash([a@0], 10), input_partitions=10, metrics=[] |
| | RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1, metrics=[] |
| | AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[sum(t1.b)], metrics=[output_rows=2, elapsed_compute=2.581625ms, output_bytes=544.0 B, reduction_factor=50% (2/4)] |
| | DataSourceExec: partitions=1, partition_sizes=[1], metrics=[] |
| | |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```
Note: For AggregateExec cases where this doesn't apply, the reduction_factor metric won't be shown. Here's an example of of the explain analyze from the modified test.
## 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)?
-->
Yes
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
Yes, a new metric will be visible when running `EXPLAIN ANALYZE`
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add `reduction_factor` metric to `AggregateExec` for EXPLAIN ANALYZE [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #18455:
URL: https://github.com/apache/datafusion/pull/18455#discussion_r2485175033
##########
datafusion/physical-plan/src/aggregates/row_hash.rs:
##########
@@ -433,6 +433,9 @@ pub(crate) struct GroupedHashAggregateStream {
/// Aggregation-specific metrics
group_by_metrics: GroupByMetrics,
+
+ /// Reduction factor metric (only for partial aggregation)
Review Comment:
```suggestion
/// Reduction factor metric, calculated as `output_rows/input_rows` (only for partial aggregation)
```
##########
datafusion/core/tests/sql/explain_analyze.rs:
##########
@@ -68,6 +68,13 @@ async fn explain_analyze_baseline_metrics() {
"AggregateExec: mode=Partial, gby=[]",
"output_bytes="
);
+
+ assert_metrics!(
+ &formatted,
+ "AggregateExec: mode=Partial, gby=[c1@0 as c1]",
+ "reduction_factor="
Review Comment:
This metric should be stable, we can include the specific expected value here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add `reduction_factor` metric to `AggregateExec` for EXPLAIN ANALYZE [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18455:
URL: https://github.com/apache/datafusion/pull/18455#discussion_r2487811844
##########
datafusion/core/tests/sql/explain_analyze.rs:
##########
@@ -68,6 +68,13 @@ async fn explain_analyze_baseline_metrics() {
"AggregateExec: mode=Partial, gby=[]",
"output_bytes="
);
+
+ assert_metrics!(
+ &formatted,
+ "AggregateExec: mode=Partial, gby=[c1@0 as c1]",
+ "reduction_factor=5.1% (5/99)"
Review Comment:
this is really nice
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add `reduction_factor` metric to `AggregateExec` for EXPLAIN ANALYZE [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #18455:
URL: https://github.com/apache/datafusion/pull/18455
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add `reduction_factor` metric to `AggregateExec` for EXPLAIN ANALYZE [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #18455:
URL: https://github.com/apache/datafusion/pull/18455#issuecomment-3482540676
Thank you @2010YOUY01 and @petern48
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add `reduction_factor` metric to `AggregateExec` for EXPLAIN ANALYZE [datafusion]
Posted by "petern48 (via GitHub)" <gi...@apache.org>.
petern48 commented on PR #18455:
URL: https://github.com/apache/datafusion/pull/18455#issuecomment-3478804346
Oh my bad, I didn't mean to click re-request review. (I forgot this is datafusion with the 24 hr merge delay)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org