pub struct CostModel { /* private fields */ }Expand description
Cost model for estimating operator costs.
Default constants are calibrated relative to each other:
- Tuple scan is the baseline (1x)
- Hash lookup is ~3x (hash computation + potential cache miss)
- Sort comparison is ~2x (key extraction + comparison)
- Distance computation is ~10x (vector math)
Implementations§
Source§impl CostModel
impl CostModel
Sourcepub fn with_avg_fanout(self, avg_fanout: f64) -> Self
pub fn with_avg_fanout(self, avg_fanout: f64) -> Self
Sets the global average fanout from graph statistics.
Sourcepub fn with_edge_type_degrees(
self,
degrees: HashMap<String, (f64, f64)>,
) -> Self
pub fn with_edge_type_degrees( self, degrees: HashMap<String, (f64, f64)>, ) -> Self
Sets per-edge-type degree statistics for accurate expand cost estimation.
Each entry maps edge type name to (avg_out_degree, avg_in_degree).
Sourcepub fn estimate(&self, op: &LogicalOperator, cardinality: f64) -> Cost
pub fn estimate(&self, op: &LogicalOperator, cardinality: f64) -> Cost
Estimates the cost of a logical operator.
Sourcepub fn cheaper<'a>(&self, a: &'a Cost, b: &'a Cost) -> &'a Cost
pub fn cheaper<'a>(&self, a: &'a Cost, b: &'a Cost) -> &'a Cost
Compares two costs and returns the cheaper one.
Sourcepub fn leapfrog_join_cost(
&self,
num_relations: usize,
cardinalities: &[f64],
output_cardinality: f64,
) -> Cost
pub fn leapfrog_join_cost( &self, num_relations: usize, cardinalities: &[f64], output_cardinality: f64, ) -> Cost
Estimates the cost of a worst-case optimal join (WCOJ/leapfrog join).
WCOJ is optimal for cyclic patterns like triangles. Traditional binary hash joins are O(N²) for triangles; WCOJ achieves O(N^1.5) by processing all relations simultaneously using sorted iterators.
§Arguments
num_relations- Number of relations participating in the joincardinalities- Cardinality of each input relationoutput_cardinality- Expected output cardinality
§Cost Model
- Materialization: O(sum of cardinalities) to build trie indexes
- Intersection: O(output * log(min_cardinality)) for leapfrog seek operations
- Memory: Trie storage for all inputs
Sourcepub fn prefer_leapfrog_join(
&self,
num_relations: usize,
cardinalities: &[f64],
output_cardinality: f64,
) -> bool
pub fn prefer_leapfrog_join( &self, num_relations: usize, cardinalities: &[f64], output_cardinality: f64, ) -> bool
Compares hash join cost vs leapfrog join cost for a cyclic pattern.
Returns true if leapfrog (WCOJ) is estimated to be cheaper.
Sourcepub fn factorized_benefit(&self, avg_fanout: f64, num_hops: usize) -> f64
pub fn factorized_benefit(&self, avg_fanout: f64, num_hops: usize) -> f64
Estimates cost for factorized execution (compressed intermediate results).
Factorized execution avoids materializing full cross products by keeping results in a compressed “factorized” form. This is beneficial for multi-hop traversals where intermediate results can explode.
Returns the reduction factor (1.0 = no benefit, lower = more compression).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CostModel
impl RefUnwindSafe for CostModel
impl Send for CostModel
impl Sync for CostModel
impl Unpin for CostModel
impl UnsafeUnpin for CostModel
impl UnwindSafe for CostModel
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> 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 more