pub struct ColumnStatistics {
pub n_distinct: usize,
pub null_count: usize,
pub min_value: Option<SqlValue>,
pub max_value: Option<SqlValue>,
pub most_common_values: Vec<(SqlValue, f64)>,
pub histogram: Option<Histogram>,
}Expand description
Statistics for a single column
Fields§
§n_distinct: usizeNumber of distinct values (cardinality)
null_count: usizeNumber of NULL values
min_value: Option<SqlValue>Minimum value (for range queries)
max_value: Option<SqlValue>Maximum value (for range queries)
most_common_values: Vec<(SqlValue, f64)>Most common values with their frequencies (top 10)
histogram: Option<Histogram>Optional histogram for improved selectivity estimation (Phase 5.1)
Implementations§
Source§impl ColumnStatistics
impl ColumnStatistics
Sourcepub fn compute(rows: &[Row], column_idx: usize) -> Self
pub fn compute(rows: &[Row], column_idx: usize) -> Self
Compute statistics for a column by scanning all rows
Sourcepub fn compute_with_histogram(
rows: &[Row],
column_idx: usize,
enable_histogram: bool,
num_buckets: usize,
bucket_strategy: BucketStrategy,
) -> Self
pub fn compute_with_histogram( rows: &[Row], column_idx: usize, enable_histogram: bool, num_buckets: usize, bucket_strategy: BucketStrategy, ) -> Self
Compute statistics with optional histogram support
§Arguments
rows- The rows to analyzecolumn_idx- Index of the columnenable_histogram- Whether to build a histogramnum_buckets- Number of histogram buckets (default: 100)bucket_strategy- Histogram bucketing strategy
Sourcepub fn estimate_eq_selectivity(&self, value: &SqlValue) -> f64
pub fn estimate_eq_selectivity(&self, value: &SqlValue) -> f64
Estimate selectivity of equality predicate: col = value
Returns fraction of rows expected to match (0.0 to 1.0) Uses histogram if available for improved accuracy (Phase 5.1)
Sourcepub fn estimate_ne_selectivity(&self, value: &SqlValue) -> f64
pub fn estimate_ne_selectivity(&self, value: &SqlValue) -> f64
Estimate selectivity of inequality: col != value
Sourcepub fn estimate_range_selectivity(
&self,
value: &SqlValue,
operator: &str,
) -> f64
pub fn estimate_range_selectivity( &self, value: &SqlValue, operator: &str, ) -> f64
Estimate selectivity of range predicate: col > value or col < value
Uses histogram if available (Phase 5.1), otherwise falls back to min/max-based linear interpolation (assumes uniform distribution)
Trait Implementations§
Source§impl Clone for ColumnStatistics
impl Clone for ColumnStatistics
Source§fn clone(&self) -> ColumnStatistics
fn clone(&self) -> ColumnStatistics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more