Skip to main content

promote_multiway

Function promote_multiway 

Source
pub fn promote_multiway(
    plan: &mut ExecutionPlan,
    _rel_ids: &HashMap<String, RelId>,
    stats: &StatsManager,
    config: &CompilerConfig,
)
Expand description

Walk an ExecutionPlan and rewrite eligible triangle / 4-cycle subtrees in each rule body to RirNode::MultiWayJoin. Idempotent.

CompiledRule.meta is preserved unchanged — the metadata is rule-level (head schema, row estimates, layout hints), not node-level, and the promoter does not alter rule semantics.

rel_ids is the canonical predicate-name → RelId map used to resolve body Scans against the head SCC’s predicate set. Pass Compiler::rel_ids() (or Lowerer::rel_ids()) at the call site.

Recursive SCC bodies. Multi-recursive bodies are admitted, including same-predicate self-recursive occurrences (per arXiv:2604.20073 — semi-naïve evaluation reasons over body-clause OCCURRENCES, not predicate names). The triangle / 4-cycle shape gates already cap atom count at 3 / 4, so the recursive-Scan count is implicitly bounded; the runtime’s per-variant rewrite + dispatch loop in execute_recursive_scc handles N variants correctly with the occurrence-identity rewrite.