Repository navigation
refactor(asap-aware-mapping)!: delete the legacy replacement search and CostModel - #736
Conversation
62a8c65 to
544bc09
Compare
…ch tested The legacy replacement search's tests pinned capabilities the planner stages still have: CMS, CMS-heap and KLL sizing, refused rollups, top-k reuse and capability sharing, CSE keeping differing accuracies apart, zero repetition intervals and non-finite arrival rates, per-series rate states, grouped avg schemas and SQL avg output names. Pin them on the stage code before the search is deleted.
…nd CostModel Nothing in the planner reached the legacy search any more. Delete it: ASAPStrategies and the realization engine, the search and global selection, the strategies (shared sub-DAG, rollup, avg rewrite, top-k reuse, Hydra grouping, accuracy reconciliation, exact composition), the replacement explanations, the CostModel trait with DefaultCostModel and its CSE hooks, and the legacy recurrence decision. The capabilities no stage implements are tracked in #735, #703 and #681 (user-approved exception). PlanningModels loses its unread cost field. AccuracyModel loses exact_operation_rule, AccuracyEvidenceProvider loses the unread topk_max_distinct_items and propagation_stats, and PropagationStats loses the Hydra grid fields. MaintainedPopulationStrategy keeps candidate (#681) without the ReplacementStrategy impl. Tests of capabilities the stages have move to the stage code; the integration tests drive the stages instead of the search.
544bc09 to
8a6aa83
Compare
…rs only the legacy core used
|
If you remove the CostModel, where are my defined 3 cost models,and how are they used by physical optimization stage? |
|
Your three cost models are untouched. #736 removed a different, older thing with the same name. What was removed: the legacy Where your three cost models are: in Stage 3, pub enum CostModel {
UsageOverTime(ResourceUnitCost), // cost model 1
ProvisionedCapacity(ResourceUnitCost), // cost model 2
ClusterCapacity(ClusterLimits), // cost model 3
}
pub struct PlanSelectionSettings {
pub cost_model: CostModel, // default: UsageOverTime(ResourceUnitCost::illustrative())
pub resource_speed: ResourceSpeed,
pub non_repeating_query_horizon_seconds: f64,
pub measured_operation_costs: ...,
}The deployment picks one through How the stages use them:
So the physical-optimization stage feeds the cost models but doesn't use them. That keeps Stage 2 independent of how a deployment pays. |
Why
The planner runs Stage 0 → Pass 1 → Pass 2 → Stage 2 → Stage 3 (
docs/design_docs/proposals/planner-layering.md). It no longer calls the legacy replacement search or theCostModelthe search ranked with. That legacy core is about 21k lines that every refactor still has to compile around, and it blocks the crate layout (G3, #572).The rule is to delete a legacy piece only once the stages implement it. Most of the core is replaced. Some of it is not (see the table). The user approved deleting the whole legacy core anyway, as an explicit exception, on 2026-10-16. The capabilities it loses are tracked in #735, #703 (Hydra) and #681 (maintained-population top-k).
What
Deleted modules of
asap-aware-mapping:replacement.rs:ASAPStrategiesand its realization engine,CandidatePlanningInputs,new_with_planning_inputs*,nested_layers_target, the workload search,CandidateLogicalASAPDAGs/GlobalSelection,SharedSubDAGStrategy,Matcher,retain_exact,posterior_aware_size_params,sketch_state_bytes;grouping.rs(HydraGroupingStrategy),rollup.rs,rewrite.rs,topk_reuse.rs,exact_composition.rs,accuracy/reconciliation.rs;explanation.rs;cost_model.rs:CostModel,DefaultCostModeland the CSE share/recompute and exact-composition cost hooks;recurrence.rs: the legacydecideand its rate types.feat(asap-aware-mapping)!: price sketch nodes from measured operation costs in Stage 3 #734 already deleted the physical-plan and empirical cost models, which were built on
CostModel.Public interfaces trimmed, each because only the deleted code read it:
PlanningModels.costandwith_cost;PlanningModels::newtakes(accuracy, evidence);AccuracyModel::exact_operation_rule;AccuracyEvidenceProvider::{topk_max_distinct_items, propagation_stats};PropagationStats::{hydra_shared_grid_collision_bound, hydra_shared_grid_failure_probability};realization::RealizationError;FunctionRules.accumulatorfield;OperandDomain::supports_ddsketch;MaintainedPopulationStrategy'sReplacementStrategyimpl.candidatestays: executor and frontend tests build population DAGs with it, and Offer maintained-population top-k candidates in Pass 1 #681 moves it into Pass 1.Not changed: what the stages plan. Candidate sets, selections and costs are the same; Examples 1–4 and
stage_pipelinepass unchanged.Tests: tests of deleted code go with it. Tests of capabilities the stages have are moved onto the stage code: 24 new or extended tests, and three integration-test files that now drive the stages instead of the search.
How
Every remaining reference was a type, a re-export or a doc link.
PlanningModelsheld a&dyn CostModelthat no stage read.AccuracyModelnamedExactOperationin a method onlyExactCompositionStrategycalled.function_rulesreturned a struct whose accumulator half only the legacy engine read; it becomesapproximate_input_composition(intent) -> Option<CompositionOperator>.realize_keyed_additive_summary_inputreturned a three-way result whose "unsupported" reason only the legacy rule table read; it returnsOption<PhysicalSummaryInput>, with the reasons kept as comments.The integration tests
promql_to_post_asap.rs,sql_to_post_asap.rsandexact_composition.rsusedASAPStrategies::replacementsandglobal_selection. They now take a Stage 1 logical candidate (planning::logical_candidates), or Stage 3's selection when they need evidence. Assertions follow the stages' shapes:Project;state;maxover an estimate is an exactMaxstate;Where the stages behave differently by design, the test pins the new behaviour or is dropped. Examples: an unsupported arm of a binary op stays exact while the other arm keeps its accumulator, and
on(job)matching keeps both accumulators.Capability → replacement
realizations_for_intent,sketch_realizations)per_computation_candidates.rs:computation_candidates_for_intent;realization.rs:summary_candidatesCostModel::size_params)realization.rs:default_size_params→accuracy::estimators::size_params; Pass 1sizedretain_exact,construct_summary_*,finalize_*,evaluation,compose_guaranteeper_computation_candidates.rs:substitute_measure,compose_logical_candidate,statistic,composed_guarantee/recompose_guarantees; target check instage3_plan_selection.rs:accuracy_checkper_computation_candidates.rs:measure_input,summary_update,whole_expression_input;realization.rs:realize_keyed_additive_summary_inputnested_layers_target,per_input_target)per_computation_candidates.rs:budget_shares+sized; δ instage3_plan_selection.rs:resize_for_failure_probabilityavg_over_timeandavgas sum/count (realize_temporal_average,AvgToSumOverCountStrategy)per_computation_candidates.rs:ExactAccumulator([Sum, Count])insubstitute_measure/sql_avgSemanticEquivalentRewriteStrategy)per_computation_candidates.rs:add_nested_sum_targets/nested_sumstage2_physical_asap_optimization.rs:implement_topkrewrite+arithmetic_guarantee;stage3_plan_selection.rs:domain_boundwith the division operand domainsSharedSubDAGStrategy)asap_aware_cse.rs:identical_expression_pass2_candidatesAccuracyReconciliationStrategy,strictest_sibling_accuracy)asap_aware_cse.rs:summary_capability_pass2_candidates;accuracy::estimators::size_for_all_readersRollupStrategy,is_legal_rollup_source)asap_aware_cse.rs:rollup_candidates,rollup_pass2_candidatesTopKLimitReuseStrategy)asap_aware_cse.rs:topk_reuse_candidates,topk_reuse_pass2_candidatesExactCompositionStrategy, query time)per_computation_candidates.rs:compose_logical_candidatesearch_workload*,GlobalSelection,rank_group,CostModel::{rank_candidates, estimate_cost, candidate_cost})pass/stage1_to_stage3.rs:run_stage1_to_stage3;stage3_plan_selection.rs:select_plancse_*hooks,recurrence::decide,RecurrenceProfile,CostRate,Horizon)stage2_physical_asap_optimization.rs:materialization_assignments;stage3_plan_selection.rs:computations,price,evaluation_ratestage3_plan_selection.rs:priceexplain_replacements)PruneReason,PrunedCandidate,Rejection.reason; devtoolsstage_pipelineMatcher(trait, no impl)asap_types::post_asap::FamilyCapability::answers;DeploymentCapabilities(#730)CostModel::summary_support_evidenceDeploymentCapabilities.supported_summaries(#730)PhysicalPlanCostModel), measured costs (EmpiricalCostModel),ResourceCalibrationstage3_plan_selection::measured_operation_costs); the rest is tracked in #733Not replaced (user-approved exception, 2026-10-16):
HydraGroupingStrategy)MaintainedPopulationStrategyin the search)OperationPlacement::Maintenance, value-operation hooks)CostModel::realize_extension/evaluation_extension)posterior_aware_size_params, unwired)maintenance_exact_values)max_samplescheck (supports_ddsketch)Stays, and why:
PlanningModels.accuracyand.evidence: Stage 3 reads them (accuracy.satisfies,evidence.operand_domain,evidence.output_guarantee).MaintainedPopulationStrategy::candidate: see What (Offer maintained-population top-k candidates in Pass 1 #681).storage_io.rs,physical_handoff_cost.rsandquery_physical_lowering.rs: unwired, with their own tests, kept for Plan selection: price storage I/O, handoffs and cache, from deployment evidence with provenance #733.PropagationStats'topk_*fields: theTopKSelectioncomposition rule reads them. Nothing sets them sincepropagation_statsis gone (Capabilities lost with the legacy replacement search: maintenance-time exact operations, extension intents, nested folds, rate-maintained summaries and guards #735 item 6).Key code interfaces added / modified
crates/asap-aware-mapping/src/pass/mod.rscrates/asap-aware-mapping/src/accuracy/mod.rs,accuracy/evidence.rscrates/asap-aware-mapping/src/lib.rs,realization.rs,maintained_population.rs,function_rules.rsUsage (end to end, run at the head commit): a deployment with a DDSketch ratio query and an enforced value range plans with the two-argument
PlanningModels::new.Before this PR
The planner already planned only through the stages. Next to them sat the legacy search, its strategies and the
CostModeltrait. Only their own tests and three integration-test files reached them.PlanningModelscarried acost: &dyn CostModelthat nothing read.AccuracyModelandAccuracyEvidenceProviderhad methods that only the legacy engine called.After this PR
asap-aware-mappingholds the stages and the models they read.PlanningModels::new(accuracy, evidence)has no cost model. Planning results are unchanged. The capabilities only the legacy core had are listed in #735, #703 and #681.Also deleted because only the legacy core used them:
asap_types::post_asap::lift_plain,ExactOperationSchemaError, and the test helperstest_support::agg_per_entityandtime_and_export.Verification
Run on the rebased head, on top of main de19eba (#737):
cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features --locked -- -D warningson asap-aware-mapping, asap-integration-tests, asap-types, asap-planner and asap-devtools: clean.cargo check --testson asap-physical-operators, asap-frontend-promql and asap-frontend-sql: clean.asap-aware-mapping, the touched modules (accuracy,realization,function_rules,per_computation_candidates,maintained_population,analytical_cost,pass,asap_aware_cse) plustests/cost_independence.rsandtests/per_computation_candidates.rs: 225 passed.asap-integration-tests,promql_to_post_asap,sql_to_post_asap,exact_composition,stage1_logical_asap_optimization,planner_layering_example1–4,materialization_e2eandoperator_design_examples: 135 passed. Examples 1–4 pin the selections and costs, unchanged.asap-plannere2e_plan,plan_stagesandsummary_sharing, andasap-devtoolsstage_pipeline: 42 passed.maintained_population,maintained_population_horizon,univmon_candidates,current_series_heap,deployment_computation,precompute_candidates): 37 passed.asap-typesir::cse,workloadandquery_time: 63 passed.Not run, per the current rule: workspace clippy and the full workspace suite (GitHub CI runs them after merge).
Found while moving the tests. These are not fixed here: they are pre-existing and this PR changes no planning behaviour.
avg without (instance) (m)composes with a closed schema while the pre-ASAP schema is open.whole_expression_inputrefuses grouped top-k fusion because the schema is closed.avgover an Int64 column does not compile physically (summary update type is unsupported by its family).Old drafts this PR fully supersedes: #635 (delete the legacy search and CostModel). #622 (delete the physical-plan cost model) is superseded by #734.