Skip to content

Cache PlanProperties, add fast-path for with_new_children - #19792

Merged
alamb merged 8 commits into
apache:mainfrom
askalt:askalt/with_new_children_fast_path
Feb 24, 2026
Merged

Cache PlanProperties, add fast-path for with_new_children#19792
alamb merged 8 commits into
apache:mainfrom
askalt:askalt/with_new_children_fast_path

Conversation

@askalt

@askaltaskalt commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

This patch aims to implement a fast-path for the ExecutionPlan::with_new_children function for some plans, moving closer to a physical plan re-use implementation and improving planning performance. If the passed children properties are the same as in self, we do not actually recompute self's properties (which could be costly if projection mapping is required). Instead, we just replace the children and re-use self's properties as-is.

To be able to compare two different properties -- ExecutionPlan::properties(...) signature is modified and now returns &Arc<PlanProperties>. If children properties are the same in with_new_children -- we clone our properties arc and then a parent plan will consider our properties as unchanged, doing the same.

  • Return &Arc<PlanProperties> from ExecutionPlan::properties(...) instead of a reference.
  • Implement with_new_children fast-path if there is no children properties changes for all
    major plans.

Note: currently, reset_plan_states does not allow to re-use plan in general: it is not
supported for dynamic filters and recursive queries features, as in this case state reset
should update pointers in the children plans.

@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation physical-expr Changes to the physical-expr crates optimizer Optimizer rules core Core DataFusion crate catalog Related to the catalog crate common Related to common crate proto Related to proto crate datasource Changes to the datasource crate ffi Changes to the ffi crate physical-plan Changes to the physical-plan crate labels Jan 13, 2026
@askaltaskalt changed the title add fast-path for with_new_childrenDraft: add fast-path for with_new_childrenJan 13, 2026
@askalt
askalt marked this pull request as draft January 13, 2026 14:26
@askalt
askaltforce-pushed the askalt/with_new_children_fast_path branch from 72ff575 to 796f731CompareJanuary 13, 2026 15:20
@askalt

Copy link
Copy Markdown
ContributorAuthor

Also added a typical analytical query plan re-usage benchmark. On the main branch it runs ~4-5 ms when at this MR it spends ~100us.

$ cargo bench --profile=release-nonlto --bench plan_reuse

@askalt
askaltforce-pushed the askalt/with_new_children_fast_path branch from 796f731 to 5601c4fCompareJanuary 13, 2026 15:24
@alamb

Copy link
Copy Markdown
Contributor

I filed a ticket to track this idea

@alamb

Copy link
Copy Markdown
Contributor

run benchmark sql_planner

@alamb-ghbot

Copy link
Copy Markdown

🤖 ./gh_compare_branch_bench.shcompare_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 askalt/with_new_children_fast_path (5601c4f) to 4c67d02diff
BENCH_NAME=sql_planner
BENCH_COMMAND=cargo bench --features=parquet --bench sql_planner
BENCH_FILTER=
BENCH_BRANCH_NAME=askalt_with_new_children_fast_path
Results will be posted here when complete

@alamb

Copy link
Copy Markdown
Contributor

Also added a typical analytical query plan re-usage benchmark. On the main branch it runs ~4-5 ms when at this MR it spends ~100us.

$ cargo bench --profile=release-nonlto --bench plan_reuse

Could you move the plan_reuse benchmark into its own PR (as I think it is valuable both for this PR and others, and it makes it easier to automatically compare performance)

@alamb-ghbot

Copy link
Copy Markdown

Benchmark script failed with exit code 101.

Last 10 lines of output:

Click to expand
 time: [5.6457 ms 5.6877 ms 5.7286 ms]
