Commit d648982
authored
Skip unnecessary plan rebuild in adjust_input_keys_ordering for non-join plans (apache#21947)
## Which issue does this PR close?
Closes apache#21946
## Rationale for this change
`adjust_input_keys_ordering` returns `Transformed::yes` unconditionally
in the default else branch, even when `requirements.data` is empty and
no changes were made. This triggers unnecessary `with_new_children`
rebuilds on every node in the plan tree for non-join/non-aggregate
queries.
For plans with custom `ExecutionPlan` nodes whose `with_new_children` is
expensive (e.g. nodes that re-evaluate cost functions on rebuild), this
causes significant overhead.
## What changes are included in this PR?
Add an early return with `Transformed::no` when
`requirements.data.is_empty()` in the default else branch of
`adjust_input_keys_ordering`. This skips the unnecessary plan tree
rebuild for simple scan/filter/limit plans that have no join key
reordering requirements.
## Are these changes tested?
Yes, two unit tests added:
- `adjust_input_keys_ordering_no_transform_for_scan` — verifies a bare
parquet scan returns `Transformed::no`
- `adjust_input_keys_ordering_no_transform_for_filter_scan` — verifies a
filter→scan tree returns `Transformed::no` via `transform_down`
## Are there any user-facing changes?
No. This is a performance optimization that does not change query
results or plan structure.1 parent c2824b5 commit d648982
2 files changed
Lines changed: 33 additions & 0 deletions
File tree
- datafusion
- core/tests/physical_optimizer
- physical-optimizer/src
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3978 | 3978 | | |
3979 | 3979 | | |
3980 | 3980 | | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
415 | 418 | | |
416 | 419 | | |
417 | 420 | | |
| |||
0 commit comments