pub struct PlanCost {
pub cpu: f64,
pub io: f64,
pub network: f64,
pub memory: f64,
pub startup_cost: f64,
pub total: f64,
}Expand description
Cost of executing a query plan.
Mirrors PostgreSQL’s Cost split: startup_cost is the work needed
before the first row can be produced, total is the work to
produce the last row. Both are reported so plan selection can
pick a low-startup plan when a small LIMIT is in scope, even if
total work is higher.
See src/storage/query/planner/README.md § Invariant 1.
Fields§
§cpu: f64CPU computation cost
io: f64IO access cost
network: f64Network transfer cost (for distributed)
memory: f64Memory requirement
startup_cost: f64Cost to produce the first row.
Zero for streaming operators (full scan, index scan, filter over
scan). Equal to total for blocking operators (sort, hash join
build side, materialize).
total: f64Cost to produce the last row.
Implementations§
Source§impl PlanCost
impl PlanCost
Sourcepub fn new(cpu: f64, io: f64, memory: f64) -> PlanCost
pub fn new(cpu: f64, io: f64, memory: f64) -> PlanCost
Create a new cost estimate with startup_cost = 0 (streaming).
Sourcepub fn with_startup(
cpu: f64,
io: f64,
memory: f64,
startup_cost: f64,
) -> PlanCost
pub fn with_startup( cpu: f64, io: f64, memory: f64, startup_cost: f64, ) -> PlanCost
Create a cost with an explicit startup_cost. Use for blocking
operators (sort, hash build) and for index point lookups whose
first-row cost is non-zero.
Sourcepub fn combine_pipelined(&self, other: &PlanCost) -> PlanCost
pub fn combine_pipelined(&self, other: &PlanCost) -> PlanCost
Compose two costs in a pipelined fashion: the second operator consumes the first as a stream.
Both startup_cost and total add together. Use for filter
over scan, projection over filter, etc.
Sourcepub fn combine_blocking(&self, blocker: &PlanCost) -> PlanCost
pub fn combine_blocking(&self, blocker: &PlanCost) -> PlanCost
Compose two costs where self must be fully consumed before
blocker can produce its first row.
self.total flows into blocker.startup_cost. Use for sort,
hash build, materialise — anything that has to drain its input
before emitting.
Sourcepub fn combine(&self, other: &PlanCost) -> PlanCost
pub fn combine(&self, other: &PlanCost) -> PlanCost
Backwards-compatible alias for [combine_pipelined].
New code should prefer combine_pipelined / combine_blocking
explicitly. This is kept so existing callers compile unchanged.
Sourcepub fn scale(&self, factor: f64) -> PlanCost
pub fn scale(&self, factor: f64) -> PlanCost
Scale cost by a factor (cardinality multiplier, etc.).
Sourcepub fn prefer_over(
&self,
other: &PlanCost,
limit: Option<u64>,
cardinality: f64,
) -> Ordering
pub fn prefer_over( &self, other: &PlanCost, limit: Option<u64>, cardinality: f64, ) -> Ordering
Plan-comparison helper. Picks Less when self should be
preferred over other.
When limit is Some(k) and k < 0.1 * cardinality, the
comparison switches from total to startup_cost — the client
will only consume a small slice of the result, so we want the
plan that produces the first rows fastest even if the full scan
would be more expensive.
This mirrors PostgreSQL’s compare_path_costs_fuzzily logic for
STARTUP vs TOTAL cost ordering.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PlanCost
impl RefUnwindSafe for PlanCost
impl Send for PlanCost
impl Sync for PlanCost
impl Unpin for PlanCost
impl UnsafeUnpin for PlanCost
impl UnwindSafe for PlanCost
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request