pub struct DatasetStatistics { /* private fields */ }Expand description
Dataset-level statistics aggregating per-predicate histograms.
Provides the interface expected by the cost-based optimizer for pattern cardinality estimation.
Implementations§
Source§impl DatasetStatistics
impl DatasetStatistics
Sourcepub fn with_num_buckets(num_buckets: usize) -> Self
pub fn with_num_buckets(num_buckets: usize) -> Self
Create a new statistics store with a custom bucket count.
Sourcepub fn record_triple(&mut self, predicate: &str, object: &str)
pub fn record_triple(&mut self, predicate: &str, object: &str)
Record the insertion of a single triple (subject, predicate, object).
Updates global counts and incrementally updates the per-predicate histogram.
Sourcepub fn get_histogram(&self, predicate: &str) -> Option<&PredicateHistogram>
pub fn get_histogram(&self, predicate: &str) -> Option<&PredicateHistogram>
Return the histogram for predicate, if one exists.
Sourcepub fn estimate_pattern_cardinality(
&self,
subject: Option<&str>,
predicate: Option<&str>,
object: Option<&str>,
) -> u64
pub fn estimate_pattern_cardinality( &self, subject: Option<&str>, predicate: Option<&str>, object: Option<&str>, ) -> u64
Estimate the cardinality of the triple pattern (?s, predicate?, object?).
Pattern selectivity is computed as:
- Unknown subject and unknown predicate →
total_triples. - Known predicate, unknown object →
histogram.total_count. - Known predicate + known object → equality filter estimate.
- Known object, unknown predicate → brute-force across all histograms.
- Unknown predicate and unknown object →
total_triples.
Sourcepub fn rebuild_histograms(&mut self, values: &[(String, String)])
pub fn rebuild_histograms(&mut self, values: &[(String, String)])
Rebuild all histograms from a full scan of (predicate, object) pairs.
This is an expensive O(n log n) operation and should be run during off-peak periods or triggered by the auto-analyze subsystem.
Sourcepub fn total_triples(&self) -> u64
pub fn total_triples(&self) -> u64
Return the total number of triples tracked by these statistics.
Sourcepub fn set_distinct_subjects(&mut self, count: u64)
pub fn set_distinct_subjects(&mut self, count: u64)
Update the known distinct subject count.
Called by the store layer after it recomputes subject cardinality.
Sourcepub fn set_distinct_objects(&mut self, count: u64)
pub fn set_distinct_objects(&mut self, count: u64)
Update the known distinct object count.
Sourcepub fn last_updated(&self) -> Instant
pub fn last_updated(&self) -> Instant
Return when the statistics were last updated.
Sourcepub fn predicate_count(&self) -> usize
pub fn predicate_count(&self) -> usize
Return the number of predicates with histograms.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DatasetStatistics
impl RefUnwindSafe for DatasetStatistics
impl Send for DatasetStatistics
impl Sync for DatasetStatistics
impl Unpin for DatasetStatistics
impl UnsafeUnpin for DatasetStatistics
impl UnwindSafe for DatasetStatistics
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> 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 more