-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: optimise outer joins #16004
Closed
Closed
feat: optimise outer joins #16004
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Allows for pushing projection and LIMIT to the RHS of ApplyJoins Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
vitess-bot
bot
added
NeedsBackportReason
If backport labels have been applied to a PR, a justification is required
NeedsDescriptionUpdate
The description is not clear or comprehensive enough, and needs work
NeedsIssue
A linked issue is missing for this Pull Request
NeedsWebsiteDocsUpdate
What it says
labels
May 23, 2024
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
systay
removed
NeedsDescriptionUpdate
The description is not clear or comprehensive enough, and needs work
NeedsWebsiteDocsUpdate
What it says
labels
May 23, 2024
systay
added
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Component: Query Serving
and removed
NeedsIssue
A linked issue is missing for this Pull Request
NeedsBackportReason
If backport labels have been applied to a PR, a justification is required
labels
May 23, 2024
systay
requested review from
harshit-gangal,
frouioui,
GuptaManan100 and
arthurschreiber
as code owners
May 23, 2024 16:36
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Component: Query Serving
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces enhancements to the query planner, enabling the push down of
LIMIT
clauses to the right-hand side (RHS) of joins, including outer joins, when the expressions permit. Additionally, logic has been added to push downLIMIT
under routes when applicable.These changes aim to optimize query efficiency and resource utilization, ensuring faster query processing and lower overhead in the presence of outer joins.
For inner joins, we can't push down
LIMIT
on the left-hand side (LHS) of our nested loop joins (ApplyJoin). For a join to produce a row, we need a match on both sides, and we don't know how many rows we need from the LHS for the join to produce sufficient rows to satisfy the user-setLIMIT
. The best we can do is push aLIMIT
on the RHS and then alsoLIMIT
on top of the join.On the other hand, for left outer joins, we know that every row from the LHS will be returned from the join. This means we can push down the
LIMIT
to the LHS of the join. This is really good and important - we want to run the RHS of the join as few times as possible.Example
The first, unoptimized version of the query with the
LIMIT
looks like this:Now we rewrite by doing iterative tree rewrites until we reach a fixed point. It will look something like this:
Here are the reasons for the different
LIMIT
operations:LIMIT
. It ensures that the final results do not contain more than 10 rows.LIMIT
on top of the LHS of the JOIN.LIMIT
under the route. 🎉LIMIT
on top of the Route to minimize the number of rows processed by the join.Related Issue(s)
Fixes #15828
Checklist