Skip to content

rqe-optimizer: split SumOrCount and TopK by kind; deny unknown AtomicCostEntry fields #161

Closed

Description

@milindsrivastava1997

Two rqe-optimizer / aqpbm-core changes that came out of review on ProjectASAP/ASAPQuery#798 (A2b of ProjectASAP/ASAPQuery#790).

1. Split Capability::SumOrCount into Sum and Count

Sum and count both map to SumOrCount. A Deployment is keyed by (capability, metric, spatial filter, grouping, config, window), so the MILP can serve sum by (job) (x) and count by (job) (x) from one exact-sum deployment. One accumulator holds either the sum of values or the sum of 1s, not both.

Failure: ASAPQuery rewrites avg by (job) (x) into a sum item and a count item on the same metric and grouping. Both get served by one shared deployment, so ingest and memory come out ~2× too low, and the plan can't be deployed (ASAPQuery's MultipleSum has distinct sum/count sub-types).

Fix: separate Sum and Count capabilities, as Min / Max already are. Both keep exact-sum as their family; they just must not share a deployment. Rate/Increase can stay together, since rate is derived from increase.

2. #[serde(deny_unknown_fields)] on AtomicCostEntry

ASAPQuery now uses aqpbm_core::AtomicCostEntry directly instead of its own copy, which had deny_unknown_fields. Without it, a misspelled or newer field (e.g. merge_acuracy, or a future subtract_cpu_secs) loads silently with its data dropped. For example, merge-count accuracy would then never be checked. Please add deny_unknown_fields (optional fields already use #[serde(default)]), plus a test that an unknown field is rejected.

3. Distinguish value-weighted and count-weighted top-k

Same problem as §1, for TopK. ASAPQuery's top-k has two kinds: value-weighted (topk(5, sum_over_time(x[5m]))) and count-weighted (topk(5, count_over_time(x[5m])), topk_count_events = true). Raqe can't express the difference, so two such queries at the same cadence become identical Raqes and the MILP can serve both from one cms-heap-topk-fastpath-vector2d deployment. ASAPQuery deploys them as two CountMinSketchWithHeap configs with different count_events, so one query gets wrong rankings and the plan counts one sketch too few.

Fix: split TopK into two capabilities (e.g. TopKByValue / TopKByCount) that don't share deployments, or add a field to Raqe that is part of stream identity. Both keep the same families. Until this lands, ASAPQuery errors when both kinds hit the same metric and grouping.

Once all three land, ASAPQuery bumps its pinned rqe-optimizer rev.

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Oct 7, 2026
    1f306d0
  2. changed the title [-]rqe-optimizer: split SumOrCount into Sum and Count; deny unknown AtomicCostEntry fields[/-] [+]rqe-optimizer: split SumOrCount and TopK by kind; deny unknown AtomicCostEntry fields[/+] on Oct 7, 2026
  3. milindsrivastava1997 commented on Oct 7, 2026

    @milindsrivastava1997
    ContributorAuthor

    Added §3: the same deployment-sharing problem for value-weighted vs count-weighted top-k (topk_count_events), found in review of ProjectASAP/ASAPQuery#798.

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

Metadata

Metadata

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