-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Resolve empty relation opt for join types #11066
Resolve empty relation opt for join types #11066
Conversation
Merge branch 'main' into fill-out-empty-relation-opt-for-rest-join-types
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 @LorrensP-2158466
@@ -142,13 +146,19 @@ impl OptimizerRule for PropagateEmptyRelation { | |||
schema: join.schema.clone(), | |||
}), | |||
)), | |||
JoinType::LeftAnti if right_empty => { |
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 double checked that an ANTI join (e.g. a NOT IN
) is true when there are no tuples (aka the right side is emprt)
postgres=# select * from foo;
x
-----
1
2
NaN
(3 rows)
postgres=# select * from bar;
y
---
(0 rows)
postgres=# select x NOT IN (SELECT y from bar) from foo;
?column?
----------
t
t
t
(3 rows)
postgres=# select x from foo where NOT EXISTS (SELECT y from bar);
x
-----
1
2
NaN
(3 rows)
Thus I think this is a valid rewrite
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.
Nice, thanks for the double check!
JoinType::RightAnti if right_empty => Ok(Transformed::yes( | ||
LogicalPlan::EmptyRelation(EmptyRelation { | ||
produce_one_row: false, | ||
schema: join.schema.clone(), | ||
}), | ||
)), | ||
_ => Ok(Transformed::no(LogicalPlan::Join(join.clone()))), | ||
_ => Ok(Transformed::no(plan)), |
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.
👍
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.
Looks good to me! Thanks @LorrensP-2158466
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.
Nothing to add over what's been said... LGTM!
Co-authored-by: Jonah Gao <jonahgao@msn.com>
…n-opt-for-join-types
…n-opt-for-join-types
I merged this PR up from main and plan to merge it when CI passes |
Merged. Thanks @LorrensP-2158466 @alamb @tshauck |
* handle left/right anti with empty join_table & added tests for those * add tests and only resolve cases 1,2,3 of issue * forgot to change a test * Update datafusion/optimizer/src/propagate_empty_relation.rs Co-authored-by: Jonah Gao <jonahgao@msn.com> --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> Co-authored-by: Jonah Gao <jonahgao@msn.com>
Which issue does this PR close?
Almost closes #10967:
Rationale for this change
Currently the PropagateEmptyRelation relation doesn't optimize all join types
This PR closes following cases
What changes are included in this PR?
Added match statements that resolve the above cases.
Are these changes tested?
Yes these changes are tested with unit tests and 3 added slt tests.
Are there any user-facing changes?
No