Skip to content

Cost calibration: a deployment's measured cost file, per-series scans, priced predicates, raw rows in memory, groups a window reaches - #1555

Draft
zzylol wants to merge 18 commits into
feat/sil-inlist-selectivityfrom
feat/backend-cost-calibration
Draft

zzylol wants to merge 18 commits into
feat/sil-inlist-selectivityfrom
feat/backend-cost-calibration

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Update 2026-12-04: restacked on the IN-list branch (dae00dc), review I1–I4, item 6 adopted

  • Base: feat/sil-inlist-selectivity at dae00dc (IN-list selectivity + item 6's declared skew). Item 2's series visited are the series a query-time scan's predicates select.
  • I1 (how a window's rows reach groups): GroupReach is read from the chain's own key columns and its sources' facts.
    • Periodic series (sample_interval declared) reach min(1, rows/groups). 10,000 series every 15 s in 10 s windows reach 2/3 of them; a window equal to the interval reaches all.
    • A key column with a declared Zipf skew (zipf_exponent_per_label, item 6) reaches Σ g(1 − e^(−rows·p_i/g)). 100,000 rows over 10,000 Zipf(1) hosts of 10 users reach 28.1% of the groups.
    • Otherwise rows fall at random (1 − e^(−rows/groups)).
    • Window merges use the same reach for their wider windows.
  • I2: readers still read every group per window. The measured SummaryMerge price was fitted on those all-group state counts, and scaling the output edge broke Stage 3's per-family folded-rows check. The share scales the window's memory and emitted states.
  • I3: the per-series charge applies only to query-time scans, over the selected series.
  • I4: T4 runs and is no longer ignored. With the measured file and the declared host skew, drill_cnt's full intent keeps the (host, user) counts: 48.14/s vs 50.66/s for the on-demand plan. With the formulas alone it does not (39.40/s, no lightcone).
  • Anchors re-pinned after I1: E6 192.9132 / 169.4972 / 141.1861. Both lowest_mean_latency pins are back to the base values. Q5-E2 is 98.22/s (bound 99). The sketch snapshots are regenerated; only chains-10m-5m-3m-10s differs from the base.
  • Local runs (12 jobs): asap-cost lib 166/166; asap-planner --test planner 101 (1 ignored), all pass; asap-planner-cli --test planner_cli 90 pass; integration pass; corpus + sketch snapshots pass after regeneration; clippy -D warnings clean on asap-cost.

Deferred

  • Service skew in the dash/rca fixtures. With zipf_exponent_per_label: {service: 0.8} on dash's tables and the measured file, Stage 3's objective and plan_cost differ by 3e-6 relative in full intent. The difference persists with this branch's reach disabled, so it lies in the skew-share path; it is reported on the IN-list track. The fixtures declare the host skew only.
  • A coverage warning for operators the measured file does not cover (Sum/Min/Avg chains, KLL/CMS, other DDSketch α).
  • The doc note that raw_data_medium applies to query-time scans' raw data only, and the rename disk_cost → raw_cost in plan/cost.rs (review nits).
  • Refitting the slower machine's file from its own matrix.

Summary

  • Problem. The planner misjudged the ratio between scanning raw rows and merging kept summary states. On one machine, measured runs of the drill_cnt intent show the shared (host, user) counts kept at ingestion (the lightcone) costing 3.2x less than reading auth at query time: cost model 1, 61 vs 191 per second. The planner predicted 169 vs 178, a 5% margin.
  • Change. Five changes:
    1. A deployment's measured cost file (calibration/measured-cost-files/<machine key>.json), supplied through CostInputs.
    2. A per-series scan unit (OperatorCost::ns_per_series).
    3. Named and measured scan/filter constants. A scan's predicates are now charged per compared value.
    4. Raw rows priced where the data plane keeps them (DataPlaneExecution::raw_data_medium, raw_data_bytes_per_row).
    5. A chain's window holds states only for the groups its rows reach.
  • Effect. With the file, the planner predicts 95 vs 274 for drill_cnt (2.9x; measured 3.1x). It keeps the lightcone in all three measured intents, each of which measured cheaper there. Its per-query and per-mode CPU predictions are within 1.5x of measured.

Review guide

  • Base: feat/sil-inlist-selectivity (IN-list selectivity, test-first commit 01ff90c37; its implementation is in progress). This PR stacks on it, and item 6 of the calibration (the rows a top-k binding's heavy values hold) is that branch's. Restack once it lands: item 2's series visited then takes the IN-list's kept series.
  • Read first:
    • crates/cost/src/node/usage/mod.rs: series_visited, the Scan arm's predicate terms, the Filter arm, groups_reached_share, window_group_share.
    • crates/cost/src/node/operations_per_unit.rs: SCAN_OPERATIONS_PER_ROW, FILTER_OPERATIONS_PER_ROW*, filter_terms_per_row, compared_values.
    • crates/cost/src/plan/cost.rs and crates/stage3-plan-selection/src/cost.rs: the raw data medium.
  • Data: calibration/measured-cost-files/ (two JSON files and a README with each entry's provenance).
  • Mechanical:
    • ns_per_series: 0.0 added to existing OperatorCost literals.
    • The rename raw_data_disk_cost_per_second → raw_data_cost_per_second.
    • 15 regenerated snapshots, which change numbers only.
    • Re-pinned anchors (commit 61d79428e; each change is explained there).
  • Commits: test-first. 5a37f5334 and f97953520 hold the failing tests, with interface stubs. Then one commit per item (2, 3, 4, 5, 1), then the anchors, a cost-file fix, style, and snapshots.

Behavior: before → after

The user plans E6's drill_cnt SIL intent: top-10 hosts by count over flows (1 h), then per-user counts over auth (10 min) WHERE host IN $Y, every 10 s. The data facts are 20,000 + 10,000 rows/s; auth has 100,000 series. Each mode is planned with and without the measured file:

replan_sil intent.sil tables.json data.json intent_full [calibration/measured-cost-files/x86_64-intel-xeon-e5-2683-v3-56t-registered-ddr4.json]

Cost model 1, cost per second, with CPU in ms/s:

mode measured (CPU / cost) before (3ef265d) after, formulas after, with the file
query at a time 165-170 / 191-196 159 / 177.9 174 / 192.9 246 / 273.8
full intent (lightcone kept) 52.2 / 61.3 107 / 169.3 101 / 149.6 72 / 95.2
lightcone / on demand 0.32 0.95 0.78 0.35

Per query with the file: q1 33.3 ms (measured 25.2), q2 on demand 2,340 ms (1,577), q2 from the lightcone 265 ms (262). The need is MVP correctness: the planner should pick the plan the data plane runs cheaper, and the paper's E7 figure needs predictions it can plot.

Interfaces

crates/cost/src/measured.rs

 /// The measured CPU time of one operator kind, at one phase, for one family (stays).
 pub struct OperatorCost {
     pub operator: OperatorKind,
     pub phase: Option<ExecutionTiming>,
     pub sketch: Option<SketchParams>,
     pub exact: Option<ExactKind>,
     pub measure: Option<String>,
     pub ns_per_unit: f64,
+    /// For a `Scan`: CPU ns per series it visits in one computation, beside
+    /// `ns_per_unit` per sample (a series store finds and decodes each series once
+    /// per read). Default 0; a negative or non-finite value is refused.
+    pub ns_per_series: f64,
     pub ns_per_invocation: f64,
     pub memory_bytes_per_state: Option<f64>,
     pub stored_bytes_per_state: Option<f64>,
     pub ns_per_state_emitted: f64,
     pub measured_series_count: Option<u64>,
     pub measures: Vec<String>,
 }
 /// A node's unit price, from its entry or interpolated between two (stays).
 pub struct UnitPrice {
     pub ns_per_unit: f64,
+    /// CPU ns per series a scan visits (`OperatorCost::ns_per_series`).
+    pub ns_per_series: f64,
     pub ns_per_invocation: f64,
     pub memory_bytes_per_state: Option<f64>,
     pub stored_bytes_per_state: Option<f64>,
     pub ns_per_state_emitted: f64,
     pub outside_measured_scale: bool,
 }

crates/cost/src/model.rs

 /// How the deployment's data plane runs work (stays).
 pub struct DataPlaneExecution {
     pub ingest_threads: Option<u32>,
     pub precompute_threads: u32,
     pub query_threads: u32,
     pub allowed_lateness_ms: u64,
     pub max_thread_utilization: f64,
     pub ingest_work_at_refresh: bool,
     pub view_window_cache: Option<ViewWindowCache>,
     pub kept_query_time_results: Option<KeptQueryTimeResults>,
     pub answer_cache: Option<AnswerCache>,
     pub state_offset_bytes_per_row: u64,
     pub key_bytes_per_label_column: u64,
+    /// Where the data plane keeps the raw rows its query-time scans read: `Disk`
+    /// (default), charged at the disk byte cost, or `Memory`, at the memory byte cost.
+    pub raw_data_medium: StorageMedium,
+    /// The bytes one raw row takes where it is kept, as measured; `None` (default):
+    /// its decoded width. Not finite or not positive: refused (bad input).
+    pub raw_data_bytes_per_row: Option<f64>,
 }

crates/cost/src/plan/cost.rs

-/// Cost model 1's cost per second of keeping `bytes` of raw data on disk.
-pub fn raw_data_disk_cost_per_second(bytes: f64, settings: &CostInputs) -> Option<f64>;
+/// Cost model 1's cost per second of keeping `bytes` of raw data where the data plane
+/// keeps it (`raw_data_medium`); `None` under cost models 2 and 3. Stage 3 prices with it.
+pub fn raw_data_cost_per_second(bytes: f64, settings: &CostInputs) -> Option<f64>;

The function was renamed because it no longer prices disk only.

crates/cost/src/node/cost_terms.rs

 /// A named per-unit constant of the cost formulas (stays). JSON: snake_case.
 pub enum CostConstant {
+    /// A row a scan reads (`SCAN_OPERATIONS_PER_ROW`, 1).
+    ScanOperationsPerRow,
+    /// A row a filter or a scan's predicates read (`FILTER_OPERATIONS_PER_ROW`, 1).
+    FilterOperationsPerRow,
+    /// A value each such row is compared with (`FILTER_OPERATIONS_PER_ROW_PER_COMPARED_VALUE`, 2.4).
+    FilterOperationsPerRowPerComparedValue,
     TimeRangeOperationsPerRow,
     OperationsPerGroupPerRawBatch,
     ChainOperationsPerArrivingRow,
     HashAggregateOperationsPerRow,
     HashAggregateOperationsPerFurtherKey,
     AggregateMeasureOperationsPerRow,
     SortOperationsPerRowPerLevel,
     DdsketchUpdateOperationsPerRow,
     KllUpdateOperationsPerRow,
     ExactUpdateOperationsPerRow,
     CounterUpdateOperationsPerRow,
     CarriedLabelOperationsPerRowPerLabel,
     KmvUpdateOperationsPerRow,
     KmvUpdateOperationsPerComparedHash,
     KmvMergeOperationsPerHash,
     KmvMergeOperationsPerComparedHash,
     ExactDistinctOperationsPerRow,
     ExactDistinctOperationsPerValueDoubling,
     ExactDistinctOperationsPerRowAtFullValueMiss,
     ExactDistinctOperationsPerRowAtFullPairMiss,
     ExactDistinctOperationsPerInsertedValue,
     ExactDistinctOperationsPerInsertedPair,
     SketchUpdateOperationsPerCounter,
     CounterMatrixUpdateOperationsPerCounter,
     UnivmonUpdateOperationsPerCounter,
     CmsHeapOperationsPerEstimate,
     CmsHeapOperationsPerEstimatedCounter,
     CountSketchHeapOperationsPerEstimate,
     CountSketchHeapOperationsPerEstimatedCounter,
     SketchAllocationOperationsPerCounter,
     ExactMergeOperationsPerState,
     ExtremumMergeOperationsPerState,
     CounterMergeOperationsPerState,
     DdsketchMergeOperationsPerState,
     KllMergeOperationsPerState,
     KllMergeOperationsPerInputByte,
     KllMergeOperationsPerMergedByte,
     MergeOperationsPerOutputGroup,
     SketchMergeOperationsPerByte,
     CounterMatrixMergeOperationsPerState,
     CounterMatrixMergeOperationsPerCounter,
     HeapMergeOperationsPerResidentCounter,
     KllEstimateOperationsPerByte,
     KllEstimateOperationsPerUnsortedItem,
     SketchEstimateOperationsPerGroup,
     HeapReadOperationsPerGroup,
     HeapReadOperationsPerResidentCounter,
     OutputRowOperationsPerGroup,
     SketchChainEmitOperationsPerState,
     ExactChainEmitOperationsPerState,
     KllMergeOperationsPerOutputGroup,
 }

calibration/measured-cost-files/ (new file format: a CostInputs JSON per machine key)

+{
+ "frozen_calibration_factor": 1.0,
+ "data_plane_execution": {"view_window_cache": {"idle_ms": 60000, "file_span_ms": 900000},
+                          "raw_data_medium": "Memory", "raw_data_bytes_per_row": 32.0},
+ "measured_operation_costs": {"ns_per_ingested_sample": 460.0, "operators": [
+   {"operator": "Scan", "phase": "query_time", "ns_per_unit": 41.0, "ns_per_series": 8700.0},
+   {"operator": "SummaryMerge", "phase": "query_time", "exact": "Count", "ns_per_unit": 200.0},
+   ...one entry per measured (operator, phase, family); full list in the file and its README]}
+}

Usage. The user writes the SIL intent above. They pass the data facts (data.json: auth with series_count 100,000 at 10,000 rows/s) and the measured cost file as the deployment's CostInputs. Everything below is checked in crates/planner/tests/measured_cost_file.rs.

// The deployment's measured cost file: what its data plane measured on this machine.
let cost_inputs: CostInputs = serde_json::from_str(&std::fs::read_to_string(
    "calibration/measured-cost-files/x86_64-intel-xeon-e5-2683-v3-56t-registered-ddr4.json")?)?;
// The planner's models with the deployment's capabilities (raw data kept) and those costs.
let models = PlanningModels::builtin()
    .with_deployment_capabilities(&DeploymentCapabilities { raw_data_retained: true, ..Default::default() })
    .with_cost_inputs(&cost_inputs);
// Full intent planning: with and without a lightcone; Stage 3 prices every candidate node.
let (plan, report) = plan_intents(&intents, &catalog, &data, models, &options).await?;

Inside Stage 3, node_usage_and_cost_terms reaches each new interface:

  • Query-time scans: auth's q2 scan finds the Scan entry: 6,000,000 rows × 41 ns + 100,000 series (series_visited) × 8,700 ns = 1,116 ms. Its IN-list is part of the measured scan time; without a file it would be charged per compared value.
  • The lightcone's chain: it emits states only for the 63,212 groups a 10 s window reaches (groups_reached_share).
  • On demand: the plan keeps 6,000,000 × 32 B of raw auth as memory (raw_data_medium).

The user gets back plan.lightcone_query_indices == [2], which keeps the (host, user) counts, at cost 95.24/s against 273.79 for planning each query alone. In report.predicted_usage.per_query, q1 is 33.3 ms and q2 265 ms.

Algorithm changes

Scan and filter CPU (item 3)

  • Problem. A scan charged 1 abstract op per row and nothing for its predicates. A filter charged 1 op per row whatever its predicate: a 100-value IN-list cost the same as TRUE.
  • Before / after. Before: Scan = rows; Filter = rows (PassThrough). After (filter_terms_per_row, compared_values): Scan = rows × ScanOperationsPerRow + rows × (FilterOperationsPerRow + compared values × FilterOperationsPerRowPerComparedValue) when it has predicates. Filter = input rows × the same filter terms. Compared values count an IN-list's values, one per comparison, null test or subquery, and sum over AND/OR.
  • Correctness. The terms equal the formula CPU (terms_reproduce_the_formula_cpu_of_every_costed_node, a_scan_charges_*, a_filter_charges_*). A predicate-free scan and a TRUE filter cost what they did.
  • Complexity. O(predicate size) per node.
  • Measurements. On the reference executor (2,000,000 rows, batches of 10,000): scan 0.2 ns/row; IN-list of 1 / 10 / 100 values 3.5 / 25.7 / 244 ns/row, i.e. 1 + 2.4 per value.
  • Limits. The executor compares an IN-list linearly. Long bindings (the rca q2 binding is estimated at hundreds of values) therefore cost a lot under the formulas: rca's query-at-a-time formula cost rises from 148 to 873 per second. A deployment's file replaces this with its measured scan.

Series visited (item 2)

  • Before: a measured scan cost rows × ns_per_unit.
  • After: a measured scan costs rows × ns_per_unit + min(declared series, rows read) × ns_per_series.
  • Correctness: T2 checks 1,116 ms at 100,000 series and 333 ms at 10,000.
  • Limits: it uses the declared series, without the IN-list's kept series until the restack.

Raw data medium (item 4)

  • Before: raw rows kept for query-time scans were always disk bytes.
  • After: they are memory or disk by raw_data_medium, sized at raw_data_bytes_per_row. The same rule applies in plan_cost and in Stage 3's cost, peak-memory and disk quantities.
  • Correctness: T5 checks that the objective equals plan_cost, that disk is 0, and that memory is +1,920,000 bytes for 60,000 rows.

Groups a window reaches (item 5)

  • Before: a chain window held, emitted and kept one state per group.
  • After: it holds G·(1 − e^(−rows/G)) states (expected_distinct_values). This applies to emitted states, sealed/open/cached memory, and SummaryMergeWindows' merged and emitted states.
  • Correctness: T6 checks 6,321.2 states/s and 61 windows × 63,212 states for auth; dense chains are unchanged.
  • Limits: rows are assumed uniform over groups. The measured Zipf data reaches about 25,000 of the 100,000 groups. A declared skew (item 6's fact) would refine it.

Decisions and open questions

Needs reviewer decision

  1. Where measured cost files live. This PR uses calibration/measured-cost-files/<machine key>.json. The key is CPU architecture, model, logical cores and memory type; hostnames are never used. Alternative: tools/cost-inputs/.
  2. The slower machine's file. It is the measured one at 1.25x in every measured time and in frozen_calibration_factor. This matches 1.22-1.28x per operator class from one run of 2 of the 3 intents, plus drill_cnt (1.05x on its q2 scan). Alternative: wait for its own fit from the second machine's full matrix.
  3. IN-list cost per compared value under the formulas. Item 3 charges linearly, as the reference executor compares. Alternative: also make the executor's IN-list a hash set (follow-up) and charge per row.

Decided

  • 2026-12-03 (user): all six calibration changes approved. Items 1-5 are here; item 6 is on the IN-list branch.
  • 2026-12-03: deployment numbers come only from the measured cost file, never as planner constants. The reference executor's constants change only where they were placeholders (item 3).

Verification

Tests were run on a build host (cargo test --workspace --no-fail-fast). Every failure that remains is one of the base branch's own failing IN-list tests (same names at 01ff90c37).

scope result newly failing vs base notes
asap-cost lib 145+ passed; the IN-list U-tests fail as on base none new: T2 (2), item 3 (3), T6 (2) pass
asap-planner --test planner measured_cost_file: 4 passed, 1 ignored (T4) none sil_intents S-tests fail as on base
asap-planner-cli --test planner_cli inlist_selectivity E-tests fail as on base none anchors re-pinned: E6, lowest_mean_latency (3 pins)
asap-integration-tests --test integration stage3_objective 23 passed none T5
asap-types lib bounds T1-T4 fail as on base none
corpus snapshots (release, --ignored) pass after regeneration none 10 o11y_bench + 5 sketch snapshots; numbers only, no plan changed
cargo fmt --check, cargo clippy -D warnings (cost, stage3, planner, planner-cli, integration-tests, devtools) clean the existing unused-dependency warnings are unchanged

New tests:

  • T1: the measured cost files validate; the slower machine's is the measured one at 1.25x; every node whose operator a file measures is priced from it.
  • T2: a measured scan charges each series it visits.
  • Item 3: a scan charges each row and its predicates per compared value; a filter the same.
  • T3: q1 of drill_cnt/dash/rca is predicted within 1.5x of measured in every mode; full intent keeps dash's and rca's state and predicts its upkeep within 1.5x.
  • T4 (ignored until item 6): drill_cnt keeps the lightcone once top-k bindings hold their heavy rows.
  • T5: raw rows kept in memory are charged as memory.
  • T6: a chain emits and keeps states only for the groups its windows reach; dense chains are unchanged.

End-to-end, all three intents. All modes were re-planned with and without the file and compared with measured E6 runs. Measured cost = plan-dependent CPU (precompute, persist and query threads) + raw/view memory at the cost-model-1 price, mean of 2 runs.

intent x1 mode measured CPU / cost formulas CPU / cost with file CPU / cost chooses measured-cheaper?
drill_cnt on demand 165-170 / 191-196 174 / 192.9 246 / 273.8
drill_cnt full (lightcone) 52.2 / 61.3 101 / 149.6 72 / 95.2 yes (both)
dash on demand 63-64 / 91-92 79 / 80.1 108 / 134.7
dash full (lightcone) 10.7 / 12.0 4.5 / 5.5 8.5 / 9.2 yes (both)
rca on demand 152-153 / 204-205 871 / 872.9 209 / 245.4
rca full (q3 lightcone) 130.6 / 156.9 856 / 858.8 183 / 209.6 yes (both)

With the slower machine's file, the choices are the same: drill_cnt 113 vs 335, dash 11.4 vs 162, rca 256 vs 298. Measured on that machine: 74 vs 208, 14.5 vs 107, 192 vs 247.

Lightcone points, planner with the file. The base has no IN-list selectivity yet, so these use today's data-plane behaviour, where a dependent scan reads every row. The lightcone is chosen at every point:

point lightcone / on demand
x0.1 17.3 / 87.3 = 0.20
x1 0.35
x10 191 / 1,180 = 0.16 (3ef265d dropped the lightcone here)
q2 over 5 min 0.46
q2 over 1 h 0.11

After label pushdown and true selectivity, the analysis model with the file's constants predicts both sides of break-even: x0.1 0.20, x1 0.94, 5 min 1.75, 1 h 0.23, x10 3.68. The planner reproduces these once the IN-list branch and item 6 land.

Screenshots: not applicable.

Follow-ups

  • Restack onto the IN-list implementation: switch item 2 to the kept series, and resolve the expected conflicts in usage/mod.rs's Scan and Filter arms. Notes are in the coordination file.
  • Item 6 (IN-list branch): a declared skew for top-k bindings. Item 5 should then read it too.
  • Executor: an IN-list as a hash set beyond a few values, then refit FILTER_OPERATIONS_PER_ROW_PER_COMPARED_VALUE.
  • Refit the slower machine's file from its full E6 matrix, and the ingest-side entries (4 points, 3 parameters) from a dedicated calibration run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi

zzylol and others added 16 commits December 3, 2026 23:15
…med scan/filter constants, raw rows in memory and active groups per window

Test-first phase of the cost calibration (items 2-5 of the calibration
proposal; item 1's cost file and the e2e tests follow in their own commit):

- T2: a measured Scan entry's `ns_per_series` charges each series the scan
  visits (10 min of `auth`: 6,000,000 rows x 41 ns + 100,000 series x
  8,700 ns = 1,116 ms); a negative one is refused.
- item 3: a scan charges `ScanOperationsPerRow` per row read and its
  predicates `FilterOperationsPerRow` + `FilterOperationsPerRowPerComparedValue`
  per value compared; a Filter the same (reference executor: 1 + 2.4 ns
  per compared value per row). U1's last assertion now expects the
  IN-list's compared values on top of a TRUE filter.
- T5: `raw_data_medium` Memory charges a query-time scan's retained raw
  rows as memory at `raw_data_bytes_per_row`, none on disk, objective =
  plan_cost.
- T6: a chain emits and keeps states only for the groups its windows
  reach (100,000 rows over 100,000 groups: 63,212 per window); a dense
  chain is unchanged.

Signatures only, behaviour kept: `OperatorCost::ns_per_series`,
`UnitPrice::ns_per_series`, `DataPlaneExecution::{raw_data_medium,
raw_data_bytes_per_row}`, `CostConstant::{ScanOperationsPerRow,
FilterOperationsPerRow, FilterOperationsPerRowPerComparedValue}` and their
`operations_per_unit` constants are added but not read yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…t's measured cost file

T1, T3, T4 of the cost calibration over three SIL intents whose runs were
measured on one machine (fixtures: SIL text, tables, data facts):

- T1: each measured cost file validates; the slower machine's is the
  measured machine's at 1.25x (every measured time and the formula scale);
  every node whose operator the file measures is priced from it.
- T3: binding-free queries (drill_cnt q1, dash q1, rca q1) predicted
  within 1.5x of their measured medians; full intent keeps dash's and
  rca's shared state and predicts its upkeep within 1.5x of measured.
- T4 (ignored): drill_cnt keeps the lightcone once a top-k binding is
  costed at its heavy values' rows (needs item 6, IN-list branch).

The cost files themselves come with item 1's commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… (ns_per_series)

Item 2 of the cost calibration. A deployment whose store keeps raw rows by
series pays per series a scan finds and decodes, beside per row:
`OperatorCost::ns_per_series` (default 0) is charged per series visited,
each series its sources declare and at most one per row read. Validated
like every other price; summed over an aggregate's measure entries.

Example (T2): 10 min of `auth`, 6,000,000 rows, at 41 ns per row and
8,700 ns per series: 1,116 ms over 100,000 series, 333 ms over 10,000
(246 ms per row alone). The test's 10,000-series data now keeps the
source's 10,000 rows per second (sample interval 1 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… compared value

Item 3 of the cost calibration. The abstract 1-operation-per-row charges
of a scan and a filter become named, measured constants:

- `SCAN_OPERATIONS_PER_ROW` (1): the reference executor's in-memory store
  hands batches on whole, 0.2-1.9 ns per row (batches of 10,000 to 1,000
  rows, 1,000 to 100,000 series: no per-series cost there; a deployment's
  per-series cost comes from its measured file).
- `FILTER_OPERATIONS_PER_ROW` (1) and
  `FILTER_OPERATIONS_PER_ROW_PER_COMPARED_VALUE` (2.4): a filter, and now a
  scan's predicates too (charged 0 before), per row read and per value
  each row is compared with. Measured: IN-list of 1 / 10 / 100 values
  3.5 / 25.7 / 244 ns per row (2,000,000 rows in batches of 10,000).

`compared_values` counts an IN-list's values, one per comparison, null test
or subquery membership, summed over AND/OR; a literal compares nothing, so
a `TRUE` filter costs what it did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…lane keeps them

Item 4 of the cost calibration. `DataPlaneExecution::raw_data_medium`
(default `Disk`) says where the data plane keeps the raw rows its
query-time scans read, and `raw_data_bytes_per_row` (default `None`: the
decoded width) what one row takes there, as measured. In memory they are
charged as memory (average and peak, memory byte cost) instead of disk,
in `plan_cost` and in Stage 3 alike: `raw_data_disk_cost_per_second` is
renamed `raw_data_cost_per_second` and prices by the medium; Stage 3's
peak-memory and disk quantities take the raw part by the medium.

T5, revised: the scanning plan of `count_over_time(m[1m])` every minute
keeps 60,000 rows, 1,920,000 bytes, on disk by default and in memory for
the in-memory deployment (none on disk). At the memory price that scan is
no longer the cheapest, so the test costs the default-selected scanning
plan for both deployments and checks that Stage 3 then selects a plan
keeping no raw data, its objective equal to its plan_cost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…he groups its rows reach

Item 5 of the cost calibration. A tumbling-window chain was charged a state
per group in every window, emitted and kept, though a window holds a state
only for the groups its rows reach. Now each window holds
`expected_distinct_values(rows per window, groups)` of them (rows spread
uniformly over the groups): the chain's emitted states, its windows'
memory (sealed, open, cached) and a `SummaryMergeWindows`' merged and
emitted states and memory scale by that share. Dense chains are
unchanged (10,000 rows over 1,000 series reach all but 0.005%).

Example (T6): `auth`'s 10 s windows hold 100,000 rows over 100,000
(host, user) groups, 63,212 reached: 6,321.2 states emitted per second,
not 10,000, and 61 windows of 63,212 states kept. Rows are assumed
uniform over the groups; a declared skew (with item 6) would lower it
further (about 25,000 under the measured Zipf data).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
Item 1 of the cost calibration: the deployment's measured costs as data,
supplied through `CostInputs` (no planner constant changes).
`calibration/measured-cost-files/<machine key>.json` is a CostInputs file:

- measured_operation_costs: query-time Scan 41 ns per row + 8,700 ns per
  series (TimeRange inside it), ingestion-time Scan 150 ns per arriving
  row, chain updates and window closes, merges (200 ns per exact state,
  1,200 per DDSketch state), finalize 300 ns per group, DDSketch estimate,
  ns_per_ingested_sample 460;
- data_plane_execution: the data plane's view window cache (60 s idle,
  15-minute files) and raw rows kept in memory at 32 bytes per row;
- frozen_calibration_factor 1.0.

Fitted on 2026-12-03 from 60-round runs of three SIL intents in three
planning modes on one machine (README: each entry's data points). The
second machine's file is the same table at 1.25x (measured 1.22-1.28x in
every operator class), the formula-priced nodes scaled 1.25x too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
Values pinned on today's costs that the cost calibration changes, each
explained:

- U13 (IN-list anchor): an undeclared IN-list still keeps every row; its
  filter and scan now cost that plus evaluating it (100,000 x 10 compared
  values; a scan's 6,000,000 rows x (1 + 10 x 2.4)).
- E6 (IN-list anchor): today's drill_cnt costs 177.9132 / 169.2572 /
  140.9361 become 192.9132 / 149.6450 / 125.8274: q2's scan evaluates its
  10-value IN-list on its 6,000,000 rows (+15.0/s); a chain over `auth`
  keeps and emits states only for the 63% of groups its windows reach.
- lowest_mean_latency pins: distinct-two-forms 36.7112 -> 36.4823 ms (10,000
  series at 15 s: a 10 s window reaches 49% of them, fewer states to emit
  in the refresh), seed-862 709.8367 -> 709.8338, typical dashboard
  847.2063 -> 847.0459 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…es too

With the measured scan prices the planner may build a summary chain at
query time (dash q2 in query-at-a-time mode); the files measured chains
only at ingestion, leaving that node on the formulas. Add query-time
chain entries at the same per-row update (exact 55 ns, DDSketch 116 ns;
1.25x on the slower machine), so every node of the measured intents whose
operator the files measure is priced from them (T1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… test

clippy::wildcard_enum_match_arm (denied in usage/mod.rs) on item 2's match,
and rustfmt on the measured cost file test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… whose costs items 3 and 5 move

No selected plan changes: every difference is a cost, CPU, memory or detail
number of the same DAG.

- o11y_bench q02, q05, q06, q12, q18, q19, q21, q22, q23, q25: each scan's
  label matcher (e.g. `{job="order-service"}`) is now evaluated per row
  read (1 + 2.4 operations per compared value), e.g. q12's scan 5.9 ->
  9.4 us per evaluation, cost 0.5572 -> 0.5607 per second.
- sketch plans chains-10m-5m-3m-10s-mvp, distinct-over-time-5pct-raw-retained,
  random-mixed-seed-862-long-w01-q3-mvp, seed-862-w01-q3-q8-mvp and
  seed-862-w02-q2-q7-mvp: a chain's window emits and keeps states only for
  the groups its rows reach, e.g. 667 rows per 10 s window over 10,000
  series reach 4,866 of them: 486.6 states emitted per second, not 1,000.

Regenerated with UPDATE_SNAPSHOTS=1 (release, --ignored).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… only the series its predicates select

Item 2 on the IN-list rule: a query-time scan's series visited are the
declared series times the share its label predicates keep (kept values
over declared values per restricted column), at most one per row read;
`a_measured_scan_visits_only_the_series_its_predicates_select` checks 100
of 100,000 series under `host IN (10 of 10,000)`.

Tests that now meet the IN-list rule: the scan-predicate terms test reads
every arriving row at ingestion time (query time reads the selected
series' rows); U5's ingestion scan costs its predicate on every arriving
row; Q5-E2's lower bound follows item 5's cheaper chain (78.37/s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
… readers see them, series only at query time

Review of #1555 (important findings):

- I1: a window's groups reached now follows how its rows spread
  (`GroupReach`): periodic series (`sample_interval` declared) reach
  min(1, rows/groups) - 10,000 series every 15 s in 10 s windows hold
  2/3 of them, a window equal to the interval all of them; a key column
  with a declared Zipf skew (item 6's `zipf_exponent_per_label`) reaches
  Σ g(1 - e^(-rows p_i/g)) - 100,000 rows over 10,000 Zipf(1) hosts of 10
  users reach 28.1% of the (host, user) groups; otherwise rows fall at
  random (1 - e^(-rows/groups)).
- I2: the share is the chain's and window merge's output: its rows and
  bytes are one window's states (readers, stored files and memory see
  the same count); `OutputFacts::window_groups` carries every group and
  the reach so a window merge sizes its wider window.
- I3: a measured scan's per-series charge applies only at query time,
  over the series its predicates select (none at ingestion).
- I4: T4 runs: with the measured file and the declared host skew,
  drill_cnt's full intent keeps the (host, user) counts, below the
  on-demand plan, and the formulas alone do not keep them.

The measured intents' fixtures now declare the generator's skews (hosts
Zipf 1.0; services Zipf 0.8).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…ted on those counts); window share scales memory, stored bytes and emits

Revises I2 of the review: scaling the chain's output edge broke Stage 3's
per-family folded-rows invariant and the MILP = plan_cost check. The
measured SummaryMerge price was fitted against the planner's all-group
state counts, so readers keep charging every group; the window's memory,
stored file bytes and emitted states hold only the groups its rows reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…h too; re-pin anchors after I1

- How a window spreads its rows (`GroupReach`) is read from the node's
  own output key columns and its sources' facts, not its producer's
  schema, so a candidate costs the same in Stage 3 and plan_cost.
- A window merge's wider window reaches the groups the rows of its
  narrower windows reach (same reach), its merged and emitted states and
  memory scaled by it; `OutputFacts::window_groups` is gone (unused).
- With periodic series reaching every group again (I1), the anchors move
  back: E6 192.9132 / 169.4972 / 141.1861 (each IN-list evaluated per row
  read), distinct-two-forms 36.7112, seed-862 709.8367, typical
  dashboard 847.2063; Q5-E2 98.22/s, bound 99.
- dash/rca fixtures declare no service skew: with it Stage 3's objective
  and plan_cost differ by 3e-6 relative in dash full intent, also with
  this branch's reach disabled (reported on the IN-list track).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…dic series reach rows/groups of them)

Numbers only, no plan changes. Against the base, only chains-10m-5m-3m-10s
still moves on item 5: 10,000 series every 15 s in 10 s windows reach
2/3 of them (6,667 states per window, not every series); the other four
return to the base's numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
@zzylol
zzylol force-pushed the feat/backend-cost-calibration branch from 672e7fe to b64df3f Compare December 4, 2026 03:30
zzylol and others added 2 commits December 4, 2026 06:01
…and, not lightcone query indices

Under cost model 1 the full intent may be planned once with its dependent
queries reading kept state directly, leaving `lightcone_query_indices`
empty by design. T3 and T4 now check that the full-intent plan keeps
state the on-demand plan does not (more ingestion-time nodes) and costs
less than it; T4 also checks that the formulas alone keep no such state.
Holds with and without lightcone queries reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the eval build, rca's full intent keeps two chains: the measured q3
chain over `node_metrics` (predicted 1.5 + 4.45 + 0.78 = 6.7 ms/s,
measured 7.9) and a per-(service, node) DDSketch chain over `requests`
for q2 (3.0 + 6.2 + 1.5 = 10.7 ms/s), which no measured run kept. The
17.45 ms/s total compared both with the one chain's 7.9: not a model
over-prediction (each node is priced from its measured entries: scan
150 ns/row, DDSketch 116 ns/row, 3.9 us per state emitted). T3 now sums
the ingestion-time nodes fed by the measured tables' scans (dash:
`requests`, `errors`; rca: `node_metrics`).

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

Labels

cost-model Cost formulas, statistics, ranking, and selection enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant