Skip to content

Wrap Arc to Statistics for partition_statistics API#20570

Open
xudong963 wants to merge 3 commits intoapache:mainfrom
xudong963:arc_stats
Open

Wrap Arc to Statistics for partition_statistics API#20570
xudong963 wants to merge 3 commits intoapache:mainfrom
xudong963:arc_stats

Conversation

@xudong963
Copy link
Member

@xudong963 xudong963 commented Feb 26, 2026

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@xudong963 xudong963 marked this pull request as draft February 26, 2026 10:57
@github-actions github-actions bot added optimizer Optimizer rules core Core DataFusion crate datasource Changes to the datasource crate physical-plan Changes to the physical-plan crate labels Feb 26, 2026
@xudong963 xudong963 marked this pull request as ready for review March 1, 2026 20:06
@xudong963 xudong963 requested a review from alamb March 1, 2026 20:06
@xudong963
Copy link
Member Author

cc @jonathanc-n

Copy link
Contributor

@getChan getChan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement. Since this changes public trait signatures (Result -> Result<Arc>), could we add a short note in user-facing changes / migration guide for downstream implementers?

/// (the default), not an error.
/// If `partition` is `None`, it returns statistics for the entire plan.
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
fn partition_statistics(&self, partition: Option<usize>) -> Result<Arc<Statistics>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking we should deprecate first + make another function signature (ex. shared_partition_statistics() or something). We can make the follow up on the new function signature after this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it should be. But given the change is small, only wrap an Arc, I'm thinking if it's enough to only mark the PR as API changing and add some notes to upgrade doc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. If I have the time, I'll try to do the the follow pull request, revert this API change and deprecate the original function in favour of the new one with Arc passed into the arguments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it should be. But given the change is small, only wrap an Arc, I'm thinking if it's enough to only mark the PR as API changing and add some notes to upgrade doc

I agree that marking as an API change and then adding an upgrade guide is enough

@xudong963 I didn't see anything in the upgrade guide yet -- you might be the first PR for 54.0.0 (53.0.0 is being finalized now)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically it should at least call out the Old vs new pattern:

Including the Arc::unwrap_or_clone example I think would also help people upgrade

  // old
  fn partition_statistics(&self, p: Option<usize>) -> Result<Statistics>;

  // new
  fn partition_statistics(&self, p: Option<usize>) -> Result<Arc<Statistics>>;

Copy link
Contributor

@jonathanc-n jonathanc-n Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only potential concern I have with this change is that it is a public API change (and thus will require a bunch of downstream consumer changes). If we are going to change the statistics API again in the near future having to do two API upgrades for the same function could be annoying to users

In regards to my second comment to this thread. If this is going through for v54.0.0, I can make a follow up PR to change this back to the original API signature before v54.1.0

// Change this
fn partition_statistics(&self, p: Option<usize>) -> Result<Arc<Statistics>>;

// Back to this
fn partition_statistics(&self, p: Option<usize>) -> Result<Statistics>;

// And then create new signature + deprecate old `partition_statistics()`
fn new_partition_statistics(&self, p: Option<usize>, child_statistics: Arc<Statistics>) -> Result<Arc<Statistics>>;

This allows users to not have to make two upgrades to the same thing

I put out #20711 to finish up the EPIC to somewhat unblock the concern in #20184. So after that merges, the follow up to this pull request can be made to add the new function signature. WDYT? @alamb @xudong963

@xudong963 xudong963 added the api change Changes the API exposed to users of the crate label Mar 2, 2026
Copy link
Member

@asolimando asolimando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @xudong963, good prerequisite for #20184 and also good to avoid deep clones, hope to see this landing soon :)

@jonathanc-n
Copy link
Contributor

cc @alamb

@paleolimbot paleolimbot mentioned this pull request Mar 4, 2026
22 tasks
@alamb
Copy link
Contributor

alamb commented Mar 4, 2026

run benchmark sql_planner

@alamb-ghbot
Copy link

🤖 ./gh_compare_branch_bench.sh compare_branch_bench.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing arc_stats (f6a232f) to 6713439 diff
BENCH_NAME=sql_planner
BENCH_COMMAND=cargo bench --features=parquet --bench sql_planner
BENCH_FILTER=
BENCH_BRANCH_NAME=arc_stats
Results will be posted here when complete

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @xudong963 @jonathanc-n @getChan and others.

