Skip to main content

ChainBound

Struct ChainBound 

Source
pub struct ChainBound {
    pub distinct_counts: Vec<u64>,
}
Expand description

Degree-derived chain-join upper bound.

Takes a per-relation distinct-key count and converts it into a sound bound on the relation’s maximum join degree, maxdeg_i ≤ |R_i| − D_i + 1, then applies the spanning-tree degree ceiling from crate::degree. Falls back to ProductBound when no equality predicates are supplied.

§Caller obligation

distinct_counts[i] must be the distinct-value count of the join key relation i carries, and it must not over-state the truth — an HLL reading that comes back high would relax the derived degree bound in the unsafe direction. crate::sketches::HllSketch readings should be used at or below their estimate, not above it.

§Soundness note (changed in 1.2.0)

Through v1.1 this bound divided the Cartesian product by max(D_i, D_j) per predicate. That formula is a uniform-distribution estimate, not an upper bound: under skew it lands below the true cardinality. Concretely, two 20-row relations with 5 distinct keys each and 16 rows piled on one key join to 260 rows, while the old formula returned 80. The bound now returns 320 for that instance — larger, and actually provable. See crate::degree for the theorem.

§Examples

use samkhya_core::lpbound::{ChainBound, UpperBound};

// A foreign-key join: 10 orders, 100 line items, 10 distinct keys on
// both sides. Bounds exactly at the true output of 100 rows.
let cb = ChainBound::new(vec![10, 10]);
assert_eq!(cb.ceiling(&[10, 100], &[(0, 1)]), 100);

Fields§

§distinct_counts: Vec<u64>

Implementations§

Source§

impl ChainBound

Source

pub fn new(distinct_counts: Vec<u64>) -> Self

Construct a chain-join bound from per-relation distinct-key counts.

§Examples
use samkhya_core::lpbound::{ChainBound, UpperBound};

// Two 1000-row relations over a key with 100 distinct values: at
// worst 901 rows share one value, so the ceiling is 1000 * 901.
let cb = ChainBound::new(vec![100, 100]);
assert_eq!(cb.ceiling(&[1_000, 1_000], &[(0, 1)]), 901_000);

Trait Implementations§

Source§

impl UpperBound for ChainBound

Source§

fn ceiling( &self, relations: &[u64], equality_predicates: &[(usize, usize)], ) -> u64

Compute the inclusive ceiling for a join. 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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V