Repository navigation
Open
Labels
cost-modelCost formulas, statistics, ranking, and selectionCost formulas, statistics, ranking, and selectionenhancementNew feature or requestNew feature or request
Description
Problem, by example
count by (job) (m) and sum by (job) (count_over_time(m[1m])), both every 60 s, over 1,000 gauge series m sampled every 1 s (arriving at 1,000 rows/s, raw data kept, loose absolute targets), with the default CostInputs after #1355:
| Plan | Shape | Predicted cost/s | Measured query CPU per evaluation (p50) |
|---|---|---|---|
| Exact query-time lowering | two scans: Scan(1 s) → TimeRange(1s, instant) → Aggregate by (job); Scan(60 s) → TimeRange(60s) → per-series Count → Aggregate by (job) |
0.04600 | 17.9 ms |
| Selected | one shared Scan(60 s): TimeRange(60s) → per-series Count → Aggregate by (job), and TimeRange(1s, instant) → Aggregate by (job) over the same scan |
0.04590 | 20.7 ms (0.87× of exact) |
Stage 3 predicts the two plans equal, but the selected plan measures 13% slower. (Measured at #1355's head 008704da2, release, one pinned core, 600 s of evaluations; on main the selected plan measured 0.84×.)
Two more gaps of the same kind, from #1355's measurements:
- A hash aggregate that carries an extra label per row:
sum by (job) (sum_over_time(latency[1m]))at 1 Hz, every 10 s. The exact per-series aggregate measures 68 ns/row with ajoblabel and 27 without, but is charged 27. It accounts for most of the remaining misranks in fix(cost): charge each operation the executor's measured time, so a sketch plan is no longer predicted cheaper than a faster exact plan #1355's 85-case grid (exactsum_over_time/count_over_timewithsum by (job)over 1m and 5m windows). - Small query-time sketches: a mixed workload with 5m windows (300 rows per series) selects exact quantiles measured at 126.0 ms against 117.6 ms for main's query-time sketch plan (still 1.03× faster than exact): the DDSketch update and merge constants, measured on 3,600-row states, over-charge small ones a little.
Why it happens
- The instant
TimeRangeover the shared 60 s scan reads 60,000 rows to keep 1,000, butestimate_operatorcharges a time range by the rows it keeps (output.rows × TIME_RANGE_OPERATIONS_PER_ROW,crates/cost/src/node/analytical.rs), so the shared scan looks free for the instant reader. This is the likely cause; it has not been measured per node. hash_aggregate_operations_per_row(crates/cost/src/node/operations_per_unit.rs) charges 15 per grouping key and 12 per measure, and nothing for the columns the group carries.- The DDSketch and KLL constants are single numbers per row or state, not a function of the state's rows.
Proposal
- Charge a time range by the rows it reads (its input) when it keeps fewer than it reads, or measure both and charge read + kept.
- Add a per-carried-column term to the hash aggregate (measure it per label).
- Measure the sketch update/merge constants at small state sizes and interpolate by rows per state, or let the per-machine measured table ([Design] asap_run: one binary to execute plans, calibrate measured unit costs per machine, and bench predicted vs measured #1317) cover it.
Scope and acceptance
- Acceptance:
default_cost_plan_ranking::predicted_cpu_orders_exact_and_alternative_plans_as_measuredgains the three cases above (with the measured numbers) and passes.
Related
- fix(cost): charge each operation the executor's measured time, so a sketch plan is no longer predicted cheaper than a faster exact plan #1355 (measured unit costs), [Design] Price CPU and latency from a measured cost table per state family (scan, update, merge), not built-in unit costs #1314, [Design] asap_run: one binary to execute plans, calibrate measured unit costs per machine, and bench predicted vs measured #1317.
Metadata
Metadata
Assignees
Labels
cost-modelCost formulas, statistics, ranking, and selectionCost formulas, statistics, ranking, and selectionenhancementNew feature or requestNew feature or request
Activity