-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fixed PushDownFilter bug [15047] #15142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed PushDownFilter bug [15047] #15142
Conversation
…revent this specific situation
| // This prevents the Filter from being removed when the extension node has no children, | ||
| // so we return the original Filter unchanged. | ||
| LogicalPlan::Extension(extension_plan) | ||
| if extension_plan.node.inputs().is_empty() => | ||
| { | ||
| filter.input = Arc::new(LogicalPlan::Extension(extension_plan)); | ||
| Ok(Transformed::no(LogicalPlan::Filter(filter))) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding the part to the branch of LogicalPlan::Extension, so we don't need to add a such new branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can absolutely do that. I will do it later today. Thank you very much for your review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved logic into the branch of LogicalPlan::Extension, thanks!
|
FYI @helgikrs -- can you also help review this PR? |
| let plan_schema = Arc::clone(plan.schema()); | ||
|
|
||
| let LogicalPlan::Filter(mut filter) = plan else { | ||
| let LogicalPlan::Filter(mut filter) = plan.clone() else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this clone is necessary--is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary, I've removed it and committed to the new version. Thanks for your review!
| } | ||
|
|
||
| #[test] | ||
| fn test_push_down_filter_to_user_defined_node_2() -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this test is identical to the test_push_down_filter_to_user_defined_node test except for the comments. Consider removing one of them, or consolidating the common logic to remove the duplication if they are supposed to test different things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thank you very much for your review! I've removed the second test in the latest commit.
helgikrs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM -- thanks
xudong963
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
…revent this specific situation
Which issue does this PR close?
Rationale for this change
This PR fixes a bug in PushDownFilter where a Filter node is incorrectly removed when its child is an extension node with no inputs (e.g., Filter: false -> TestNode becomes TestNode). This change ensures the Filter is preserved in such cases to maintain the intended query logic.
What changes are included in this PR?
Modified the rewrite method in PushDownFilter to add a specific check for LogicalPlan::Extension nodes with no children.
When an extension node has no inputs, the Filter is kept by resetting its input and returning it unchanged using Transformed::no.
Are these changes tested?
Yes, the changes are tested with an updated unit test test_push_down_filter_to_user_defined_node that:
Creates a TestUserNode (an extension node with no inputs).
Applies a Filter with a constant expression (false).
Verifies the optimized plan retains the Filter instead of removing it.
Are there any user-facing changes?
No, this is an internal optimization fix and does not alter the public API or user-facing behavior. It only ensures correct query execution for plans involving extension nodes with no children.