pub trait StatsProvider: Send + Sync {
// Required methods
fn table_stats(&self, table: &str) -> Option<TableStats>;
fn index_stats(&self, table: &str, column: &str) -> Option<IndexStats>;
// Provided methods
fn column_stats(&self, table: &str, column: &str) -> Option<ColumnStats> { ... }
fn has_index(&self, table: &str, column: &str) -> bool { ... }
fn distinct_values(&self, table: &str, column: &str) -> Option<u64> { ... }
fn column_histogram(&self, _table: &str, _column: &str) -> Option<Histogram> { ... }
fn column_mcv(
&self,
_table: &str,
_column: &str,
) -> Option<MostCommonValues> { ... }
}Expand description
Read-only interface the planner uses to look up storage statistics.
Implementations must be cheap (O(1) or O(log n)) — the planner calls these during plan construction and must not block on I/O. Pre-aggregate expensive data into memory before exposing a provider.
Required Methods§
Sourcefn table_stats(&self, table: &str) -> Option<TableStats>
fn table_stats(&self, table: &str) -> Option<TableStats>
Return row-count / page-count / column metadata for table, or
None when stats are not available.
Sourcefn index_stats(&self, table: &str, column: &str) -> Option<IndexStats>
fn index_stats(&self, table: &str, column: &str) -> Option<IndexStats>
Return the IndexStats backing a secondary index on
(table, column), if one exists. The planner uses
IndexStats::point_selectivity to derive equality selectivity
instead of the 0.01 constant.
Provided Methods§
Sourcefn column_stats(&self, table: &str, column: &str) -> Option<ColumnStats>
fn column_stats(&self, table: &str, column: &str) -> Option<ColumnStats>
Return per-column statistics (distinct count, null count, min/max)
when available. Default implementation derives from
StatsProvider::table_stats when present.
Sourcefn has_index(&self, table: &str, column: &str) -> bool
fn has_index(&self, table: &str, column: &str) -> bool
Convenience: does a usable index exist on (table, column)?
Sourcefn distinct_values(&self, table: &str, column: &str) -> Option<u64>
fn distinct_values(&self, table: &str, column: &str) -> Option<u64>
Convenience: distinct-value count for a column, via column stats or an index on that column, whichever is available.
Sourcefn column_histogram(&self, _table: &str, _column: &str) -> Option<Histogram>
fn column_histogram(&self, _table: &str, _column: &str) -> Option<Histogram>
Optional equi-depth histogram for the column. Defaults to
None, in which case the planner falls back to its uniform
0.3 range heuristic.
Implementations should sample once and cache — this is called during plan construction and must not block on I/O.
Sourcefn column_mcv(&self, _table: &str, _column: &str) -> Option<MostCommonValues>
fn column_mcv(&self, _table: &str, _column: &str) -> Option<MostCommonValues>
Optional most-common-values list for the column. Defaults to
None, in which case the planner falls back to its uniform
0.01 equality heuristic. Use for skewed columns where one or
two values dominate the table.