Benchmarking physical_plan_clickbench_q50
Benchmarking physical_plan_clickbench_q50: Warming up for 3.0000 s
thread 'main' (3793320) panicked at datafusion/core/benches/sql_planner.rs:62:14:
called `Result::unwrap()` on an `Err` value: Context("type_coercion", Internal("Expect TypeSignatureClass::Native(LogicalType(Native(String), String)) but received NativeType::Binary, DataType: BinaryView"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: bench failed, to rerun pass `-p datafusion --bench sql_planner`

@askalt

Copy link
Copy Markdown
ContributorAuthor

Also added a typical analytical query plan re-usage benchmark. On the main branch it runs ~4-5 ms when at this MR it spends ~100us.

$ cargo bench --profile=release-nonlto --bench plan_reuse

Could you move the plan_reuse benchmark into its own PR (as I think it is valuable both for this PR and others, and it makes it easier to automatically compare performance)

Done in #19806

@askalt
askaltforce-pushed the askalt/with_new_children_fast_path branch from 5601c4f to 99cf634CompareJanuary 14, 2026 10:32
@askalt

askalt commented Jan 14, 2026

Copy link
Copy Markdown
ContributorAuthor

Benchmark script failed with exit code 101.

Last 10 lines of output:

Click to expand

The same panic on 4c67d02

Created an issue for it: #19809

@askalt
askaltforce-pushed the askalt/with_new_children_fast_path branch from 99cf634 to b81dd66CompareJanuary 14, 2026 14:49

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @askalt -- this is quite clever and I think it looks very promising

I also think we may be able to potentially make with_new_children even faster by checking the children as well -- and if they are the same there is no reason to recompute everything either.

However, this likely won't help your usecase as the children will likely change (their states need to be reset) 🤔

Comment threaddatafusion/physical-plan/src/aggregates/mod.rs Outdated
Comment threaddatafusion/physical-plan/src/execution_plan.rs
@askalt
askaltforce-pushed the askalt/with_new_children_fast_path branch from b81dd66 to 741b085CompareJanuary 15, 2026 11:48
@askalt
askalt marked this pull request as ready for review January 15, 2026 11:49
@alambalamb added the performance Make DataFusion faster label Feb 24, 2026
@alamb

Copy link
Copy Markdown
Contributor

I plan to merge this later today unless anyone else would like more time to review

@askalt

askalt commented Feb 24, 2026

Copy link
Copy Markdown
ContributorAuthor

Can you please look at the latest few commits to make sure they look reasonable?

Thank you! Sorry for the delay, I checked the patches, they look good to me.

@alamb

Copy link
Copy Markdown
Contributor

Can you please look at the latest few commits to make sure they look reasonable?

Thank you! Sorry for the delay, I checked the patches, they look good to me.

It was my bad -- I was out last week

I just merged up again to resolve a conflict

@alamb

Copy link
Copy Markdown
Contributor

run benchmark sql_planner

@alamb
alamb added this pull request to the merge queueFeb 24, 2026
@alamb

Copy link
Copy Markdown
Contributor

Thanks again @askalt

Merged via the queue into apache:main with commit 34dad2cFeb 24, 2026
33 checks passed
@alamb-ghbot

Copy link
Copy Markdown

🤖 ./gh_compare_branch_bench.shcompare_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 askalt/with_new_children_fast_path (bf74d31) to b16ad9bdiff
BENCH_NAME=sql_planner
BENCH_COMMAND=cargo bench --features=parquet --bench sql_planner
BENCH_FILTER=
BENCH_BRANCH_NAME=askalt_with_new_children_fast_path
Results will be posted here when complete

@alamb-ghbot

Copy link
Copy Markdown

🤖: Benchmark completed

Details

group askalt_with_new_children_fast_path main
----- ---------------------------------- ----
logical_aggregate_with_join 1.00 627.8±6.83µs ? ?/sec 1.01 631.4±3.91µs ? ?/sec
logical_plan_struct_join_agg_sort 1.00 289.6±2.10µs ? ?/sec 1.00 291.0±3.38µs ? ?/sec
logical_select_all_from_1000 1.00 10.4±0.04ms ? ?/sec 1.04 10.8±0.03ms ? ?/sec
logical_select_one_from_700 1.00 411.7±2.35µs ? ?/sec 1.01 414.8±3.32µs ? ?/sec
logical_trivial_join_high_numbered_columns 1.00 366.8±1.83µs ? ?/sec 1.01 369.4±1.33µs ? ?/sec
logical_trivial_join_low_numbered_columns 1.00 353.7±3.74µs ? ?/sec 1.01 356.3±2.06µs ? ?/sec
physical_intersection 1.00 1573.8±15.06µs ? ?/sec 1.02 1599.7±15.60µs ? ?/sec
physical_join_consider_sort 1.00 2.2±0.03ms ? ?/sec 1.02 2.3±0.03ms ? ?/sec
physical_join_distinct 1.00 345.6±1.92µs ? ?/sec 1.01 348.5±2.43µs ? ?/sec
physical_many_self_joins 1.00 12.2±0.11ms ? ?/sec 1.01 12.4±0.19ms ? ?/sec
physical_plan_clickbench_all 1.00 199.3±2.27ms ? ?/sec 1.01 200.8±2.22ms ? ?/sec
physical_plan_clickbench_q1 1.00 2.1±0.05ms ? ?/sec 1.00 2.1±0.02ms ? ?/sec
physical_plan_clickbench_q10 1.00 3.6±0.02ms ? ?/sec 1.02 3.6±0.05ms ? ?/sec
physical_plan_clickbench_q11 1.00 4.1±0.07ms ? ?/sec 1.01 4.1±0.03ms ? ?/sec
physical_plan_clickbench_q12 1.00 4.2±0.05ms ? ?/sec 1.03 4.3±0.06ms ? ?/sec
physical_plan_clickbench_q13 1.00 3.7±0.05ms ? ?/sec 1.03 3.8±0.14ms ? ?/sec
physical_plan_clickbench_q14 1.00 4.1±0.05ms ? ?/sec 1.02 4.1±0.02ms ? ?/sec
physical_plan_clickbench_q15 1.00 3.8±0.03ms ? ?/sec 1.02 3.8±0.08ms ? ?/sec
physical_plan_clickbench_q16 1.00 3.6±0.05ms ? ?/sec 1.01 3.7±0.06ms ? ?/sec
physical_plan_clickbench_q17 1.00 3.7±0.03ms ? ?/sec 1.01 3.8±0.05ms ? ?/sec
physical_plan_clickbench_q18 1.00 2.7±0.06ms ? ?/sec 1.00 2.7±0.02ms ? ?/sec
physical_plan_clickbench_q19 1.00 4.1±0.06ms ? ?/sec 1.02 4.2±0.11ms ? ?/sec
physical_plan_clickbench_q2 1.00 2.8±0.04ms ? ?/sec 1.01 2.8±0.05ms ? ?/sec
physical_plan_clickbench_q20 1.00 2.1±0.02ms ? ?/sec 1.02 2.2±0.04ms ? ?/sec
physical_plan_clickbench_q21 1.00 2.8±0.03ms ? ?/sec 1.00 2.8±0.03ms ? ?/sec
physical_plan_clickbench_q22 1.00 3.9±0.04ms ? ?/sec 1.02 4.0±0.10ms ? ?/sec
physical_plan_clickbench_q23 1.00 4.2±0.10ms ? ?/sec 1.01 4.2±0.08ms ? ?/sec
physical_plan_clickbench_q24 1.00 4.8±0.05ms ? ?/sec 1.02 4.9±0.12ms ? ?/sec
physical_plan_clickbench_q25 1.00 3.5±0.06ms ? ?/sec 1.01 3.5±0.10ms ? ?/sec
physical_plan_clickbench_q26 1.00 2.9±0.02ms ? ?/sec 1.01 2.9±0.03ms ? ?/sec
physical_plan_clickbench_q27 1.00 3.4±0.08ms ? ?/sec 1.02 3.5±0.10ms ? ?/sec
physical_plan_clickbench_q28 1.00 4.4±0.08ms ? ?/sec 1.03 4.5±0.09ms ? ?/sec
physical_plan_clickbench_q29 1.00 4.7±0.12ms ? ?/sec 1.01 4.7±0.07ms ? ?/sec
physical_plan_clickbench_q3 1.01 2.6±0.08ms ? ?/sec 1.00 2.5±0.05ms ? ?/sec
physical_plan_clickbench_q30 1.01 16.0±0.53ms ? ?/sec 1.00 15.8±0.10ms ? ?/sec
physical_plan_clickbench_q31 1.00 4.4±0.12ms ? ?/sec 1.01 4.5±0.07ms ? ?/sec
physical_plan_clickbench_q32 1.00 4.4±0.07ms ? ?/sec 1.01 4.5±0.11ms ? ?/sec
physical_plan_clickbench_q33 1.00 3.6±0.05ms ? ?/sec 1.00 3.6±0.02ms ? ?/sec
physical_plan_clickbench_q34 1.00 3.2±0.04ms ? ?/sec 1.03 3.3±0.16ms ? ?/sec
physical_plan_clickbench_q35 1.00 3.3±0.05ms ? ?/sec 1.01 3.3±0.01ms ? ?/sec
physical_plan_clickbench_q36 1.00 4.2±0.04ms ? ?/sec 1.04 4.3±0.12ms ? ?/sec
physical_plan_clickbench_q37 1.00 4.7±0.14ms ? ?/sec 1.02 4.8±0.15ms ? ?/sec
physical_plan_clickbench_q38 1.00 4.6±0.08ms ? ?/sec 1.01 4.7±0.07ms ? ?/sec
physical_plan_clickbench_q39 1.00 4.0±0.07ms ? ?/sec 1.01 4.1±0.01ms ? ?/sec
physical_plan_clickbench_q4 1.00 2.2±0.04ms ? ?/sec 1.00 2.2±0.04ms ? ?/sec
physical_plan_clickbench_q40 1.00 4.7±0.10ms ? ?/sec 1.04 4.9±0.09ms ? ?/sec
physical_plan_clickbench_q41 1.00 4.2±0.06ms ? ?/sec 1.03 4.3±0.07ms ? ?/sec
physical_plan_clickbench_q42 1.00 4.1±0.09ms ? ?/sec 1.03 4.3±0.08ms ? ?/sec
physical_plan_clickbench_q43 1.00 4.4±0.04ms ? ?/sec 1.03 4.5±0.06ms ? ?/sec
physical_plan_clickbench_q44 1.00 2.3±0.04ms ? ?/sec 1.00 2.3±0.05ms ? ?/sec
physical_plan_clickbench_q45 1.00 2.3±0.02ms ? ?/sec 1.01 2.3±0.03ms ? ?/sec
physical_plan_clickbench_q46 1.00 3.2±0.02ms ? ?/sec 1.00 3.2±0.01ms ? ?/sec
physical_plan_clickbench_q47 1.00 4.6±0.06ms ? ?/sec 1.01 4.7±0.01ms ? ?/sec
physical_plan_clickbench_q48 1.00 5.0±0.06ms ? ?/sec 1.03 5.1±0.02ms ? ?/sec
physical_plan_clickbench_q49 1.00 5.2±0.07ms ? ?/sec 1.03 5.4±0.04ms ? ?/sec
physical_plan_clickbench_q5 1.00 2.5±0.03ms ? ?/sec 1.02 2.5±0.03ms ? ?/sec
physical_plan_clickbench_q50 1.00 4.2±0.04ms ? ?/sec 1.04 4.3±0.14ms ? ?/sec
physical_plan_clickbench_q51 1.00 3.5±0.07ms ? ?/sec 1.02 3.6±0.10ms ? ?/sec
physical_plan_clickbench_q6 1.00 2.5±0.05ms ? ?/sec 1.01 2.5±0.05ms ? ?/sec
physical_plan_clickbench_q7 1.00 2.1±0.01ms ? ?/sec 1.01 2.1±0.04ms ? ?/sec
physical_plan_clickbench_q8 1.00 3.4±0.05ms ? ?/sec 1.03 3.5±0.09ms ? ?/sec
physical_plan_clickbench_q9 1.00 3.6±0.06ms ? ?/sec 1.02 3.6±0.08ms ? ?/sec
physical_plan_struct_join_agg_sort 1.00 3.2±0.12ms ? ?/sec 1.04 3.3±0.04ms ? ?/sec
physical_plan_tpcds_all 1.00 1838.2±29.19ms ? ?/sec 1.05 1922.5±20.18ms ? ?/sec
physical_plan_tpch_all 1.00 122.7±2.45ms ? ?/sec 1.04 127.0±1.69ms ? ?/sec
physical_plan_tpch_q1 1.00 2.9±0.02ms ? ?/sec 1.04 3.0±0.04ms ? ?/sec
physical_plan_tpch_q10 1.00 6.9±0.12ms ? ?/sec 1.06 7.3±0.13ms ? ?/sec
physical_plan_tpch_q11 1.00 8.3±0.33ms ? ?/sec 1.02 8.5±0.09ms ? ?/sec
physical_plan_tpch_q12 1.00 3.1±0.10ms ? ?/sec 1.01 3.1±0.05ms ? ?/sec
physical_plan_tpch_q13 1.00 2.9±0.02ms ? ?/sec 1.02 3.0±0.02ms ? ?/sec
physical_plan_tpch_q14 1.00 2.9±0.02ms ? ?/sec 1.07 3.1±0.12ms ? ?/sec
physical_plan_tpch_q16 1.00 5.0±0.03ms ? ?/sec 1.04 5.2±0.17ms ? ?/sec
physical_plan_tpch_q17 1.00 5.5±0.11ms ? ?/sec 1.03 5.6±0.09ms ? ?/sec
physical_plan_tpch_q18 1.00 5.8±0.03ms ? ?/sec 1.04 6.0±0.27ms ? ?/sec
physical_plan_tpch_q19 1.00 5.1±0.02ms ? ?/sec 1.03 5.3±0.16ms ? ?/sec
physical_plan_tpch_q2 1.00 11.8±0.20ms ? ?/sec 1.06 12.4±0.29ms ? ?/sec
physical_plan_tpch_q20 1.00 7.8±0.09ms ? ?/sec 1.03 8.0±0.10ms ? ?/sec
physical_plan_tpch_q21 1.00 9.8±0.13ms ? ?/sec 1.06 10.4±0.50ms ? ?/sec
physical_plan_tpch_q22 1.00 6.3±0.06ms ? ?/sec 1.02 6.5±0.06ms ? ?/sec
physical_plan_tpch_q3 1.00 5.4±0.07ms ? ?/sec 1.04 5.7±0.04ms ? ?/sec
physical_plan_tpch_q4 1.01 3.0±0.10ms ? ?/sec 1.00 3.0±0.03ms ? ?/sec
physical_plan_tpch_q5 1.00 5.7±0.08ms ? ?/sec 1.05 6.0±0.11ms ? ?/sec
physical_plan_tpch_q6 1.00 1592.9±18.04µs ? ?/sec 1.01 1614.7±7.68µs ? ?/sec
physical_plan_tpch_q7 1.00 6.9±0.08ms ? ?/sec 1.05 7.2±0.20ms ? ?/sec
physical_plan_tpch_q8 1.00 8.9±0.18ms ? ?/sec 1.04 9.2±0.09ms ? ?/sec
physical_plan_tpch_q9 1.00 6.3±0.15ms ? ?/sec 1.08 6.8±0.34ms ? ?/sec
physical_select_aggregates_from_200 1.00 17.5±0.17ms ? ?/sec 1.01 17.6±0.19ms ? ?/sec
physical_select_all_from_1000 1.00 23.4±0.09ms ? ?/sec 1.03 24.2±0.09ms ? ?/sec
physical_select_one_from_700 1.00 1314.3±15.36µs ? ?/sec 1.01 1323.2±13.61µs ? ?/sec
physical_sorted_union_order_by_10_int64 1.00 9.7±0.13ms ? ?/sec 1.18 11.4±0.52ms ? ?/sec
physical_sorted_union_order_by_10_uint64 1.00 26.9±0.50ms ? ?/sec 1.12 30.1±0.41ms ? ?/sec
physical_sorted_union_order_by_50_int64 1.00 153.2±1.73ms ? ?/sec 1.29 197.7±2.91ms ? ?/sec
physical_sorted_union_order_by_50_uint64 1.00 947.6±10.63ms ? ?/sec 1.15 1092.4±14.74ms ? ?/sec
physical_theta_join_consider_sort 1.00 2.6±0.03ms ? ?/sec 1.03 2.7±0.07ms ? ?/sec
physical_unnest_to_join 1.00 3.1±0.03ms ? ?/sec 1.01 3.1±0.04ms ? ?/sec
physical_window_function_partition_by_12_on_values 1.00 1285.1±31.90µs ? ?/sec 1.23 1580.3±29.48µs ? ?/sec
physical_window_function_partition_by_30_on_values 1.00 2.1±0.01ms ? ?/sec 1.41 2.9±0.04ms ? ?/sec
physical_window_function_partition_by_4_on_values 1.00 935.8±6.34µs ? ?/sec 1.16 1088.7±7.02µs ? ?/sec
physical_window_function_partition_by_7_on_values 1.00 1058.0±11.76µs ? ?/sec 1.22 1292.1±47.39µs ? ?/sec
physical_window_function_partition_by_8_on_values 1.00 1108.2±21.80µs ? ?/sec 1.20 1330.4±25.27µs ? ?/sec
with_param_values_many_columns 1.00 583.7±12.48µs ? ?/sec 1.00 584.2±6.33µs ? ?/sec

@alamb

Copy link
Copy Markdown
Contributor

The benchmark results make this look like an across the board won I would say for planning speed

@alamb-ghbot

Copy link
Copy Markdown

🤖 ./gh_compare_branch_bench.shcompare_branch_bench.sh Running
Linux aal-dev 6.17.0-1008-gcp #8~24.04.1-Ubuntu SMP Fri Jan 30 23:44:29 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Comparing askalt/with_new_children_fast_path (bf74d31) to b16ad9bdiff
BENCH_NAME=sql_planner
BENCH_COMMAND=cargo bench --features=parquet --bench sql_planner
BENCH_FILTER=
BENCH_BRANCH_NAME=askalt_with_new_children_fast_path
Results will be posted here when complete

@alamb-ghbot

Copy link
Copy Markdown

🤖: Benchmark completed

Details

group askalt_with_new_children_fast_path main
----- ---------------------------------- ----
logical_aggregate_with_join 1.00 629.1±4.08µs ? ?/sec 1.00 627.7±1.10µs ? ?/sec
logical_plan_struct_join_agg_sort 1.01 291.3±2.25µs ? ?/sec 1.00 289.1±3.02µs ? ?/sec
logical_select_all_from_1000 1.00 10.5±0.06ms ? ?/sec 1.04 10.9±0.07ms ? ?/sec
logical_select_one_from_700 1.00 414.8±2.44µs ? ?/sec 1.00 415.4±3.26µs ? ?/sec
logical_trivial_join_high_numbered_columns 1.00 370.1±1.53µs ? ?/sec 1.00 368.5±0.68µs ? ?/sec
logical_trivial_join_low_numbered_columns 1.01 356.8±1.84µs ? ?/sec 1.00 354.1±1.37µs ? ?/sec
physical_intersection 1.00 1573.4±16.94µs ? ?/sec 1.00 1578.6±22.35µs ? ?/sec
physical_join_consider_sort 1.00 2.2±0.03ms ? ?/sec 1.00 2.2±0.01ms ? ?/sec
physical_join_distinct 1.00 349.8±2.62µs ? ?/sec 1.00 348.5±2.31µs ? ?/sec
physical_many_self_joins 1.00 12.3±0.08ms ? ?/sec 1.00 12.3±0.04ms ? ?/sec
physical_plan_clickbench_all 1.00 197.4±2.04ms ? ?/sec 1.01 199.4±1.60ms ? ?/sec
physical_plan_clickbench_q1 1.00 2.1±0.02ms ? ?/sec 1.00 2.1±0.02ms ? ?/sec
physical_plan_clickbench_q10 1.00 3.5±0.03ms ? ?/sec 1.01 3.6±0.02ms ? ?/sec
physical_plan_clickbench_q11 1.00 4.0±0.03ms ? ?/sec 1.02 4.1±0.09ms ? ?/sec
physical_plan_clickbench_q12 1.00 4.1±0.04ms ? ?/sec 1.01 4.2±0.04ms ? ?/sec
physical_plan_clickbench_q13 1.00 3.7±0.04ms ? ?/sec 1.01 3.7±0.04ms ? ?/sec
physical_plan_clickbench_q14 1.00 4.0±0.05ms ? ?/sec 1.02 4.1±0.05ms ? ?/sec
physical_plan_clickbench_q15 1.00 3.7±0.04ms ? ?/sec 1.01 3.8±0.04ms ? ?/sec
physical_plan_clickbench_q16 1.00 3.6±0.03ms ? ?/sec 1.01 3.6±0.06ms ? ?/sec
physical_plan_clickbench_q17 1.00 3.7±0.06ms ? ?/sec 1.01 3.7±0.05ms ? ?/sec
physical_plan_clickbench_q18 1.00 2.6±0.04ms ? ?/sec 1.00 2.6±0.02ms ? ?/sec
physical_plan_clickbench_q19 1.00 4.1±0.04ms ? ?/sec 1.02 4.1±0.07ms ? ?/sec
physical_plan_clickbench_q2 1.00 2.7±0.01ms ? ?/sec 1.00 2.7±0.03ms ? ?/sec
physical_plan_clickbench_q20 1.00 2.1±0.03ms ? ?/sec 1.02 2.1±0.02ms ? ?/sec
physical_plan_clickbench_q21 1.01 2.7±0.02ms ? ?/sec 1.00 2.7±0.02ms ? ?/sec
physical_plan_clickbench_q22 1.00 3.8±0.05ms ? ?/sec 1.01 3.9±0.02ms ? ?/sec
physical_plan_clickbench_q23 1.00 4.1±0.03ms ? ?/sec 1.01 4.1±0.02ms ? ?/sec
physical_plan_clickbench_q24 1.00 4.8±0.04ms ? ?/sec 1.00 4.8±0.05ms ? ?/sec
physical_plan_clickbench_q25 1.00 3.4±0.04ms ? ?/sec 1.00 3.4±0.01ms ? ?/sec
physical_plan_clickbench_q26 1.00 2.9±0.01ms ? ?/sec 1.00 2.9±0.03ms ? ?/sec
physical_plan_clickbench_q27 1.00 3.5±0.01ms ? ?/sec 1.00 3.4±0.04ms ? ?/sec
physical_plan_clickbench_q28 1.00 4.3±0.06ms ? ?/sec 1.04 4.5±0.13ms ? ?/sec
physical_plan_clickbench_q29 1.00 4.6±0.06ms ? ?/sec 1.03 4.7±0.05ms ? ?/sec
physical_plan_clickbench_q3 1.00 2.5±0.03ms ? ?/sec 1.00 2.5±0.02ms ? ?/sec
physical_plan_clickbench_q30 1.00 16.1±0.23ms ? ?/sec 1.00 16.1±0.18ms ? ?/sec
physical_plan_clickbench_q31 1.00 4.4±0.04ms ? ?/sec 1.01 4.4±0.05ms ? ?/sec
physical_plan_clickbench_q32 1.00 4.3±0.05ms ? ?/sec 1.02 4.4±0.02ms ? ?/sec
physical_plan_clickbench_q33 1.00 3.5±0.04ms ? ?/sec 1.00 3.5±0.02ms ? ?/sec
physical_plan_clickbench_q34 1.00 3.2±0.02ms ? ?/sec 1.01 3.2±0.04ms ? ?/sec
physical_plan_clickbench_q35 1.00 3.3±0.04ms ? ?/sec 1.01 3.3±0.01ms ? ?/sec
physical_plan_clickbench_q36 1.00 4.1±0.04ms ? ?/sec 1.01 4.2±0.04ms ? ?/sec
physical_plan_clickbench_q37 1.00 4.5±0.06ms ? ?/sec 1.02 4.6±0.03ms ? ?/sec
physical_plan_clickbench_q38 1.00 4.6±0.06ms ? ?/sec 1.02 4.6±0.04ms ? ?/sec
physical_plan_clickbench_q39 1.00 4.0±0.08ms ? ?/sec 1.01 4.0±0.03ms ? ?/sec
physical_plan_clickbench_q4 1.01 2.1±0.02ms ? ?/sec 1.00 2.1±0.02ms ? ?/sec
physical_plan_clickbench_q40 1.00 4.6±0.06ms ? ?/sec 1.05 4.9±0.03ms ? ?/sec
physical_plan_clickbench_q41 1.00 4.1±0.05ms ? ?/sec 1.03 4.3±0.06ms ? ?/sec
physical_plan_clickbench_q42 1.00 4.1±0.05ms ? ?/sec 1.03 4.2±0.05ms ? ?/sec
physical_plan_clickbench_q43 1.00 4.3±0.04ms ? ?/sec 1.04 4.5±0.04ms ? ?/sec
physical_plan_clickbench_q44 1.00 2.2±0.02ms ? ?/sec 1.00 2.2±0.02ms ? ?/sec
physical_plan_clickbench_q45 1.00 2.2±0.02ms ? ?/sec 1.00 2.2±0.01ms ? ?/sec
physical_plan_clickbench_q46 1.00 3.1±0.02ms ? ?/sec 1.00 3.1±0.02ms ? ?/sec
physical_plan_clickbench_q47 1.00 4.6±0.05ms ? ?/sec 1.02 4.7±0.03ms ? ?/sec
physical_plan_clickbench_q48 1.00 4.9±0.07ms ? ?/sec 1.03 5.0±0.04ms ? ?/sec
physical_plan_clickbench_q49 1.00 5.2±0.06ms ? ?/sec 1.03 5.3±0.03ms ? ?/sec
physical_plan_clickbench_q5 1.01 2.5±0.04ms ? ?/sec 1.00 2.5±0.02ms ? ?/sec
physical_plan_clickbench_q50 1.00 4.1±0.04ms ? ?/sec 1.01 4.2±0.03ms ? ?/sec
physical_plan_clickbench_q51 1.00 3.5±0.03ms ? ?/sec 1.00 3.5±0.03ms ? ?/sec
physical_plan_clickbench_q6 1.00 2.5±0.03ms ? ?/sec 1.00 2.5±0.04ms ? ?/sec
physical_plan_clickbench_q7 1.01 2.0±0.02ms ? ?/sec 1.00 2.0±0.02ms ? ?/sec
physical_plan_clickbench_q8 1.00 3.3±0.05ms ? ?/sec 1.01 3.4±0.03ms ? ?/sec
physical_plan_clickbench_q9 1.00 3.5±0.02ms ? ?/sec 1.02 3.5±0.03ms ? ?/sec
physical_plan_struct_join_agg_sort 1.00 3.1±0.05ms ? ?/sec 1.06 3.3±0.05ms ? ?/sec
physical_plan_tpcds_all 1.00 1837.0±7.38ms ? ?/sec 1.04 1906.0±7.82ms ? ?/sec
physical_plan_tpch_all 1.00 122.0±1.15ms ? ?/sec 1.03 125.6±0.46ms ? ?/sec
physical_plan_tpch_q1 1.00 2.9±0.05ms ? ?/sec 1.02 3.0±0.03ms ? ?/sec
physical_plan_tpch_q10 1.00 6.9±0.03ms ? ?/sec 1.05 7.2±0.10ms ? ?/sec
physical_plan_tpch_q11 1.00 8.2±0.09ms ? ?/sec 1.03 8.4±0.20ms ? ?/sec
physical_plan_tpch_q12 1.00 3.0±0.01ms ? ?/sec 1.02 3.0±0.03ms ? ?/sec
physical_plan_tpch_q13 1.00 2.9±0.05ms ? ?/sec 1.01 3.0±0.02ms ? ?/sec
physical_plan_tpch_q14 1.00 2.9±0.02ms ? ?/sec 1.04 3.0±0.01ms ? ?/sec
physical_plan_tpch_q16 1.00 5.0±0.01ms ? ?/sec 1.03 5.1±0.05ms ? ?/sec
physical_plan_tpch_q17 1.00 5.4±0.02ms ? ?/sec 1.03 5.5±0.02ms ? ?/sec
physical_plan_tpch_q18 1.00 5.8±0.16ms ? ?/sec 1.01 5.9±0.02ms ? ?/sec
physical_plan_tpch_q19 1.00 5.0±0.02ms ? ?/sec 1.02 5.1±0.03ms ? ?/sec
physical_plan_tpch_q2 1.00 11.8±0.10ms ? ?/sec 1.03 12.2±0.07ms ? ?/sec
physical_plan_tpch_q20 1.00 7.8±0.19ms ? ?/sec 1.01 7.9±0.16ms ? ?/sec
physical_plan_tpch_q21 1.00 9.8±0.13ms ? ?/sec 1.02 10.1±0.04ms ? ?/sec
physical_plan_tpch_q22 1.00 6.3±0.12ms ? ?/sec 1.01 6.4±0.02ms ? ?/sec
physical_plan_tpch_q3 1.00 5.4±0.08ms ? ?/sec 1.02 5.5±0.04ms ? ?/sec
physical_plan_tpch_q4 1.00 2.9±0.01ms ? ?/sec 1.01 2.9±0.01ms ? ?/sec
physical_plan_tpch_q5 1.00 5.7±0.07ms ? ?/sec 1.03 5.9±0.07ms ? ?/sec
physical_plan_tpch_q6 1.00 1556.2±21.01µs ? ?/sec 1.01 1571.4±10.49µs ? ?/sec
physical_plan_tpch_q7 1.00 6.8±0.03ms ? ?/sec 1.04 7.1±0.10ms ? ?/sec
physical_plan_tpch_q8 1.00 8.8±0.05ms ? ?/sec 1.04 9.2±0.11ms ? ?/sec
physical_plan_tpch_q9 1.00 6.3±0.02ms ? ?/sec 1.04 6.5±0.07ms ? ?/sec
physical_select_aggregates_from_200 1.00 17.4±0.08ms ? ?/sec 1.01 17.6±0.09ms ? ?/sec
physical_select_all_from_1000 1.00 23.6±0.07ms ? ?/sec 1.02 24.1±0.09ms ? ?/sec
physical_select_one_from_700 1.00 1308.8±13.26µs ? ?/sec 1.00 1310.6±9.62µs ? ?/sec
physical_sorted_union_order_by_10_int64 1.00 9.7±0.10ms ? ?/sec 1.12 11.0±0.07ms ? ?/sec
physical_sorted_union_order_by_10_uint64 1.00 27.2±0.52ms ? ?/sec 1.09 29.7±0.27ms ? ?/sec
physical_sorted_union_order_by_50_int64 1.00 155.2±1.31ms ? ?/sec 1.27 196.5±0.96ms ? ?/sec
physical_sorted_union_order_by_50_uint64 1.00 951.7±5.01ms ? ?/sec 1.14 1083.7±5.32ms ? ?/sec
physical_theta_join_consider_sort 1.00 2.6±0.03ms ? ?/sec 1.01 2.6±0.04ms ? ?/sec
physical_unnest_to_join 1.00 3.0±0.01ms ? ?/sec 1.01 3.1±0.06ms ? ?/sec
physical_window_function_partition_by_12_on_values 1.00 1238.1±12.35µs ? ?/sec 1.24 1538.9±5.85µs ? ?/sec
physical_window_function_partition_by_30_on_values 1.00 2.1±0.01ms ? ?/sec 1.40 2.9±0.02ms ? ?/sec
physical_window_function_partition_by_4_on_values 1.00 921.6±16.98µs ? ?/sec 1.15 1055.8±9.17µs ? ?/sec
physical_window_function_partition_by_7_on_values 1.00 1030.9±11.51µs ? ?/sec 1.20 1240.5±24.54µs ? ?/sec
physical_window_function_partition_by_8_on_values 1.00 1081.4±8.70µs ? ?/sec 1.21 1305.3±14.53µs ? ?/sec
with_param_values_many_columns 1.00 581.5±4.24µs ? ?/sec 1.01 587.3±4.74µs ? ?/sec

@alamb-ghbot

Copy link
Copy Markdown

🤖 ./gh_compare_branch_bench.shcompare_branch_bench.sh Running
Linux aal-dev 6.17.0-1008-gcp #8~24.04.1-Ubuntu SMP Fri Jan 30 23:44:29 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Comparing askalt/with_new_children_fast_path (bf74d31) to b16ad9bdiff
BENCH_NAME=sql_planner
BENCH_COMMAND=cargo bench --features=parquet --bench sql_planner
BENCH_FILTER=
BENCH_BRANCH_NAME=askalt_with_new_children_fast_path
Results will be posted here when complete

@alamb

Copy link
Copy Markdown
Contributor

(sorry for the benchmark noise -- I had some script issues)

de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
…#19792)
- closesapache#19796
This patch aims to implement a fast-path for the
ExecutionPlan::with_new_children function for some plans, moving closer
to a physical plan re-use implementation and improving planning
performance. If the passed children properties are the same as in self,
we do not actually recompute self's properties (which could be costly if
projection mapping is required). Instead, we just replace the children
and re-use self's properties as-is.
To be able to compare two different properties --
ExecutionPlan::properties(...) signature is modified and now returns
`&Arc<PlanProperties>`. If `children` properties are the same in
`with_new_children` -- we clone our properties arc and then a parent
plan will consider our properties as unchanged, doing the same.
- Return `&Arc<PlanProperties>` from `ExecutionPlan::properties(...)`
instead of a reference.
- Implement `with_new_children` fast-path if there is no children
properties changes for all
major plans.
Note: currently, `reset_plan_states` does not allow to re-use plan in
general: it is not
supported for dynamic filters and recursive queries features, as in this
case state reset
should update pointers in the children plans.
---------
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
pullBot pushed a commit to Stars1233/datafusion that referenced this pull request Jul 10, 2026
…dren_if_necessary (PR 1 of apache#22555) (apache#23332)
## Which issue does this PR close?
Part of apache#22555. This is **PR 1 of 2** — see the issue body for the full
plan. PR 2 will audit direct `with_new_children` callers and add a
clippy lint.
## Rationale for this change
Today the "skip work when children are unchanged" intent is split across
two layers:
- **caller-side** —
[`with_new_children_if_necessary`](https://github.com/apache/datafusion/blob/main/datafusion/physical-plan/src/execution_plan.rs)
short-circuits via `Arc::ptr_eq` on child pointers.
- **callee-side** — the `check_if_same_properties!` macro from apache#19792,
invoked inside each impl's `with_new_children`, short-circuits when
children's `PlanProperties` Arcs match (allowing the plan to reuse its
cached `PlanProperties` Arc instead of recomputing).
Having two independent layers means two places to maintain and two
places for future changes to drift apart. This PR consolidates the
fast-path into the single free-function helper so callers get both
short-circuits uniformly.
## What changes are included in this PR?
`with_new_children_if_necessary` now applies **three layers**, cheapest
first:
1. **Same child pointers** — every `children[i]` is `Arc::ptr_eq` to the
corresponding existing child → return the original plan unchanged, no
allocation.
2. **Same child properties** — children's `PlanProperties` Arcs match →
call the new [`ExecutionPlan::with_new_children_and_same_properties`](#)
trait method to reuse the plan's `PlanProperties` cache without
recomputing.
3. **Full recompute** — otherwise, delegate to
`ExecutionPlan::with_new_children`.
To make layer 2 dispatchable via `&dyn ExecutionPlan`,
`with_new_children_and_same_properties` is promoted from an ad-hoc
inherent method on each impl to a **trait method** with a safe default
that falls back to `with_new_children`. All 22 existing impls migrate
their inherent method to a trait override (mechanical change — signature
`&self → self: Arc<Self>`, return `Self → Result<Arc<dyn
ExecutionPlan>>`, body wrapped in `Ok(Arc::new(...))`).
The `check_if_same_properties!` macro and its call sites inside impls
are **kept**, so direct callers of `with_new_children` (which PR 2 will
audit + migrate) do not regress on this PR.
## Are these changes tested?
Yes — added `test_with_new_children_if_necessary_layers` in
`execution_plan.rs` that constructs test-local `WithChildrenTestLeaf` +
`WithChildrenTestParent` plans (the parent tracks recompute vs fast-path
calls via `AtomicUsize`) and asserts, for each of the three layers:
- **Layer 1**: `Arc::ptr_eq(result, parent)` returns true,
`recompute_calls == 0`, `fast_path_calls == 0`
- **Layer 2**: `Arc::ptr_eq(result.properties(), orig_props)` returns
true, `recompute_calls == 0`, `fast_path_calls == 1`
- **Layer 3**: `Arc::ptr_eq(result.properties(), orig_props)` returns
false, `recompute_calls == 1`, `fast_path_calls` unchanged
All 1523 `datafusion-physical-plan` unit tests pass. Full workspace
`cargo check` + `cargo clippy --all-targets --all-features -- -D
warnings` pass.
## Are there any user-facing changes?
Yes — `ExecutionPlan` gains a new default-implemented trait method
`with_new_children_and_same_properties`. Downstream impls that used to
override the ad-hoc inherent method with the same name will need to
re-implement as a trait override (mechanical signature change). Marking
as `api change`.
## Follow-up (PR 2, not in this PR)
- Audit the ~47 remaining direct callers of
`plan.with_new_children(children)` across the codebase and route them
through `with_new_children_if_necessary`.
- Add a `disallowed_methods` clippy lint (or custom lint) that forbids
direct `ExecutionPlan::with_new_children` outside of a small allow-list.
- Once all callers migrate, remove the `check_if_same_properties!` macro
and its impl-side invocations, making the helper the single source of
truth as described in the issue.
epgif pushed a commit to influxdata/arrow-datafusion that referenced this pull request Aug 14, 2026
UnionExec::try_new recomputes the union schema via union_schema() on
every construction, including with_new_children rebuilds performed by
optimizer passes. For wide unions whose children share one schema
(generated UNION ALL, unions of per-partition scans) this makes
physical planning O(n^2) in child count.
Two fast paths:
- union_schema(): if every input schema is pointer- or content-equal
to the first, return the first schema (merging N identical schemas
is the identity operation).
- UnionExec::with_new_children(): when child count and per-position
child schemas are unchanged, reuse the existing schema. Plan
properties are always recomputed, since they can legitimately change
when schemas do not. (DataFusion 53 has an analogous properties
optimization upstream, apache#19792; this variant targets
the 51 line.)
Adds a union_schema benchmark covering shared-Arc, content-equal, and
adversarial (last child differs) shapes. All existing union unit tests
pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
alamb pushed a commit to influxdata/arrow-datafusion that referenced this pull request Aug 14, 2026
UnionExec::try_new recomputes the union schema via union_schema() on
every construction, including with_new_children rebuilds performed by
optimizer passes. For wide unions whose children share one schema
(generated UNION ALL, unions of per-partition scans) this makes
physical planning O(n^2) in child count.
Two fast paths:
- union_schema(): if every input schema is pointer- or content-equal
to the first, return the first schema (merging N identical schemas
is the identity operation).
- UnionExec::with_new_children(): when child count and per-position
child schemas are unchanged, reuse the existing schema. Plan
properties are always recomputed, since they can legitimately change
when schemas do not. (DataFusion 53 has an analogous properties
optimization upstream, apache#19792; this variant targets
the 51 line.)
Adds a union_schema benchmark covering shared-Arc, content-equal, and
adversarial (last child differs) shapes. All existing union unit tests
pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ryux1 pushed a commit to ryux1/datafusion that referenced this pull request Aug 15, 2026
…n share a schema (apache#24389)
## Which issue does this close?
Complements apache#19792. Fits with the wide-`UnionExec` planning-cost work,
but originates from an InfluxDB issue.
## Rationale for this change
`union_schema` builds the output schema for `UnionExec` and
`InterleaveExec` by coercing field metadata and nullability across
**every** child. That merge is quadratic in the number of children: for
each output field it walks all inputs, and for each input it walks
*every other* input to union field-level metadata. For a union of `n`
children with `f` fields the construction cost is `O(n^2 * f)` (worse
when fields carry metadata).
For narrow unions this is insignificant. It matters when a plan fans a
single source out into many identical-schema children and unions them
back together -- e.g. a union assembled from repartitioned copies of the
same input. An instance like this occurred with InfluxDB: every child
schema was the same, so the merge, guaranteed to reproduce the first
child's schema, unnecessarily incurred the planning latency penalty from
`O(n^2 * f)` complexity.
### Relationship to apache#19792
`UnionExec` construction has two quadratic halves:
- **`with_new_children` / `PlanProperties`** -- addressed by apache#19792
(`with_new_children_and_same_properties`, `Arc<PlanProperties>`, the
properties fast path). Already on `main`.
- **`union_schema`** -- *not* covered by apache#19792 and still quadratic on
`main`.
This PR complements it by making `union_schema` skip the merge when it
can't change the result. It deliberately doesn't touch
`with_new_children`; that path is already handled.
## What changes are included?
A fast path at the top of `union_schema`: after taking
`inputs[0].schema()`, if every remaining child's schema is either the
**same allocation** (`Arc::ptr_eq`) or **structurally equal** (`==`) to
the first, return the first schema immediately. Otherwise we fall
through to the existing full merge, so behavior for genuinely
heterogeneous unions is byte-for-byte unchanged.
```rust
let first_schema = inputs[0].schema();
if inputs[1..].iter().all(|input| {
let schema = input.schema();
Arc::ptr_eq(&schema, &first_schema) || schema == first_schema
}) {
return Ok(first_schema);
}
```
`InterleaveExec` shares `union_schema`, so it gets the same speedup for
free.
## On the cost of the deep compare...
The natural objection (which came up before this PR): **doesn't the deep
`==` make the *unequal* case slower?** I'll paraphrase the prior
conclusions, risking verbosity to avoid rehashing the discussion.
Spoiler: it's not an issue.
- The equal case avoids the merge, and its check is cheap. The
shared-`Arc` case is settled by pointer comparison. The
distinct-but-equal case runs `Schema::eq`, which is allocation-free and
short-circuits on the first difference. Benchmarks show a small loss
versus a pointer-equality-only control (the theoretical floor) but it
still beats the full merge by a wide margin, and that advantage grows
with schema complexity.
- The adversarial worst case is bounded. The one shape where the scan is
pure overhead is `last_differs`: children `0..n-1` are equal and the
last diverges, so we scan `n` schemas, fail on the last, then merge
anyway. That's a single linear `==` pass bounded by the merge that
follows -- a constant fraction, not another factor of `n` -- and it
takes *thousands* of near-identical children differing only in the last
to hit.
- Ordinary unequal unions fail fast. `SELECT a ... UNION ALL SELECT b
...` differs at field 0, so `==` rejects on the first field (see
`names_differ`). And `UnionExec::try_new` already rejects misaligned
children, so the only divergence `union_schema` ever sees is top-level
(caught in the first pass).
## Benchmark results
New bench `datafusion/physical-plan/benches/union_schema.rs` measures
`UnionExec::try_new` construction over a flat schema and a nested/struct
schema, for the four child shapes above. Run interleaved (baseline /
patched alternated per cell) on a fixed-clock T2D VM.
### `union_schema` construction (lower is better)
| scenario | n | baseline (ms) | patched (ms) | change |
|---|---|---|---|---|
| union_exec_try_new/shared_arc | 100 | 0.263 | 0.042 | 6.2× |
| union_exec_try_new/shared_arc | 1000 | 2.60 | 0.429 | 6.1× |
| union_exec_try_new/shared_arc | 4000 | 10.5 | 1.74 | 6.0× |
| union_exec_try_new/content_equal | 100 | 0.262 | 0.042 | 6.2× |
| union_exec_try_new/content_equal | 1000 | 2.61 | 0.433 | 6.0× |
| union_exec_try_new/content_equal | 4000 | 10.5 | 1.74 | 6.0× |
| union_exec_try_new/last_differs | 4000 | ~98 | ~97 | flat (±1.5%) |
| union_exec_try_new/names_differ | 4000 | ~87 | ~87 | flat (±1%) |
| union_exec_try_new_nested/content_equal | 1000 | 2.68 | 0.431 | 6.2× |
| union_exec_try_new_nested/content_equal | 4000 | 10.8 | 1.73 | 6.2× |
The `last_differs` (adversarial: N-1 children equal, deep compare then
full merge) and `names_differ` (typical unequal: fails on the first
field) cells were re-measured with tight per-cell interleaving
(baseline/patched adjacent, 4 rounds) to control for variance: both are
within ±1.5%, straddling zero. Interpretation: the **deep compare cost
isn't observable end to end**.
### End-to-end planning: no regression (`sql_planner`)
`cargo bench --bench sql_planner` (TPC-H + ClickBench) run baseline vs
patched on the fixed-clock T2D VM. Every case lands within ±1% --
run-to-run noise -- with no case regressing beyond that noise. Notable
rows, including the union-heavy `sorted_union` cases the fast path is
meant to help:
| case | baseline (ms) | patched (ms) |
|---|---|---|
| physical_plan_tpcds_all | 995.9 ± 1.4 | 991.9 ± 1.9 |
| physical_plan_tpch_all | 60.4 ± 0.2 | 60.3 ± 0.1 |
| physical_sorted_union_order_by_50 | 349.9 ± 2.4 | 346.3 ± 2.7 |
| physical_sorted_union_order_by_10 | 12.3 ± 0.03 | 12.2 ± 0.07 |
| physical_select_all_from_1000 | 30.8 ± 0.25 | 30.7 ± 0.08 |
The full TPC-H q1-q22 and ClickBench sets are all flat (ratio is
1.00-1.01 in both directions). Separately, interleaving tests per-cell
(baseline and patched back-to-back, so run-to-run variance -- e.g.
thermal -- cancels rather than favoring one) for
`physical_join_distinct` + eight ClickBench queries (4 rounds) confirmed
the same thing: patched and baseline straddle zero; no systematic
regression from the deep compare.
## Testing
- `cargo test -p datafusion-physical-plan --lib union` -- all pass,
including a new `test_union_schema_fast_path_content_equal` that
exercises the `==` branch with pointer-distinct-but-equal schemas and
asserts the result matches the shared schema (i.e. identical to the
slow-path merge).
- `cargo clippy -p datafusion-physical-plan --lib -- -D warnings` --
clean.
- `cargo bench --bench union_schema` -- compiles and runs.
## Are there any user-facing changes?
No: planning-time performance change only, results and schema are
identical.
---------
Signed-off-by: Reid Kaufmann <reid.kaufmann@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changeChanges the API exposed to users of the cratecatalogRelated to the catalog cratecoreCore DataFusion cratedatasourceChanges to the datasource cratedocumentationImprovements or additions to documentationffiChanges to the ffi crateoptimizerOptimizer rulesperformanceMake DataFusion fasterphysical-exprChanges to the physical-expr cratesphysical-planChanges to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid recomputing PlanProperties redundently

4 participants

@askalt@alamb@alamb-ghbot@Omega359