Acfboy opened a new pull request, #20545:
URL: https://github.com/apache/datafusion/pull/20545
## 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 #18816 .
## 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.
-->
In `UserDefinedLogicalNodeCore`, the default implementation of
`necessary_children_exprs ` returns `None`, which signals to the optimizer that
it cannot determine which columns are required from the child.
The optimizer takes a conservative approach and skips projection pruning for
that node, leading to complex and redundant plans in the subtree. However, it
would make more sense to assume all columns are required and let the optimizer
proceed, rather than giving up on the entire subtree entirely.
## What changes are included in this PR?
```rust
LogicalPlan::Extension(extension) => {
if let Some(necessary_children_indices) =
extension.node.necessary_children_exprs(indices.indices())
{
...
} else {
// Requirements from parent cannot be routed down to user defined
logical plan safely
// Assume it requires all input exprs here
plan.inputs()
.into_iter()
.map(RequiredIndices::new_for_all_exprs)
.collect()
}
}
```
instead of
https://github.com/apache/datafusion/blob/b6d46a63824f003117297848d8d83b659ac2e759/datafusion/optimizer/src/optimize_projections/mod.rs#L331-L337
<!--
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.
-->
## Are these changes tested?
Yes.
In addition to unit tests, I've also added a complete end-to-end integration
test that reproduces the full scenario in the issue. This might seem redundant,
bloated, or even unnecessary. Please let me know if I should remove these tests.
<!--
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)?
-->
## Are there any user-facing changes?
Yes. But I think the new implementation is the expected behavior.
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
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: [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]