Improve get_meet_of_orderings to check for common prefixes#5111
Improve get_meet_of_orderings to check for common prefixes#5111alamb merged 2 commits intoapache:masterfrom synnada-ai:get_meet_bugfix
get_meet_of_orderings to check for common prefixes#5111Conversation
|
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. |
| }, | ||
| ]; | ||
|
|
||
| let expected = vec![PhysicalSortExpr { |
| ]; | ||
|
|
||
| let result = get_meet_of_orderings_helper(vec![&input1, &input2, &input3]); | ||
| assert!(result.is_none()); |
| ]; | ||
|
|
||
| let result = get_meet_of_orderings_helper(vec![&input1, &input2, &input3]); | ||
| assert_eq!(result.unwrap(), input1); |
| self.inputs() | ||
| .iter() | ||
| .map(|child| { | ||
| if let Some(child_ordering) = child.output_ordering() { |
There was a problem hiding this comment.
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.
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_orderingsfunction 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.