-
Notifications
You must be signed in to change notification settings - Fork 1.5k
support simple/cross lateral joins #16015
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
Conversation
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
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.
Thanks @jayzhan211 imho it is lgtm, please check some nits though
4 4 1 | ||
|
||
query IIII | ||
SELECT * FROM t0, LATERAL (SELECT * FROM t1 WHERE t1.v0 = 1); |
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.
should we also check the join syntax?
SELECT * FROM t0 JOIN LATERAL (SELECT * FROM t1 WHERE t1.v0 = 1) on true;
?
@@ -313,6 +317,11 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr { | |||
missing_exprs.push(un_matched_row); | |||
} | |||
} | |||
if aggregate.group_expr.is_empty() { | |||
// TODO: how do we handle the case where we have pulled multiple aggregations? For example, |
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.
prob we can create a ticket for that?
} | ||
|
||
match join.right.apply_with_subqueries(|p| { | ||
if p.contains_outer_reference() { |
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.
perhaps we can add a comment why queries with outer reference won't be optimized? 🤔
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.
not yet supported feature
return Ok(Transformed::no(LogicalPlan::Join(join))); | ||
} | ||
let subquery_plan = subquery.subquery.as_ref(); | ||
let mut pull_up = PullUpCorrelatedExpr::new().with_need_handle_count_bug(true); |
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.
now I'm thinking of having this .with_need_handle_count_bug
to move it to unsafe
or something to let users know immediately the risks?
FYI @Lordworms I am not sure if this is related to some of your other work |
I am doing a DelimJoin way (duckdb style) to support non-euqual lateral join like
and
which may got some overlap with this pr since I have to identify the join condition as well |
@irenjj perhaps you can review this PR as well as i cross / lateral joins are related to subqueries I think |
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.
Maybe eventually it would be nice to add / adapt the tests from duckdb and make sure we get the same answers: https://github.com/duckdb/duckdb/tree/main/test/sql/subquery/lateral
🤖 |
pub mod decorrelate; | ||
pub mod decorrelate_lateral_join; | ||
pub mod decorrelate_predicate_subquery; |
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 would be really nice to figure out how to combine these passes into one unified set of decorrelation code -- now we have three passes
FYI @irenjj
I am sorry I don't have the capacity to study LATERAL joins in detail to really review the code carefully. If you are happy with I think we should merge it. I suspect we'll have to add more general code eventually but augmenting our test cases / features along the way seems good to me |
🤖: Benchmark completed Details
|
TODOs:
|
* support simple lateral joins Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * fix explain test Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * plan scalar agg correctly Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * add uncorrelated query tests Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * fix clippy + fmt Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * make rule matching faster Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * revert build_join visibility Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * revert find plan outer column changes Signed-off-by: Alex Chi Z <iskyzh@gmail.com> * remove clone * address comment --------- Signed-off-by: Alex Chi Z <iskyzh@gmail.com> Co-authored-by: Alex Chi Z <iskyzh@gmail.com>
Which issue does this PR close?
address comment from #14595 to get this in.
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?