pub struct IndexStats {
pub entries: usize,
pub distinct_keys: usize,
pub approx_bytes: usize,
pub kind: IndexKind,
pub has_bloom: bool,
pub index_correlation: f64,
}Expand description
Per-index statistics used by the cost-based planner and diagnostics. All fields are best-effort; zero means “unknown”.
Fields§
§entries: usizeTotal number of (key, value) pairs stored.
distinct_keys: usizeNumber of distinct keys. For hash/btree this equals the key set size.
approx_bytes: usizeApproximate memory footprint in bytes (0 if not tracked).
kind: IndexKindFamily of index this originates from.
has_bloom: boolWhether a bloom filter is attached (enables fast negative lookups).
index_correlation: f64Physical correlation between index key order and heap row order. 1.0 = perfectly correlated (monotonic insert, timeseries) → sequential I/O. 0.0 = completely random → worst-case random I/O per row. Default 0.0 (conservative). Used by Mackert-Lohman I/O cost formula.
Implementations§
Source§impl IndexStats
impl IndexStats
Sourcepub fn point_selectivity(&self) -> f64
pub fn point_selectivity(&self) -> f64
Rough selectivity estimate for an equality predicate. Returns the
expected fraction of rows matching a random key, clamped to [0, 1].
Used by the planner to pick between index probes and full scans.
Sourcepub fn avg_values_per_key(&self) -> f64
pub fn avg_values_per_key(&self) -> f64
Average number of values per distinct key.
Estimate the I/O cost (in arbitrary page-cost units) of fetching
result_rows rows via this index from a heap_pages-page table.
Uses the Mackert-Lohman (1986) formula — the same model PostgreSQL
uses in cost_index (optimizer/path/costsize.c:545-700):
pages_fetched = ML(selectivity, heap_pages)
io_cost = lerp(random_io, seq_io, correlation²)Constants match PG GUC defaults:
random_page_cost = 4.0seq_page_cost = 1.0
Trait Implementations§
Source§impl Clone for IndexStats
impl Clone for IndexStats
Source§fn clone(&self) -> IndexStats
fn clone(&self) -> IndexStats
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IndexStats
impl Debug for IndexStats
Source§impl Default for IndexStats
impl Default for IndexStats
Source§fn default() -> IndexStats
fn default() -> IndexStats
Auto Trait Implementations§
impl Freeze for IndexStats
impl RefUnwindSafe for IndexStats
impl Send for IndexStats
impl Sync for IndexStats
impl Unpin for IndexStats
impl UnsafeUnpin for IndexStats
impl UnwindSafe for IndexStats
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,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request