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

Method could_run_expensive_function

src/expr/src/relation.rs:1979–2000  ·  view source on GitHub ↗

The MirRelationExpr is considered potentially expensive if and only if at least one of the following conditions is true: - It contains at least one MirScalarExpr with a function call. - It contains at least one FlatMap or a Reduce operator. - We run into a RecursionLimitError while analyzing the expression. !!!WARNING!!!: this method has an HirRelationExpr counterpart. The two should be kept in

(&self)

Source from the content-addressed store, hash-verified

1977 /// !!!WARNING!!!: this method has an HirRelationExpr counterpart. The two
1978 /// should be kept in sync w.r.t. HIR ⇒ MIR lowering!
1979 pub fn could_run_expensive_function(&self) -> bool {
1980 let mut result = false;
1981 use MirRelationExpr::*;
1982 use MirScalarExpr::*;
1983 if let Err(_) = self.try_visit_scalars::<_, RecursionLimitError>(&mut |scalar| {
1984 result |= match scalar {
1985 Column(_, _) | Literal(_, _) | CallUnmaterializable(_) | If { .. } => false,
1986 // Function calls are considered expensive
1987 CallUnary { .. } | CallBinary { .. } | CallVariadic { .. } => true,
1988 };
1989 Ok(())
1990 }) {
1991 // Conservatively set `true` if on RecursionLimitError.
1992 result = true;
1993 }
1994 self.visit_pre(|e: &MirRelationExpr| {
1995 // FlatMap has a table function; Reduce has an aggregate function.
1996 // Other constructs use MirScalarExpr to run a function
1997 result |= matches!(e, FlatMap { .. } | Reduce { .. });
1998 });
1999 result
2000 }
2001
2002 /// Hash to an u64 using Rust's default Hasher. (Which is a somewhat slower, but better Hasher
2003 /// than what `Hashable::hashed` would give us.)

Callers

nothing calls this directly

Calls 1

visit_preMethod · 0.45

Tested by

no test coverage detected