pub struct JoinSelectivity {
pub left_rel: RelId,
pub right_rel: RelId,
pub left_keys: Vec<usize>,
pub right_keys: Vec<usize>,
pub selectivity: f64,
pub is_pk_fk: bool,
/* private fields */
}Expand description
Join selectivity model for estimating join output cardinality.
Tracks information about joins between two relations, including the join keys and estimated selectivity. This is crucial for the optimizer to choose between nested-loop, hash, and sort-merge join strategies.
Fields§
§left_rel: RelIdLeft relation in the join
right_rel: RelIdRight relation in the join
left_keys: Vec<usize>Column indices used as join keys on the left relation
right_keys: Vec<usize>Column indices used as join keys on the right relation
selectivity: f64Estimated selectivity factor (0.0 to 1.0)
is_pk_fk: boolWhether this is a primary key to foreign key join
Implementations§
Source§impl JoinSelectivity
impl JoinSelectivity
Sourcepub fn set_keys(&mut self, left_keys: Vec<usize>, right_keys: Vec<usize>)
pub fn set_keys(&mut self, left_keys: Vec<usize>, right_keys: Vec<usize>)
Sets the join keys for both relations.
§Arguments
left_keys- Column indices on the left relationright_keys- Column indices on the right relation
Sourcepub fn set_selectivity(&mut self, selectivity: f64)
pub fn set_selectivity(&mut self, selectivity: f64)
Sourcepub fn mark_pk_fk(&mut self)
pub fn mark_pk_fk(&mut self)
Marks this as a primary key to foreign key join.
PK-FK joins have special selectivity characteristics: the output cardinality equals the FK side’s cardinality.
Sourcepub fn estimate_output_rows(&self, left_rows: u64, right_rows: u64) -> u64
pub fn estimate_output_rows(&self, left_rows: u64, right_rows: u64) -> u64
Estimates the output row count for this join.
For PK-FK joins, returns the cardinality of the FK side. For other joins, returns: left_rows * right_rows * selectivity
§Arguments
left_rows- Cardinality of the left relationright_rows- Cardinality of the right relation
§Returns
The estimated output cardinality (minimum of 1)
Sourcepub fn estimate_selectivity_from_stats(
left_distinct: u64,
right_distinct: u64,
) -> f64
pub fn estimate_selectivity_from_stats( left_distinct: u64, right_distinct: u64, ) -> f64
Estimates selectivity from column statistics.
Uses the “independence assumption” and distinct value counts: selectivity = 1 / max(distinct_left, distinct_right)
§Arguments
left_distinct- Distinct value count for left join keyright_distinct- Distinct value count for right join key
§Returns
The estimated selectivity
Sourcepub fn update_from_observation(
&mut self,
left_rows: u64,
right_rows: u64,
output_rows: u64,
)
pub fn update_from_observation( &mut self, left_rows: u64, right_rows: u64, output_rows: u64, )
Updates selectivity based on observed join statistics.
This can be called after query execution to improve future estimates.
§Arguments
left_rows- Actual left cardinalityright_rows- Actual right cardinalityoutput_rows- Actual output cardinality
Trait Implementations§
Source§impl Clone for JoinSelectivity
impl Clone for JoinSelectivity
Source§fn clone(&self) -> JoinSelectivity
fn clone(&self) -> JoinSelectivity
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more