-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve get_meet_of_orderings
to check for common prefixes
#5111
Conversation
LGTM |
In case the |
Should move the calculation logic to the Or here I think we do not need to call fn maintains_input_order(&self) -> Vec<bool> {
// If the Union has an output ordering, it maintains at least one
// child's ordering (i.e. the meet).
// For instance, assume that the first child is SortExpr('a','b','c'),
// the second child is SortExpr('a','b') and the third child is
// SortExpr('a','b'). The output ordering would be SortExpr('a','b'),
// which is the "meet" of all input orderings. In this example, this
// function will return vec![false, true, true], indicating that we
// preserve the orderings for the 2nd and the 3rd children.
self.inputs()
.iter()
.map(|child| {
ordering_satisfy(self.output_ordering(), child.output_ordering(), || {
child.equivalence_properties()
})
})
.collect()
} |
You mean something like this? fn maintains_input_order(&self) -> Vec<bool> {
// ... comment text ...
if let Some(output_ordering) = self.output_ordering() {
self.inputs()
.iter()
.map(|child| {
if let Some(child_ordering) = child.output_ordering() {
output_ordering.len() == child_ordering.len()
} else {
false
}
})
.collect()
} else {
vec![false; self.inputs().len()]
}
} |
Yes. |
Done, thanks for taking a closer look.
@mustafasrepo will take over and think about this in a follow-on PR. |
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.
Thank you @ozankabak
}, | ||
]; | ||
|
||
let expected = vec![PhysicalSortExpr { |
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.
👍
]; | ||
|
||
let result = get_meet_of_orderings_helper(vec![&input1, &input2, &input3]); | ||
assert!(result.is_none()); |
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.
👍
]; | ||
|
||
let result = get_meet_of_orderings_helper(vec![&input1, &input2, &input3]); | ||
assert_eq!(result.unwrap(), input1); |
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.
👍
self.inputs() | ||
.iter() | ||
.map(|child| { | ||
if let Some(child_ordering) = child.output_ordering() { |
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 don't understand why we no longer need to check that the output order of the child is compatible with the output order of the input. Shouldn't this be calling get_meet_of_orderings
to check rather than checking the length?
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.
The call self.output_ordering()
in turn calls get_meet_of_orderings
and computes the common longest prefix. We then check whether any of the inputs are equal to that prefix (equality in length implies equality in this case). Note that we are checking for strict equality instead of an equivalence-aware check following @mingmwang's suggestion.
Thanks @ozankabak -- makes sense to me |
Benchmark runs are scheduled for baseline = 125a858 and contender = 1f7885b. 1f7885b is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
This PR addresses a concern raised by @mingmwang in his review of #5035.
Rationale for this change
As discussed here, we want to get the longest common prefix when finding the meet of the given orderings. If we don't do that, we may lose some coarse ordering information.
What changes are included in this PR?
This PR changes the internal logic of the
get_meet_of_orderings
function to add the desired functionality.Are these changes tested?
New unit tests are added to verify the correct behavior in three relevant test cases.
Are there any user-facing changes?
No.