You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement an analytical planner cost estimator that derives CPU work, memory/state usage, disk or object-store scan I/O, and related costs from algorithm complexity plus workload/data characteristics. This gives ASAPPlanner a principled modeled estimate when compatible empirical benchmark evidence (#322) is unavailable.
Motivation
The current DAG annotations can use RelativeStructuralUnits, which primarily reflect plan structure. That proxy cannot explain cases where a plan has more operators but is substantially cheaper in practice—for example, replacing a raw aggregation over a large input with a compact sketch update/readout path.
The planner needs resource-aware mathematical estimates rather than treating every DAG node as roughly equal. Unknown inputs must remain unavailable; the model must not invent row counts, cardinalities, update rates, state sizes, or hardware throughput.
Scope
Resource dimensions
Estimate at least:
CPU work for build, update, merge, raw aggregation, and summary readout;
peak and retained memory/state size;
disk/object-store bytes scanned and I/O operations where applicable;
network/materialization bytes where a plan crosses an explicit boundary; and
recurring rates versus finite-horizon/one-shot totals without mixing their units.
Analytical inputs
Use explicit, unit-tagged inputs where relevant:
input rows and bytes;
distinct/group cardinality and distribution/skew descriptors;
storage scan bandwidth/latency and CPU throughput calibration; and
an explicit evaluation horizon when rates and one-shot work must be combined.
Complexity-to-cost formulas
Define versioned formulas for the currently supported exact and approximate families. Examples include:
raw scan/aggregation: O(input_rows) CPU plus input_bytes scanned;
grouped exact aggregation: state proportional to group cardinality and accumulator width;
CMS/Count Sketch: update CPU proportional to depth and state proportional to width * depth * counter_width;
KLL: state/update/readout estimates derived from k and compaction behavior;
HLL: state proportional to register count and readout proportional to registers;
merge costs proportional to state size and merge fan-in; and
shared summaries counted once for state/build/maintenance while consumer readout costs remain per consumer.
Asymptotic notation alone is insufficient for plan comparison. Each supported formula must produce a dimensional estimate (operations, bytes, or time/rate after applying an explicit calibration), carry model version and inputs, and document constants/assumptions.
Planner integration
Add a public analytical CostModel implementation or provider.
Fail closed to Unavailable when required statistics or calibration inputs are missing, invalid, stale, or incompatible.
Ensure candidate selection and displayed annotations use the same cost calculation rather than independent formulas.
Initial demonstration
Include a generated query/workload in which a sketch aggregation has more DAG nodes than the raw aggregation but is estimated cheaper because it processes/retains less state or avoids repeated raw scans. The exported viewer comparison should identify exactly which CPU, memory, and scan terms produce the positive benefit; no hand-edited JSON values.
Acceptance criteria
A design/reference table defines formulas, units, assumptions, and required inputs for every initially supported family.
Tests validate formulas against hand-computed examples and cover monotonicity in rows, bytes, groups, consumers, and sketch parameters.
CPU, memory, and scan costs remain separate dimensions until an explicit, versioned calibration converts them to a comparable objective.
Shared state and shared scans are counted once; per-consumer readouts are counted per effective consumer.
Rate and one-shot values cannot be combined without an explicit horizon.
Missing or non-finite inputs produce Unavailable or a typed error, never zero or a fabricated estimate.
At least one planner choice changes when analytical resource inputs change.
dag_export and the viewer show a generated positive sketch-vs-raw benefit with complete inputs and model provenance.
Summary
Implement an analytical planner cost estimator that derives CPU work, memory/state usage, disk or object-store scan I/O, and related costs from algorithm complexity plus workload/data characteristics. This gives ASAPPlanner a principled modeled estimate when compatible empirical benchmark evidence (#322) is unavailable.
Motivation
The current DAG annotations can use
RelativeStructuralUnits, which primarily reflect plan structure. That proxy cannot explain cases where a plan has more operators but is substantially cheaper in practice—for example, replacing a raw aggregation over a large input with a compact sketch update/readout path.The planner needs resource-aware mathematical estimates rather than treating every DAG node as roughly equal. Unknown inputs must remain unavailable; the model must not invent row counts, cardinalities, update rates, state sizes, or hardware throughput.
Scope
Resource dimensions
Estimate at least:
Analytical inputs
Use explicit, unit-tagged inputs where relevant:
width,depth,k, HLL precision, reservoir size, Hydra dimensions, etc.);Complexity-to-cost formulas
Define versioned formulas for the currently supported exact and approximate families. Examples include:
O(input_rows)CPU plusinput_bytesscanned;width * depth * counter_width;kand compaction behavior;Asymptotic notation alone is insufficient for plan comparison. Each supported formula must produce a dimensional estimate (operations, bytes, or time/rate after applying an explicit calibration), carry model version and inputs, and document constants/assumptions.
Planner integration
CostModelimplementation or provider.CostAnnotationvalues with units, inputs, model version, baseline, delta, and benefit ratio for DAG export/viewer ((dev-tools) Export and visualize planner cost/benefit annotations #286).ModeledandMeasuredprovenance distinct.Unavailablewhen required statistics or calibration inputs are missing, invalid, stale, or incompatible.Initial demonstration
Include a generated query/workload in which a sketch aggregation has more DAG nodes than the raw aggregation but is estimated cheaper because it processes/retains less state or avoids repeated raw scans. The exported viewer comparison should identify exactly which CPU, memory, and scan terms produce the positive benefit; no hand-edited JSON values.
Acceptance criteria
Unavailableor a typed error, never zero or a fabricated estimate.dag_exportand the viewer show a generated positive sketch-vs-raw benefit with complete inputs and model provenance.Related