-
-
Notifications
You must be signed in to change notification settings - Fork 234
drop sorts in cross joins and inner joins #3117
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
sql/analyzer/replace_sort.go
Outdated
if errRight != nil { | ||
return nil, transform.SameTree, errRight | ||
} | ||
// Nothing replaced, so nothing to do |
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.
Can we use a more specific comment, like "Neither child was converted to an IndexedTableAccess, so we can't remove the sort node"?
sql/analyzer/replace_sort.go
Outdated
return nil, transform.SameTree, errRight | ||
} | ||
// Nothing replaced, so nothing to do | ||
if sameLeft && sameRight { |
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 have an idea that might improve readability. What if we wrote:
leftIsSorted := !sameLeft
rightIsSorted := !sameRight
And then wrote the conditionals in terms of these? It might make it more clear what each of these branches means.
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.
That makes sense; I'll change the variable names
sql/analyzer/replace_sort.go
Outdated
if c.JoinType().IsCross() || c.JoinType().IsInner() { | ||
// For cross joins and inner joins, if the right child is sorted, we need to swap | ||
if !sameRight { | ||
// Rule eraseProjection will drop any Projections that are now unnecessary. |
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.
Why are these comments added here, in the part where we swap the left and right nodes?
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.
Swapping left and right nodes opens up the opportunity for projections to be dropped and messes up the GetField indexes. These comments are just saying that both those things are handled later on in analysis.
It may also come in handy if we ever change the order of those rules
This PR applies the sort removal optimizations over cross and inner joins.