Repository navigation
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
a + b = a#26623.Rationale for this change
A sort-merge join on
(a, b)fails withSanityCheckPlanwhen a filter below it equates an expression with one of its own sub-expressions, such asx.a + x.b = x.a.The filter puts
a + bandain one equivalence class, witha + bas the canonical expression because it comes first.normalize_exprrewrites bottom-up, so it replaces theainsidea + bwitha + band turnsa + binto(a + b) + b. The join requires[a, b], which normalizes to[a + b, b], while the sort below it is on[a + b, b], which normalizes to[(a + b) + b, b], so the sort no longer satisfies the join. Written asx.a = x.a + x.b, the query works, becauseais the canonical expression.What changes are included in this PR?
When
EquivalenceGroup::add_equal_conditionsadds to a class, a member that is a sub-expression of the canonical expression now becomes the canonical expression.normalize_expris unchanged, so classes without such a pair normalize as before.What is the testing strategy for this PR?
The query from the issue is added to
sort_merge_join.slt. It fails without the fix.equivalence_properties.sltgets a plan thatmainalready gets right and that a fix innormalize_expritself would break: witha = b AND c = a + 1aboveORDER BY a + 1 LIMIT 100, the outerORDER BY a + 1needs no sort.It also gets a query with two
INlists that hold the same values in a different order. They compare equal but hash differently, so both stay in the class, and the promotion must still stop.Are there any user-facing changes?
No API changes. Queries like the one in the issue now plan instead of failing in
SanityCheckPlan.