Skip to content

refactor(planner): move Pass 1 helpers out of the legacy search; drop show_post_asap_ir, erp and empirical_comparison - #676

Merged
zzylol merged 2 commits into
mainfrom
stack/g2-legacy-removal
Oct 13, 2026
Merged

zzylol merged 2 commits into
mainfrom
stack/g2-legacy-removal

Conversation

@zzylol

@zzylol zzylol commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

This is the first step in removing the legacy replacement search. The rule is that a legacy piece is deleted only once the new architecture implements it, and the group that reimplements a capability deletes the legacy piece. This PR deletes only the pieces that are already replaced (show_post_asap_ir → stage_pipeline) or that the user decided to drop (erp, empirical_comparison: Assumption 5's deployment-owned empirical models cover them, and sketch-bench keeps its own copy). It also moves the helpers Pass 1 shares with the legacy search out of replacement.rs, so that file can be deleted later without touching Pass 1.

What stays, and which group or issue removes it:

What

  • New asap_aware_mapping::realization holds summary_candidates, accuracy_target, accuracy_budget, default_size_params, DEFAULT_DELTA, column_ref, summarised_column and summarised_input. The bodies moved unchanged from replacement.rs. The one difference is that summarised_column is now pub(crate), because the legacy search still calls it. Pass 1 (per_computation_candidates), replacement.rs and the other callers import from the new module. RealizationError also moves to realization (re-exported from replacement), so the new module does not depend on the legacy search.
  • Deleted the show_post_asap_ir bin, which stage_pipeline replaces. Renamed show_pre_asap_ir to show_logical_dag. Bins are auto-discovered, and no CI or tests referenced either name.
  • Renamed the frontend-common resolver's fallback schema to usage_derived_schema.
  • Deleted erp.rs and empirical_comparison.rs, plus empirical_cost::snapshot_prepare_cpu (only empirical_comparison used it) and its unit test.
  • No Markdown changes.

Key code interfaces added / modified

crates/asap-aware-mapping/src/realization.rs (new), replacement.rs, lib.rs

// realization.rs: Pass 1 helpers moved unchanged out of replacement.rs
/// Confidence δ assumed when the target carries only an ε; (ε, δ)-sized
/// sketches such as CMS need one.
pub const DEFAULT_DELTA: f64 = 0.01;
/// The sketch kinds that can serve an intent, most-preferred first; Pass 1
/// reads it to list an intent's summary candidates.
pub fn summary_candidates(intent: &AggIntent) -> &'static [SketchAlgorithm];
/// The accuracy target on an approximate-capable intent (quantile,
/// cardinality, count, top-k, ...), or `None` for every other intent.
pub fn accuracy_target(intent: &AggIntent) -> Option<&AccuracyTarget>;
/// Resolves an accuracy target into the `(eps, delta)` budget sketch sizing
/// needs, filling δ with `DEFAULT_DELTA` when only ε is given.
pub fn accuracy_budget(accuracy: &AccuracyTarget) -> (f64, f64);
/// The built-in sketch sizing for `(eps, delta)`: the smallest parameters
/// meeting the bound, clamped to the family's range.
pub fn default_size_params(kind: SketchAlgorithm, intent: &AggIntent, eps: f64, delta: f64) -> SketchParams;
/// The one column a single-column summary reads, or the PromQL sample value
/// when the intent reads none.
pub(crate) fn summarised_column(intent: &AggIntent, child_schema: &Schema) -> ColumnRef; // was private
/// A schema field as a named or table-qualified column reference.
pub(crate) fn column_ref(column: &Field) -> ColumnRef;
/// What the summary consumes per row: one column, or the whole tuple for a
/// multi-column intent; a tuple column outside the schema is an error.
pub(crate) fn summarised_input(intent: &AggIntent, child_schema: &Schema) -> Result<SummaryInputExpr, RealizationError>;

/// Why building a candidate's plan failed.
pub enum RealizationError { // moved from replacement.rs
    /// Schema derivation failed while binding a sub-DAG.
    Schema(SchemaDerivationError),
    /// The candidate cannot meet its accuracy target (no sound propagation
    /// rule, or the target is missed); it is rejected, not built.
    Accuracy(AccuracyError),
    /// The summary family's realization rule cannot represent the complete
    /// input (an unsupported shape).
    PhysicalRealization(&'static str),
    /// A constructed plan violates the update/evaluation phase contract;
    /// detected at construction.
    ExecutionDataState(ExecutionDataStateError),
    /// An exact operator's output schema could not be derived over its child,
    /// which carries summary state it can't read.
    ExactOperationSchema(ExactOperationSchemaError),
}

// replacement.rs
/// Callers that import the error from `replacement` keep compiling.
pub use crate::realization::RealizationError; // re-export keeps the old path

// lib.rs
/// Pass 1's candidate and sizing helpers.
pub mod realization;                         // new
/// Crate-root path for listing an intent's sketch candidates.
pub use realization::summary_candidates;     // was replacement::summary_candidates
// removed: pub mod erp;
// removed: pub mod empirical_comparison;

crates/asap-aware-mapping/src/erp.rs, empirical_comparison.rs, empirical_cost.rs (deleted files linked at the parent commit)

// erp.rs, removed (deployment-owned empirical models cover it)
/// A versioned file of error-resource profile records.
// removed: pub struct ErpArtifact { .. }
/// One benchmarked sketch configuration: parameters, data distribution, observed errors, resources.
// removed: pub struct ErpRecord { .. }
/// A record's memory and update/merge/query CPU costs.
// removed: pub struct ErpResourceProfile { .. }
/// Inputs for picking the cheapest record under an empirical error bound.
// removed: pub struct ErpSelectionRequest { .. }
/// Unsupported schema version, invalid artifact, or no record meets the error bound.
// removed: pub enum ErpError { .. }
// removed: /* ErpDataShape, ErpShapeFit, ErpMultiFitSelectionRequest, ErpNearestSelectionRequest, ... */

// empirical_comparison.rs, removed for the same reason
/// Compared fixed-snapshot CPU costs of sketch and exact alternatives and recommended one.
// removed: pub fn recommend_offline(evidence: &OfflineComparisonEvidence, request: &OfflineComparisonRequest) -> Result<OfflineRecommendation, String>;
/// Whether a sketch's parameters are componentwise at least a minimum.
// removed: pub fn parameters_at_least(candidate: &SketchParams, minimum: &SketchParams) -> bool;
/// Query, accuracy requirement, workload and weights for `recommend_offline`.
// removed: pub struct OfflineComparisonRequest { .. }
/// The selected option, the exact baseline, every candidate and the estimated savings.
// removed: pub struct OfflineRecommendation { .. }

// empirical_cost.rs
/// A measurement row's snapshot preparation CPU, if known.
// removed: pub(crate) fn snapshot_prepare_cpu(row: &OfflineMeasurement) -> Option<f64>; // only empirical_comparison used it

crates/devtools/src/bin/show_logical_dag.rs (renamed from show_pre_asap_ir.rs), show_post_asap_ir.rs (removed)

// Lowers a batch of SQL/PromQL queries to pre-ASAP IR and prints it; picks no sketch.
// bin show_logical_dag: renamed from show_pre_asap_ir
// Printed the post-ASAP IR; use stage_pipeline for the planner stages instead.
// bin show_post_asap_ir: removed; stage_pipeline replaces it

Usage:

use asap_aware_mapping::realization::{accuracy_budget, accuracy_target, default_size_params, summary_candidates};

if let Some(target) = accuracy_target(intent) {
    let (eps, delta) = accuracy_budget(target);
    for kind in summary_candidates(intent) {
        let params = default_size_params(kind.clone(), intent, eps, delta);
    }
}

Verification

  • git grep -w finds no remaining reference to any deleted public item or to either old bin name outside Markdown.
  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo nextest run --workspace: 1609 passed, 50 skipped. All 23 removed tests were in deleted code: 10 in erp, 9 in empirical_comparison, 3 in show_post_asap_ir, and 1 for snapshot_prepare_cpu.
  • stage_pipeline --example planner-layering-1 output is byte-identical to tools/dag-viewer/examples/planner-layering-example1.json.
  • tools/dag-viewer/test_render.py: 29 OK. tools/verify_metricsql_external_consumer.sh: OK.

Human review

  • The moved helpers and RealizationError are unchanged
  • Deleting erp/empirical_comparison (and snapshot_prepare_cpu) matches the decision
  • The ownership list above for what stays is correct

Comment thread crates/asap-aware-mapping/src/accuracy/estimators/mod.rs
Comment thread crates/asap-aware-mapping/src/cost_model.rs
… show_post_asap_ir, erp and empirical_comparison

- New asap_aware_mapping::realization holds the summary realization helpers
  (summary_candidates, accuracy_target, accuracy_budget, default_size_params,
  DEFAULT_DELTA, column_ref, summarised_column, summarised_input), moved
  unchanged from replacement.rs; Pass 1 and the legacy search import them.
- Delete the show_post_asap_ir bin (replaced by stage_pipeline); rename
  show_pre_asap_ir to show_logical_dag.
- Rename the frontend-common resolver's `fallback` schema to
  `usage_derived_schema`.
- Delete erp.rs and empirical_comparison.rs, and snapshot_prepare_cpu (only
  empirical_comparison used it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
@zzylol
zzylol force-pushed the stack/g2-legacy-removal branch from a4f58c1 to 67e7847 Compare October 13, 2026 19:29
@zzylol zzylol changed the title chore(planner): delete the legacy replacement search, legacy cost models and dag_export refactor(planner): move Pass 1 helpers out of the legacy search; drop show_post_asap_ir, erp and empirical_comparison Oct 13, 2026
realization.rs no longer imports from the legacy replacement search;
replacement.rs re-exports the error from realization.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant