Skip to content

Commit 33d1a65

Browse files
alamberratic-pattern
authored andcommitted
chore: skip order calculation / exponential planning
1 parent 31a942f commit 33d1a65

File tree

1 file changed

+36
-4
lines changed
  • datafusion/physical-expr/src/equivalence/properties

1 file changed

+36
-4
lines changed

datafusion/physical-expr/src/equivalence/properties/union.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,43 @@ fn calculate_union_binary(
6767
})
6868
.collect::<Vec<_>>();
6969

70+
// TEMP HACK WORKAROUND
71+
// Revert code from https://github.com/apache/datafusion/pull/12562
72+
// Context: https://github.com/apache/datafusion/issues/13748
73+
// Context: https://github.com/influxdata/influxdb_iox/issues/13038
74+
7075
// Next, calculate valid orderings for the union by searching for prefixes
7176
// in both sides.
72-
let mut orderings = UnionEquivalentOrderingBuilder::new();
73-
orderings.add_satisfied_orderings(&lhs, &rhs)?;
74-
orderings.add_satisfied_orderings(&rhs, &lhs)?;
75-
let orderings = orderings.build();
77+
let mut orderings = vec![];
78+
for ordering in lhs.normalized_oeq_class().into_iter() {
79+
let mut ordering: Vec<PhysicalSortExpr> = ordering.into();
80+
81+
// Progressively shorten the ordering to search for a satisfied prefix:
82+
while !rhs.ordering_satisfy(ordering.clone())? {
83+
ordering.pop();
84+
}
85+
// There is a non-trivial satisfied prefix, add it as a valid ordering:
86+
if !ordering.is_empty() {
87+
orderings.push(ordering);
88+
}
89+
}
7690

91+
for ordering in rhs.normalized_oeq_class().into_iter() {
92+
let mut ordering: Vec<PhysicalSortExpr> = ordering.into();
93+
94+
// Progressively shorten the ordering to search for a satisfied prefix:
95+
while !lhs.ordering_satisfy(ordering.clone())? {
96+
ordering.pop();
97+
}
98+
// There is a non-trivial satisfied prefix, add it as a valid ordering:
99+
if !ordering.is_empty() {
100+
orderings.push(ordering);
101+
}
102+
}
77103
let mut eq_properties = EquivalenceProperties::new(lhs.schema);
78104
eq_properties.add_constants(constants)?;
79105
eq_properties.add_orderings(orderings);
106+
80107
Ok(eq_properties)
81108
}
82109

@@ -122,6 +149,7 @@ struct UnionEquivalentOrderingBuilder {
122149
orderings: Vec<LexOrdering>,
123150
}
124151

152+
#[expect(unused)]
125153
impl UnionEquivalentOrderingBuilder {
126154
fn new() -> Self {
127155
Self { orderings: vec![] }
@@ -504,6 +532,7 @@ mod tests {
504532
}
505533

506534
#[test]
535+
#[ignore = "InfluxData patch: chore: skip order calculation / exponential planning"]
507536
fn test_union_equivalence_properties_constants_fill_gaps() -> Result<()> {
508537
let schema = create_test_schema().unwrap();
509538
UnionEquivalenceTest::new(&schema)
@@ -579,6 +608,7 @@ mod tests {
579608
}
580609

581610
#[test]
611+
#[ignore = "InfluxData patch: chore: skip order calculation / exponential planning"]
582612
fn test_union_equivalence_properties_constants_fill_gaps_non_symmetric() -> Result<()>
583613
{
584614
let schema = create_test_schema().unwrap();
@@ -607,6 +637,7 @@ mod tests {
607637
}
608638

609639
#[test]
640+
#[ignore = "InfluxData patch: chore: skip order calculation / exponential planning"]
610641
fn test_union_equivalence_properties_constants_gap_fill_symmetric() -> Result<()> {
611642
let schema = create_test_schema().unwrap();
612643
UnionEquivalenceTest::new(&schema)
@@ -658,6 +689,7 @@ mod tests {
658689
}
659690

660691
#[test]
692+
#[ignore = "InfluxData patch: chore: skip order calculation / exponential planning"]
661693
fn test_union_equivalence_properties_constants_middle_desc() -> Result<()> {
662694
let schema = create_test_schema().unwrap();
663695
UnionEquivalenceTest::new(&schema)

0 commit comments

Comments
 (0)