This is a great idea and a great change -- and it came up on the sync call with @paleolimbot and @adriangb as well

I do think we should add a note to the upgrade guide before we merge this PR in, as suggested by @jonathanc-n

The only potential concern I have with this change is that it is a public API change (and thus will require a bunch of downstream consumer changes). If we are going to change the statistics API again in the near future having to do two API upgrades for the same function could be annoying to users

I suppose we have until DataFusion 54 ships to try and get our act together for a nicer statistics API so maybe this will provide some additional pressure to do so

/// (the default), not an error.
/// If `partition` is `None`, it returns statistics for the entire plan.
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
fn partition_statistics(&self, partition: Option<usize>) -> Result<Arc<Statistics>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it should be. But given the change is small, only wrap an Arc, I'm thinking if it's enough to only mark the PR as API changing and add some notes to upgrade doc

I agree that marking as an API change and then adding an upgrade guide is enough

@xudong963 I didn't see anything in the upgrade guide yet -- you might be the first PR for 54.0.0 (53.0.0 is being finalized now)

/// (the default), not an error.
/// If `partition` is `None`, it returns statistics for the entire plan.
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
fn partition_statistics(&self, partition: Option<usize>) -> Result<Arc<Statistics>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically it should at least call out the Old vs new pattern:

Including the Arc::unwrap_or_clone example I think would also help people upgrade

  // old
  fn partition_statistics(&self, p: Option<usize>) -> Result<Statistics>;

  // new
  fn partition_statistics(&self, p: Option<usize>) -> Result<Arc<Statistics>>;

@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

