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

Method plan_bool_and

src/sql/src/plan/transform_ast.rs:315–343  ·  view source on GitHub ↗
(
        &mut self,
        expr: Expr<Aug>,
        filter: Option<Box<Expr<Aug>>>,
        distinct: bool,
        over: Option<WindowSpec<Aug>>,
    )

Source from the content-addressed store, hash-verified

313 }
314
315 fn plan_bool_and(
316 &mut self,
317 expr: Expr<Aug>,
318 filter: Option<Box<Expr<Aug>>>,
319 distinct: bool,
320 over: Option<WindowSpec<Aug>>,
321 ) -> Expr<Aug> {
322 // The code below converts `bool_and(x)` into:
323 //
324 // sum((NOT x)::int4) = 0
325 //
326 // It is tempting to use `count` instead, but count does not return NULL
327 // when all input values are NULL, as required.
328 //
329 // The `NOT x` expression has the side effect of implicitly casting `x`
330 // to `bool`. We intentionally do not write `NOT x::bool`, because that
331 // would perform an explicit cast, and to match PostgreSQL we must
332 // perform only an implicit cast.
333 let sum = self.plan_agg(
334 self.scx
335 .dangerous_resolve_name(vec![PG_CATALOG_SCHEMA, "sum"]),
336 expr.negate().cast(self.int32_data_type()),
337 vec![],
338 filter,
339 distinct,
340 over,
341 );
342 sum.equals(Expr::Value(Value::Number(0.to_string())))
343 }
344
345 fn plan_bool_or(
346 &mut self,

Callers 1

rewrite_functionMethod · 0.80

Calls 8

plan_aggMethod · 0.80
castMethod · 0.80
int32_data_typeMethod · 0.80
equalsMethod · 0.80
ValueInterface · 0.50
negateMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected