Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't workingcost-modelCost formulas, statistics, ranking, and selectionCost formulas, statistics, ranking, and selection
Description
Problem, by example
quantile_over_time(0.99, latency[1h]) with a 1% rank target (δ = 0.01), over 1,000 gauge series sampled at 1 Hz, evaluated every 10 s, raw_data_retained: false, default CostInputs, with the measured unit costs of #1355. Stage 2 offers two stored KLL candidates of the same shape (SummaryTumblingWindowChain(10 s) → TimeRange(1h) → SummaryMerge → SummaryEstimate) that differ only in k:
| Candidate | Predicted cost/s | Predicted query ms | Measured query CPU per evaluation | Measured cost/s | Worst rank error |
|---|---|---|---|---|---|
| KLL k = 1,404 (selected) | 295.66 | 2,559 | 5,734 ms | 589 | 0.37% |
| KLL k = 547 | 295.66 | 2,559 | 2,040 ms | 240 | 0.64% |
- Today: both candidates cost exactly the same, so the MILP picks one arbitrarily. Here it picks k = 1,404 and pays 2.45× the measured cost of k = 547. The same tie costs 1.61–2.05× in three more cells of the same grid (1h × 1 Hz × 60 s, 1h × 10 Hz × 10 s, 5m × 10 Hz × 10 s; all rank target, raw data not kept).
- Expected: the planner charges the larger
kmore for its merge and estimate, and picks k = 547 (or a plan measured within 1.05 of it).
Measured on a release build, one pinned core, synthetic exponential latency data; the cost is cost model 1's illustrative prices applied to measured CPU and memory.
Why it happens
merge_operations_per_state(crates/cost/src/node/operations_per_unit.rs) charges every KLL state the flatKLL_MERGE_OPERATIONS_PER_STATE= 7,000, whateverk.KLL_ESTIMATE_OPERATIONS_PER_GROUP= 35,000 is flat too.- The state bytes are also equal: each 10-row window holds far fewer items than either
k, sosketch_shapecharges both the same bytes. - The executor's merge cost grows with the items the merged sketch holds, which grow towards
k: merging 360 windows per series into one sketch takes 1.7 ms per series at k = 547 and 4.8 ms at k = 1,404 (1.7 s against 4.8 s per evaluation over 1,000 series). Over the 4 cells, the largerkmerges 1.9–2.8× slower.
Proposal
- Charge a KLL merge by the items the merged (output) state holds, min(KLL capacity at
k, rows merged so far), with a measured per-item constant; charge the estimate by the same item count. - Alternative: break exact cost ties toward the smaller sketch parameter. This fixes the tie but not the magnitude, so a larger
kwould still be under-charged against other plan kinds.
Scope and acceptance
- In scope: the KLL
SummaryMergeandSummaryEstimateCPU charge. - Acceptance: a cost test where the k = 1,404 candidate of the example is charged more than the k = 547 one for the same merge, and the four cells above select k = 547 or an arm measured within 1.05.
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), Default unit costs: shared-scan instant reads, carried labels and small sketches are still misranked #1359 (other small-sketch constants), Five-query mixed workload: duplicate widened Scan group, k=567 picked over k=345, shared-node rate overcharge #1126 (an earlier k = 567 over k = 345 pick).
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcost-modelCost formulas, statistics, ranking, and selectionCost formulas, statistics, ranking, and selection
Activity