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
analyzer.rs — thread SketchExpr through QueryWorkload instead of flattening to Vec<AggType>.
planner/ — add split_expr_by_stage() that walks the tree and emits per-stage sub-plans.
config/precompute.rs — replace hardcoded build_query_expr() template with serialization of the upper sub-tree.
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.
Background
SP-3 (Stage Assignment) currently assigns a single flat sketch type to every pipeline stage. The planner in
rules.rsreceives onlyVec<AggType>— the fullSketchExprtree built by the query parser is discarded inanalyzer.rsbefore it reaches the planner.For compositional queries like
TopK(Partition(Window(Agg(Source)))), this means:quantile_over_time(0.99, ...)template regardless of the actual query structure.Proposed subproblem: SP-9
Split the optimized
SketchExprtree across pipeline stages:SketchExprnodeSource,Filter,Window,AggPartition,Merge,DedupTopKExactAggThe full spec is in
docs/controller-optimization-problem.mdunder SP-9.Implementation gaps
analyzer.rs— threadSketchExprthroughQueryWorkloadinstead of flattening toVec<AggType>.planner/— addsplit_expr_by_stage()that walks the tree and emits per-stage sub-plans.config/precompute.rs— replace hardcodedbuild_query_expr()template with serialization of the upper sub-tree.types.rs/CollectionPlan— extend to carry a per-stage sub-expression soagent.rsandbackend.rsemit the right processor chain.Files involved
controller/src/analyzer.rscontroller/src/query_parser/mod.rs,sketch_algebra.rscontroller/src/planner/rules.rscontroller/src/config/precompute.rs,agent.rs,backend.rscontroller/src/types.rsRelation 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.