Skip to content

TopK { accuracy: Exact } routes to PassThrough — no sketch-tier approximation offered even when one would serve #151

Description

@zzylol

Context

Same migration as issue #150 (ASAPQuery-backend's `control_plane` adopting `asap_plan::bind::implement_tree_in_with`).

`crates/plan/src/boundary.rs`'s `implementation_for_with` routes any approximate-capable intent at `AccuracyTarget::Exact` through `exact_realization`:

```rust
fn exact_realization(intent: &AggIntent) -> Implementation {
match intent {
AggIntent::Count { .. } => accumulator(intent, SummaryKind::Count, SummaryParams::Count),
_ => Implementation::PassThrough,
}
}
```

For `AggIntent::TopK { accuracy: Exact, .. }` this returns `PassThrough` — no summary form at all. That's defensible (there's no exact mergeable top-k accumulator), but `control_plane`'s own (now-retired) `BindCountSketchOnTopK` rule took a different, still-useful position: an `Exact`-accuracy top-k request is treated as "exact rank / high recall required" and routed to the unbiased `CountSketch`-with-heap family (a real approximation, just the tightest-available one) rather than declining outright. This is a genuine, reasonable deployment policy choice — "no summary" vs. "the best available approximation" — that `implementation_for`'s current `Exact ⇒ exact_realization` short-circuit doesn't leave room for, since the decision of whether to consult a cost model at all happens before any `CostModel` hook (`rank_candidates`/`size_params`, see PR #146) is ever reached.

Request

Consider whether `TopK`'s exact-accuracy case should still offer sketch candidates to `CostModel::rank_candidates` (which could then return an empty `Vec` to decline, preserving today's `PassThrough` default) rather than short-circuiting to `PassThrough` before the cost model is ever consulted. This would let a deployment that wants the "closest available approximation for an exact-rank request" policy express it via the existing `CostModel` extension point, instead of needing a separate pre-pass that bypasses `implement_tree_in_with` entirely for this one shape.

What we did instead (for now)

`control_plane` currently intercepts `TopK { accuracy: Exact }` before calling `implement_tree_in_with`, matching its previous behavior via a small local helper. This works but means every deployment with a similar "still approximate under an exact request" policy has to reimplement the same pre-pass rather than using the `CostModel` hook.

References

  • `crates/plan/src/boundary.rs` — `implementation_for_with`'s `Exact => exact_realization` arm, `exact_realization`
  • ASAPController#146 (`CostModel::size_params`) — related extension-point precedent

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

    accuracyAccuracy requirements, guarantees, and propagationbindingLogical-to-physical binding and implementation selectionenhancementNew feature or requestreplacement-strategyASAP replacement candidates and physical strategies

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions