zhuqi-lucas opened a new issue, #21946: URL: https://github.com/apache/datafusion/issues/21946
## Describe the bug `adjust_input_keys_ordering` in `EnforceDistribution` returns `Transformed::yes` unconditionally in the default else branch (line 421), 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. ## To Reproduce Any query without joins or aggregates (e.g. a simple `SELECT * FROM table WHERE ... ORDER BY ... LIMIT N`) will have every node in the tree rebuilt during `adjust_input_keys_ordering`, even though no key reordering is needed. ## Expected behavior When `requirements.data` is empty (no parent key ordering to push down) and the plan node is not a join/aggregate/projection/repartition/window, `adjust_input_keys_ordering` should return `Transformed::no` to skip the rebuild. ## Impact 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. CPU profiling showed this contributes to unnecessary work in the physical optimizer chain. ## Proposed fix Add an early return with `Transformed::no` when `requirements.data.is_empty()` in the default else branch of `adjust_input_keys_ordering`. Will submit a PR. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
