(&mut self, expr: &mut Expr<Aug>)
| 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, |
nothing calls this directly
no test coverage detected