Macaw.Data.Source.Planner.Cost (macaw_data v0.21.1)
View SourceA source's read cost, measured (spec/01 §6.4.2): a read's overhead and its cost a row, fitted from the reads the owner observes, so the planner's merge distance and an eviction's weight come from measurement, never a setting.
The unit is the owner's (microseconds, reductions): every observation and estimate is in
it. new/1 takes an optional starting estimate, the adapter's declared cost:;
observe/3 adds a read; estimate/1 is the fit by least squares, each earlier
observation weighted by 0.95 against the next, once two reads of different row counts
are seen, else the starting estimate, else a call costing a chunk's rows
(Macaw.Data.Table.chunk_rows/0) at one a row. Neither part is ever negative.
iex> alias Macaw.Data.Source.Planner.Cost
iex> {:ok, cost} = Cost.new()
iex> cost = cost |> Cost.observe(1_000, 3_000.0) |> Cost.observe(5_000, 7_000.0)
iex> Cost.estimate(cost)
{2000.0, 1.0}
iex> Cost.merge_distance(cost, 500)
4
Summary
Functions
{call, row}: a read's overhead and its cost a row, as fitted or estimated.
The whole slots of rows_per_slot rows each whose rows cost no more than one read's
overhead: two gaps at most this far apart are cheaper read as one. :infinity when a row
costs nothing and a call something, 0 when a call costs nothing.
A cost model from an optional starting estimate: call: a read's overhead, row: its
cost a row, each a non-negative number, both or neither. A value it can't use is
{[key], {:type, :number}}, every fault at once.
A read of rows rows observed to cost measured, in the owner's unit.
What a read of rows rows costs: its overhead and its rows.
Types
Functions
{call, row}: a read's overhead and its cost a row, as fitted or estimated.
@spec merge_distance(t(), number()) :: non_neg_integer() | :infinity
The whole slots of rows_per_slot rows each whose rows cost no more than one read's
overhead: two gaps at most this far apart are cheaper read as one. :infinity when a row
costs nothing and a call something, 0 when a call costs nothing.
A cost model from an optional starting estimate: call: a read's overhead, row: its
cost a row, each a non-negative number, both or neither. A value it can't use is
{[key], {:type, :number}}, every fault at once.
@spec observe(t(), non_neg_integer(), number()) :: t()
A read of rows rows observed to cost measured, in the owner's unit.
@spec read(t(), non_neg_integer()) :: float()
What a read of rows rows costs: its overhead and its rows.