Skip to content

Add Subplan Sharing optimization pass #61

@justinjoy

Description

@justinjoy

Summary

Add a Subplan Sharing optimization pass that identifies and eliminates redundant sub-computations across rules within the same stratum.

Motivation

When multiple rules scan the same relation with identical filters or join the same pair of relations on the same keys, the DD plan currently generates duplicate operator chains. Subplan sharing detects these common sub-plans and merges them so the underlying DD execution evaluates each unique sub-computation only once.

Design

  • New pass file: wirelog/passes/subplan_sharing.c (following fusion.c, jpp.c, sip.c pattern)
  • Operates on the stratified IR before DD plan generation
  • Identifies structurally equivalent sub-trees (SCAN+FILTER, JOIN with same keys) across rules in a stratum
  • Rewrites the IR to share a single sub-tree, with dependent rules referencing the shared node
  • Integrated into the optimization pipeline in driver.c after SIP

Acceptance Criteria

  • wl_subplan_sharing_apply() pass implemented and integrated
  • Unit tests covering: identical scans merged, identical scan+filter merged, distinct scans preserved
  • All existing tests pass (meson test, cargo test)
  • Benchmark suite runs without regression
  • C lint clean (clang-format-18)

Context

Phase 1 optimization — item 8 in the roadmap. Follows JPP and SIP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions