Skip to main content

JoinSelectivity

Struct JoinSelectivity 

Source
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: RelId

Left relation in the join

§right_rel: RelId

Right 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: f64

Estimated selectivity factor (0.0 to 1.0)

§is_pk_fk: bool

Whether this is a primary key to foreign key join

Implementations§

Source§

impl JoinSelectivity

Source

pub fn new(left_rel: RelId, right_rel: RelId) -> Self

Creates a new join selectivity model between two relations.

Initializes with default selectivity of 1.0 (cross product).

§Arguments
  • left_rel - The left relation’s ID
  • right_rel - The right relation’s ID
§Returns

A new JoinSelectivity with default values.

Source

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 relation
  • right_keys - Column indices on the right relation
Source

pub fn set_selectivity(&mut self, selectivity: f64)

Sets the selectivity factor.

§Arguments
  • selectivity - The selectivity factor (0.0 to 1.0)
Source

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.

Source

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 relation
  • right_rows - Cardinality of the right relation
§Returns

The estimated output cardinality (minimum of 1)

Source

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 key
  • right_distinct - Distinct value count for right join key
§Returns

The estimated selectivity

Source

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 cardinality
  • right_rows - Actual right cardinality
  • output_rows - Actual output cardinality

Trait Implementations§

Source§

impl Clone for JoinSelectivity

Source§

fn clone(&self) -> JoinSelectivity

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JoinSelectivity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,