-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: rewrite subquery into dependent join logical plan #16016
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
base: main
Are you sure you want to change the base?
feat: rewrite subquery into dependent join logical plan #16016
Conversation
FYI @irenjj |
support sort support agg dummy unnest update test
// column | ||
let alias = match e { | ||
Expr::InSubquery(_) | Expr::Exists(_) | Expr::ScalarSubquery(_) => { | ||
subquery_alias_by_offset.get(offset_ref).unwrap() |
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.
nit: unwrap() is not allowed
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.
resolved, convert into error in case of unwrap fail
fn rewrite_projection( | ||
&mut self, | ||
original_proj: &Projection, | ||
dependent_join_node: &Node, | ||
current_subquery_depth: usize, | ||
mut current_plan: LogicalPlanBuilder, | ||
subquery_alias_by_offset: HashMap<usize, String>, | ||
) -> Result<LogicalPlanBuilder> { | ||
// everytime we meet a subquery during traversal, we increment this by 1 | ||
// we can use this offset to lookup the original subquery info | ||
// in subquery_alias_by_offset | ||
// the reason why we cannot create a hashmap keyed by Subquery object HashMap<Subquery,String> |
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 the shared parts among rewrite_* functions can be extracted
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.
refactored, so far i can see filter, projection and agg can be rewritten using one shared function
fix subquery in join filter
…query-in-join-filter chore: more constraint on correlated subquery in join filter
Which issue does this PR close?
This PR is a part of a long story for a general purpose subquery decorrelation, after some discussion in #5492, this PR proposes adding the followings:
To avoid breaking existing tests and smoother collaboration, the changes should happen in the following sequence
1. Merge item 1 without integrate the new optimizor to the main flow (behavior is tested in-code instead of sqllogictests)
2. Start implement more rewriting rules for different query plan (aggregate, projection, filter ...) using the a new optimizer
We keep the working of this new optimizor in a working branch, and if the implementation can fully support existing subqueries,
we make the following change to the main branch
From
Into
Or we can even combine the 2 optimizors into one, into
The following works are needed after merging this PR
Rationale for this change
Are these changes tested?
Are there any user-facing changes?