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

Function apply_existential_subquery

src/sql/src/plan/lowering.rs:2021–2051  ·  view source on GitHub ↗
(
    id_gen: &mut mz_ore::id_gen::IdGen,
    outer: MirRelationExpr,
    col_map: &ColumnMap,
    cte_map: &mut CteMap,
    subquery_expr: HirRelationExpr,
    apply_requires_distinct_outer: bool,
  

Source from the content-addressed store, hash-verified

2019}
2020
2021fn apply_existential_subquery(
2022 id_gen: &mut mz_ore::id_gen::IdGen,
2023 outer: MirRelationExpr,
2024 col_map: &ColumnMap,
2025 cte_map: &mut CteMap,
2026 subquery_expr: HirRelationExpr,
2027 apply_requires_distinct_outer: bool,
2028 context: &Context,
2029) -> Result<MirRelationExpr, PlanError> {
2030 branch(
2031 id_gen,
2032 outer,
2033 col_map,
2034 cte_map,
2035 subquery_expr,
2036 apply_requires_distinct_outer,
2037 context,
2038 |id_gen, expr, get_inner, col_map, cte_map, context| {
2039 let exists = expr
2040 // compute for every row in get_inner
2041 .applied_to(id_gen, get_inner.clone(), col_map, cte_map, context)?
2042 // throw away actual values and just remember whether or not there were __any__ rows
2043 .distinct_by((0..get_inner.arity()).collect())
2044 // Append true to anything that returned any rows.
2045 .map(vec![MirScalarExpr::literal_true()]);
2046
2047 // append False to anything that didn't return any rows
2048 get_inner.lookup(id_gen, exists, vec![(Datum::False, ReprScalarType::Bool)])
2049 },
2050 )
2051}
2052
2053impl AggregateExpr {
2054 fn applied_to(

Callers 2

applied_toMethod · 0.85
lower_subqueriesMethod · 0.85

Calls 8

branchFunction · 0.85
distinct_byMethod · 0.80
applied_toMethod · 0.80
mapMethod · 0.45
cloneMethod · 0.45
collectMethod · 0.45
arityMethod · 0.45
lookupMethod · 0.45

Tested by

no test coverage detected