group                                                 arc_stats                              main
-----                                                 ---------                              ----
logical_aggregate_with_join                           1.00    635.5±2.49µs        ? ?/sec    1.01   641.4±11.97µs        ? ?/sec
logical_plan_struct_join_agg_sort                     1.00    292.1±3.63µs        ? ?/sec    1.00    291.6±3.72µs        ? ?/sec
logical_select_all_from_1000                          1.00     10.5±0.15ms        ? ?/sec    1.02     10.7±0.22ms        ? ?/sec
logical_select_one_from_700                           1.00    416.1±3.05µs        ? ?/sec    1.01    418.3±3.07µs        ? ?/sec
logical_trivial_join_high_numbered_columns            1.00   376.9±22.00µs        ? ?/sec    1.01   380.3±11.59µs        ? ?/sec
logical_trivial_join_low_numbered_columns             1.00    360.2±3.76µs        ? ?/sec    1.01    365.5±4.40µs        ? ?/sec
physical_intersection                                 1.00  1597.4±22.67µs        ? ?/sec    1.00   1599.9±5.59µs        ? ?/sec
physical_join_consider_sort                           1.00      2.3±0.05ms        ? ?/sec    1.01      2.3±0.03ms        ? ?/sec
physical_join_distinct                                1.00    350.4±3.32µs        ? ?/sec    1.00    351.8±5.91µs        ? ?/sec
physical_many_self_joins                              1.00     12.5±0.11ms        ? ?/sec    1.02     12.8±0.11ms        ? ?/sec
physical_plan_clickbench_all                          1.00    200.7±1.17ms        ? ?/sec    1.00    201.3±1.86ms        ? ?/sec
physical_plan_clickbench_q1                           1.00      2.1±0.03ms        ? ?/sec    1.02      2.2±0.03ms        ? ?/sec
physical_plan_clickbench_q10                          1.00      3.6±0.04ms        ? ?/sec    1.05      3.8±0.07ms        ? ?/sec
physical_plan_clickbench_q11                          1.00      4.1±0.05ms        ? ?/sec    1.03      4.3±0.07ms        ? ?/sec
physical_plan_clickbench_q12                          1.00      4.2±0.06ms        ? ?/sec    1.04      4.4±0.08ms        ? ?/sec
physical_plan_clickbench_q13                          1.00      3.8±0.04ms        ? ?/sec    1.03      3.9±0.06ms        ? ?/sec
physical_plan_clickbench_q14                          1.00      4.1±0.06ms        ? ?/sec    1.02      4.2±0.08ms        ? ?/sec
physical_plan_clickbench_q15                          1.00      3.8±0.04ms        ? ?/sec    1.02      3.9±0.08ms        ? ?/sec
physical_plan_clickbench_q16                          1.00      3.6±0.05ms        ? ?/sec    1.04      3.8±0.08ms        ? ?/sec
physical_plan_clickbench_q17                          1.00      3.7±0.07ms        ? ?/sec    1.02      3.8±0.09ms        ? ?/sec
physical_plan_clickbench_q18                          1.00      2.6±0.03ms        ? ?/sec    1.02      2.7±0.04ms        ? ?/sec
physical_plan_clickbench_q19                          1.00      4.1±0.05ms        ? ?/sec    1.04      4.3±0.06ms        ? ?/sec
physical_plan_clickbench_q2                           1.00      2.8±0.03ms        ? ?/sec    1.02      2.9±0.03ms        ? ?/sec
physical_plan_clickbench_q20                          1.00      2.1±0.02ms        ? ?/sec    1.00      2.1±0.04ms        ? ?/sec
physical_plan_clickbench_q21                          1.01      2.8±0.04ms        ? ?/sec    1.00      2.8±0.03ms        ? ?/sec
physical_plan_clickbench_q22                          1.00      4.0±0.09ms        ? ?/sec    1.00      4.0±0.05ms        ? ?/sec
physical_plan_clickbench_q23                          1.00      4.2±0.10ms        ? ?/sec    1.02      4.3±0.08ms        ? ?/sec
physical_plan_clickbench_q24                          1.00      4.8±0.10ms        ? ?/sec    1.02      5.0±0.08ms        ? ?/sec
physical_plan_clickbench_q25                          1.00      3.5±0.05ms        ? ?/sec    1.03      3.6±0.08ms        ? ?/sec
physical_plan_clickbench_q26                          1.01      2.9±0.05ms        ? ?/sec    1.00      2.9±0.03ms        ? ?/sec
physical_plan_clickbench_q27                          1.00      3.5±0.08ms        ? ?/sec    1.01      3.5±0.08ms        ? ?/sec
physical_plan_clickbench_q28                          1.00      4.4±0.07ms        ? ?/sec    1.00      4.4±0.09ms        ? ?/sec
physical_plan_clickbench_q29                          1.00      4.7±0.07ms        ? ?/sec    1.00      4.7±0.09ms        ? ?/sec
physical_plan_clickbench_q3                           1.00      2.5±0.02ms        ? ?/sec    1.02      2.6±0.03ms        ? ?/sec
physical_plan_clickbench_q30                          1.00     15.9±0.19ms        ? ?/sec    1.02     16.2±0.24ms        ? ?/sec
physical_plan_clickbench_q31                          1.00      4.4±0.06ms        ? ?/sec    1.00      4.5±0.08ms        ? ?/sec
physical_plan_clickbench_q32                          1.00      4.4±0.09ms        ? ?/sec    1.00      4.5±0.08ms        ? ?/sec
physical_plan_clickbench_q33                          1.00      3.6±0.06ms        ? ?/sec    1.00      3.6±0.04ms        ? ?/sec
physical_plan_clickbench_q34                          1.00      3.3±0.12ms        ? ?/sec    1.01      3.3±0.08ms        ? ?/sec
physical_plan_clickbench_q35                          1.01      3.3±0.06ms        ? ?/sec    1.00      3.3±0.04ms        ? ?/sec
physical_plan_clickbench_q36                          1.00      4.2±0.04ms        ? ?/sec    1.01      4.2±0.06ms        ? ?/sec
physical_plan_clickbench_q37                          1.00      4.7±0.04ms        ? ?/sec    1.00      4.7±0.05ms        ? ?/sec
physical_plan_clickbench_q38                          1.00      4.7±0.04ms        ? ?/sec    1.00      4.7±0.08ms        ? ?/sec
physical_plan_clickbench_q39                          1.00      4.0±0.06ms        ? ?/sec    1.00      4.0±0.05ms        ? ?/sec
physical_plan_clickbench_q4                           1.00      2.2±0.02ms        ? ?/sec    1.03      2.2±0.03ms        ? ?/sec
physical_plan_clickbench_q40                          1.00      4.8±0.12ms        ? ?/sec    1.00      4.7±0.04ms        ? ?/sec
physical_plan_clickbench_q41                          1.00      4.2±0.03ms        ? ?/sec    1.00      4.2±0.04ms        ? ?/sec
physical_plan_clickbench_q42                          1.00      4.2±0.06ms        ? ?/sec    1.00      4.2±0.04ms        ? ?/sec
physical_plan_clickbench_q43                          1.00      4.5±0.05ms        ? ?/sec    1.00      4.5±0.05ms        ? ?/sec
physical_plan_clickbench_q44                          1.00      2.3±0.02ms        ? ?/sec    1.00      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q45                          1.00      2.3±0.01ms        ? ?/sec    1.00      2.3±0.02ms        ? ?/sec
physical_plan_clickbench_q46                          1.00      3.2±0.02ms        ? ?/sec    1.00      3.2±0.03ms        ? ?/sec
physical_plan_clickbench_q47                          1.01      4.7±0.06ms        ? ?/sec    1.00      4.7±0.06ms        ? ?/sec
physical_plan_clickbench_q48                          1.00      5.0±0.07ms        ? ?/sec    1.00      5.0±0.04ms        ? ?/sec
physical_plan_clickbench_q49                          1.00      5.3±0.09ms        ? ?/sec    1.00      5.3±0.06ms        ? ?/sec
physical_plan_clickbench_q5                           1.00      2.5±0.03ms        ? ?/sec    1.03      2.6±0.08ms        ? ?/sec
physical_plan_clickbench_q50                          1.01      4.2±0.05ms        ? ?/sec    1.00      4.2±0.05ms        ? ?/sec
physical_plan_clickbench_q51                          1.00      3.5±0.05ms        ? ?/sec    1.00      3.6±0.03ms        ? ?/sec
physical_plan_clickbench_q6                           1.00      2.5±0.04ms        ? ?/sec    1.03      2.6±0.04ms        ? ?/sec
physical_plan_clickbench_q7                           1.00      2.1±0.02ms        ? ?/sec    1.03      2.1±0.03ms        ? ?/sec
physical_plan_clickbench_q8                           1.00      3.4±0.02ms        ? ?/sec    1.03      3.5±0.04ms        ? ?/sec
physical_plan_clickbench_q9                           1.00      3.6±0.03ms        ? ?/sec    1.02      3.7±0.04ms        ? ?/sec
physical_plan_struct_join_agg_sort                    1.00      3.2±0.04ms        ? ?/sec    1.02      3.3±0.05ms        ? ?/sec
physical_plan_tpcds_all                               1.00  1921.4±14.16ms        ? ?/sec    1.00  1916.8±16.02ms        ? ?/sec
physical_plan_tpch_all                                1.01    127.4±1.66ms        ? ?/sec    1.00    126.4±1.08ms        ? ?/sec
physical_plan_tpch_q1                                 1.00      2.9±0.04ms        ? ?/sec    1.00      2.9±0.01ms        ? ?/sec
physical_plan_tpch_q10                                1.00      7.2±0.08ms        ? ?/sec    1.01      7.2±0.18ms        ? ?/sec
physical_plan_tpch_q11                                1.00      8.5±0.08ms        ? ?/sec    1.01      8.6±0.12ms        ? ?/sec
physical_plan_tpch_q12                                1.00      3.0±0.06ms        ? ?/sec    1.01      3.1±0.08ms        ? ?/sec
physical_plan_tpch_q13                                1.02      3.0±0.03ms        ? ?/sec    1.00      3.0±0.01ms        ? ?/sec
physical_plan_tpch_q14                                1.00      3.0±0.02ms        ? ?/sec    1.00      3.0±0.01ms        ? ?/sec
physical_plan_tpch_q16                                1.00      5.2±0.04ms        ? ?/sec    1.00      5.2±0.04ms        ? ?/sec
physical_plan_tpch_q17                                1.00      5.6±0.02ms        ? ?/sec    1.00      5.6±0.06ms        ? ?/sec
physical_plan_tpch_q18                                1.00      6.0±0.05ms        ? ?/sec    1.00      6.0±0.09ms        ? ?/sec
physical_plan_tpch_q19                                1.00      5.2±0.03ms        ? ?/sec    1.00      5.2±0.05ms        ? ?/sec
physical_plan_tpch_q2                                 1.01     12.5±0.28ms        ? ?/sec    1.00     12.4±0.11ms        ? ?/sec
physical_plan_tpch_q20                                1.00      8.0±0.07ms        ? ?/sec    1.01      8.1±0.14ms        ? ?/sec
physical_plan_tpch_q21                                1.00     10.1±0.07ms        ? ?/sec    1.01     10.1±0.17ms        ? ?/sec
physical_plan_tpch_q22                                1.00      6.5±0.06ms        ? ?/sec    1.00      6.5±0.07ms        ? ?/sec
physical_plan_tpch_q3                                 1.01      5.6±0.07ms        ? ?/sec    1.00      5.6±0.10ms        ? ?/sec
physical_plan_tpch_q4                                 1.00      3.0±0.03ms        ? ?/sec    1.00      3.0±0.06ms        ? ?/sec
physical_plan_tpch_q5                                 1.02      6.0±0.13ms        ? ?/sec    1.00      5.9±0.08ms        ? ?/sec
physical_plan_tpch_q6                                 1.01  1608.5±26.46µs        ? ?/sec    1.00  1590.9±14.92µs        ? ?/sec
physical_plan_tpch_q7                                 1.00      7.2±0.15ms        ? ?/sec    1.00      7.2±0.21ms        ? ?/sec
physical_plan_tpch_q8                                 1.00      9.4±0.21ms        ? ?/sec    1.00      9.4±0.14ms        ? ?/sec
physical_plan_tpch_q9                                 1.00      6.7±0.08ms        ? ?/sec    1.01      6.7±0.10ms        ? ?/sec
physical_select_aggregates_from_200                   1.00     17.4±0.13ms        ? ?/sec    1.02     17.7±0.09ms        ? ?/sec
physical_select_all_from_1000                         1.00     23.4±0.24ms        ? ?/sec    1.02     23.9±0.31ms        ? ?/sec
physical_select_one_from_700                          1.00   1335.6±9.16µs        ? ?/sec    1.00  1330.0±16.19µs        ? ?/sec
physical_sorted_union_order_by_10_int64               1.00      9.8±0.08ms        ? ?/sec    1.02     10.0±0.28ms        ? ?/sec
physical_sorted_union_order_by_10_uint64              1.00     27.4±0.34ms        ? ?/sec    1.02     27.9±0.35ms        ? ?/sec
physical_sorted_union_order_by_50_int64               1.00    157.0±2.15ms        ? ?/sec    1.01    159.3±1.41ms        ? ?/sec
physical_sorted_union_order_by_50_uint64              1.00    969.7±7.39ms        ? ?/sec    1.00    973.0±8.14ms        ? ?/sec
physical_theta_join_consider_sort                     1.00      2.6±0.03ms        ? ?/sec    1.01      2.7±0.04ms        ? ?/sec
physical_unnest_to_join                               1.00      3.1±0.02ms        ? ?/sec    1.01      3.1±0.02ms        ? ?/sec
physical_window_function_partition_by_12_on_values    1.00  1277.5±14.01µs        ? ?/sec    1.00  1271.6±16.11µs        ? ?/sec
physical_window_function_partition_by_30_on_values    1.00      2.1±0.08ms        ? ?/sec    1.01      2.1±0.08ms        ? ?/sec
physical_window_function_partition_by_4_on_values     1.00    946.8±7.21µs        ? ?/sec    1.00   948.8±14.30µs        ? ?/sec
physical_window_function_partition_by_7_on_values     1.00   1064.2±5.10µs        ? ?/sec    1.00  1062.5±10.91µs        ? ?/sec
physical_window_function_partition_by_8_on_values     1.00  1117.5±19.82µs        ? ?/sec    1.00  1114.5±18.87µs        ? ?/sec
with_param_values_many_columns                        1.00    579.5±5.04µs        ? ?/sec    1.01    584.4±6.12µs        ? ?/sec

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

Labels

api change Changes the API exposed to users of the crate core Core DataFusion crate datasource Changes to the datasource crate optimizer Optimizer rules physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants