Function mz_sql::plan::lowering::branch

source ·
fn branch<F>(
    id_gen: &mut IdGen,
    outer: MirRelationExpr,
    col_map: &ColumnMap,
    cte_map: &mut BTreeMap<LocalId, CteDesc>,
    config: &Config,
    inner: HirRelationExpr,
    apply_requires_distinct_outer: bool,
    apply: F
) -> Result<MirRelationExpr, PlanError>where
    F: FnOnce(&mut IdGen, HirRelationExpr, MirRelationExpr, &ColumnMap, &mut BTreeMap<LocalId, CteDesc>, &Config) -> Result<MirRelationExpr, PlanError>,
Expand description

Prepare to apply inner to outer. Note that inner is a correlated (SQL) expression, while outer is a non-correlated (dataflow) expression. inner will, in effect, be executed once for every distinct row in outer, and the results will be joined with outer. Note that columns in outer that are not depended upon by inner are thrown away before the distinct, so that we don’t perform needless computation of inner.

branch will inspect the contents of inner to determine whether inner is not multiplicity sensitive (roughly, contains only maps, filters, projections, and calls to table functions). If it is not multiplicity sensitive, branch will not distinctify outer. If this is problematic, e.g. because the apply callback itself introduces multiplicity-sensitive operations that were not present in inner, then set apply_requires_distinct_outer to ensure that branch chooses the plan that distinctifies outer.

The caller must supply the apply function that applies the rewritten inner to outer.