Skip to content

Commit 5f31505

Browse files
authored
Make between matching a Binary AND simplify rule (#10505)
`find_between` ran once at the top of `optimize_recursive`, flattening the whole predicate into conjuncts and rebuilding it as a balanced CNF even when there was nothing to merge, and it never reached ANDs nested under other nodes such as OR. Move it into `Binary::simplify` for `AND`. Because the optimizer simplifies children before parents, each AND node only needs to pair range comparisons that straddle it: pairs inside one side were already handled when that side's AND was simplified. The search walks the conjuncts by reference and allocates nothing unless it finds a pair, and a match rewrites only the path to the merged conjuncts, so the rest of the tree keeps its shape.
1 parent 00250fd commit 5f31505

6 files changed

Lines changed: 366 additions & 348 deletions

File tree

‎vortex-array/src/expr/optimize.rs‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use vortex_error::VortexResult;
55

66
use crate::expr::BoundExpression;
7-
use crate::expr::transform::match_between::find_between;
87
use crate::scalar_fn::ExpressionReduceNode;
98

109
impl BoundExpression {
@@ -92,15 +91,6 @@ impl BoundExpression {
9291

9392
/// Try to optimize the entire expression tree recursively.
9493
pub fn try_optimize_recursive(&self) -> VortexResult<Option<BoundExpression>> {
95-
let result = self.try_optimize_recursive_inner()?;
96-
97-
// Apply the between optimization once at the top level only.
98-
// TODO(ngates): remove the "between" optimization, or rewrite it to not always convert
99-
// to CNF?
100-
Ok(Some(find_between(result.unwrap_or_else(|| self.clone()))))
101-
}
102-
103-
fn try_optimize_recursive_inner(&self) -> VortexResult<Option<BoundExpression>> {
10494
// First optimize the root
10595
let mut current = self.try_optimize()?;
10696

@@ -110,7 +100,7 @@ impl BoundExpression {
110100
let children = expr.children();
111101
let mut new_children: Option<Vec<BoundExpression>> = None;
112102
for (idx, child) in children.iter().enumerate() {
113-
if let Some(optimized) = child.try_optimize_recursive_inner()? {
103+
if let Some(optimized) = child.try_optimize_recursive()? {
114104
new_children
115105
.get_or_insert_with(|| children[..idx].to_vec())
116106
.push(optimized);

0 commit comments

Comments
 (0)