pub struct Histogram {
pub buckets: Vec<HistogramBucket>,
pub total_count: u64,
pub incremental_updates: u64,
pub stale: bool,
}Expand description
Equi-depth histogram for column value distribution estimation.
Buckets are sorted by lower_bound and non-overlapping. The CBO uses
binary search (O(log B)) on bucket boundaries for all selectivity lookups.
Fields§
§buckets: Vec<HistogramBucket>Ordered, non-overlapping histogram buckets.
total_count: u64Total number of rows represented by this histogram (sum of all bucket counts).
incremental_updates: u64Cumulative number of incremental updates since last full ANALYZE.
stale: boolWhether the histogram is considered stale (updates > 20% of total_count).
Implementations§
Source§impl Histogram
impl Histogram
Sourcepub fn find_bucket(&self, value: f64) -> Option<usize>
pub fn find_bucket(&self, value: f64) -> Option<usize>
Finds the bucket index containing value via binary search.
Returns the index of the bucket whose range [lower_bound, upper_bound)
contains value. Returns None if value is outside all bucket ranges.
Complexity: O(log B) where B = number of buckets. No allocations.
Sourcepub fn estimate_eq_selectivity(&self, value: f64) -> f64
pub fn estimate_eq_selectivity(&self, value: f64) -> f64
Estimates equality selectivity for a given value.
If the value falls within a bucket with distinct_count > 0, returns
bucket.count / (bucket.distinct_count × total_count).
If distinct_count == 0 or value is outside all buckets, returns
1 / total_count. Returns 0.0 when total_count == 0.
Result is clamped to [0.0, 1.0].
Sourcepub fn estimate_lt_selectivity(&self, value: f64) -> f64
pub fn estimate_lt_selectivity(&self, value: f64) -> f64
Estimates less-than selectivity for a given value.
Sums counts of all buckets fully below value, plus linear interpolation
of the partial bucket containing value. Divides by total_count.
Returns 0.0 if value ≤ first bucket lower bound, 1.0 if value ≥ last
bucket upper bound. Result is clamped to [0.0, 1.0].
Sourcepub fn estimate_range_selectivity(&self, low: f64, high: f64) -> f64
pub fn estimate_range_selectivity(&self, low: f64, high: f64) -> f64
Estimates range selectivity for [low, high].
Sums full buckets within the range plus interpolates boundary buckets.
Returns 0.0 if low > high or range is outside the histogram.
Returns 1.0 if range encompasses the entire histogram.
Result is clamped to [0.0, 1.0].
Sourcepub fn increment_bucket(&mut self, value: f64)
pub fn increment_bucket(&mut self, value: f64)
Increments the count of the bucket containing value.
Finds the bucket via binary search and increments its count by 1.
Increments incremental_updates by 1. If incremental_updates
exceeds 20% of total_count, marks the histogram as stale.
No-op if value is outside all bucket ranges.
Sourcepub fn decrement_bucket(&mut self, value: f64)
pub fn decrement_bucket(&mut self, value: f64)
Decrements the count of the bucket containing value, floored at zero.
Finds the bucket via binary search and decrements its count by 1
(minimum 0). Increments incremental_updates by 1. Checks staleness.
No-op if value is outside all bucket ranges.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Histogram
impl<'de> Deserialize<'de> for Histogram
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Histogram
Auto Trait Implementations§
impl Freeze for Histogram
impl RefUnwindSafe for Histogram
impl Send for Histogram
impl Sync for Histogram
impl Unpin for Histogram
impl UnsafeUnpin for Histogram
impl UnwindSafe for Histogram
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);