MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / visit_expr_mut_internal

Method visit_expr_mut_internal

src/sql/src/plan/transform_ast.rs:596–871  ·  view source on GitHub ↗
(&mut self, expr: &mut Expr<Aug>)

Source from the content-addressed store, hash-verified

594 }
595
596 fn visit_expr_mut_internal(&mut self, expr: &mut Expr<Aug>) -> Result<(), PlanError> {
597 // `($expr)` => `$expr`
598 while let Expr::Nested(e) = expr {
599 *expr = e.take();
600 }
601
602 // `$expr BETWEEN $low AND $high` => `$expr >= $low AND $expr <= $low`
603 // `$expr NOT BETWEEN $low AND $high` => `$expr < $low OR $expr > $low`
604 if let Expr::Between {
605 expr: e,
606 low,
607 high,
608 negated,
609 } = expr
610 {
611 if *negated {
612 *expr = Expr::lt(*e.clone(), low.take()).or(e.take().gt(high.take()));
613 } else {
614 *expr = e.clone().gt_eq(low.take()).and(e.take().lt_eq(high.take()));
615 }
616 }
617
618 // When `$expr` is a `ROW` constructor, we need to desugar as described
619 // below in order to enable the row comparision expansion at the end of
620 // this function. We don't do this desugaring unconditionally (i.e.,
621 // when `$expr` is not a `ROW` constructor) because the implementation
622 // in `plan_in_list` is more efficient when row comparison expansion is
623 // not required.
624 //
625 // `$expr IN ($list)` => `$expr = $list[0] OR $expr = $list[1] ... OR $expr = $list[n]`
626 // `$expr NOT IN ($list)` => `$expr <> $list[0] AND $expr <> $list[1] ... AND $expr <> $list[n]`
627 if let Expr::InList {
628 expr: e,
629 list,
630 negated,
631 } = expr
632 {
633 if let Expr::Row { .. } = &**e {
634 if *negated {
635 *expr = list
636 .drain(..)
637 .map(|r| e.clone().not_equals(r))
638 .reduce(|e1, e2| e1.and(e2))
639 .expect("list known to contain at least one element");
640 } else {
641 *expr = list
642 .drain(..)
643 .map(|r| e.clone().equals(r))
644 .reduce(|e1, e2| e1.or(e2))
645 .expect("list known to contain at least one element");
646 }
647 }
648 }
649
650 // `$expr IN ($subquery)` => `$expr = ANY ($subquery)`
651 // `$expr NOT IN ($subquery)` => `$expr <> ALL ($subquery)`
652 if let Expr::InSubquery {
653 expr: e,

Callers

nothing calls this directly

Calls 15

ltFunction · 0.85
selectFunction · 0.85
opFunction · 0.85
gtMethod · 0.80
gt_eqMethod · 0.80
lt_eqMethod · 0.80
expectMethod · 0.80
not_equalsMethod · 0.80
equalsMethod · 0.80
binopMethod · 0.80
unwrapMethod · 0.80

Tested by

no test coverage detected