Skip to content

SP-9: AST-aware hierarchical stage assignment (edge collector → leaf nodes, precompute engine → upper AST) #90

Description

@zzylol

Background

SP-3 (Stage Assignment) currently assigns a single flat sketch type to every pipeline stage. The planner in rules.rs receives only Vec<AggType> — the full SketchExpr tree built by the query parser is discarded in analyzer.rs before it reaches the planner.

For compositional queries like TopK(Partition(Window(Agg(Source)))), this means:

  • The precompute engine receives a hardcoded quantile_over_time(0.99, ...) template regardless of the actual query structure.
  • There is no mechanism to assign leaf-level operations (sketch insertion, windowing) to the OTel Collector and upper-level operations (TopK, Merge, Partition) to the ASAPQuery Precompute Engine.

Proposed subproblem: SP-9

Split the optimized SketchExpr tree across pipeline stages:

SketchExpr node Stage
Source, Filter, Window, Agg Agent OTel Collector
Partition, Merge, Dedup Backend OTel Collector
TopK ASAPQuery Precompute Engine
ExactAgg DB-side query

The full spec is in docs/controller-optimization-problem.md under SP-9.

Implementation gaps

  1. analyzer.rs — thread SketchExpr through QueryWorkload instead of flattening to Vec<AggType>.
  2. planner/ — add split_expr_by_stage() that walks the tree and emits per-stage sub-plans.
  3. config/precompute.rs — replace hardcoded build_query_expr() template with serialization of the upper sub-tree.
  4. types.rs / CollectionPlan — extend to carry a per-stage sub-expression so agent.rs and backend.rs emit the right processor chain.

Files involved

  • controller/src/analyzer.rs
  • controller/src/query_parser/mod.rs, sketch_algebra.rs
  • controller/src/planner/rules.rs
  • controller/src/config/precompute.rs, agent.rs, backend.rs
  • controller/src/types.rs

Relation to existing subproblems

SP-9 is a refinement of SP-3, not a replacement. The flat SP-3 assignment remains as the fallback for single-aggregation queries. SP-6 can score both plans (flat vs. AST-split) and select the cheaper option.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions