Skip to main content

StatsProfile

Struct StatsProfile 

Source
pub struct StatsProfile {
Show 13 fields pub total_puts: u64, pub predicate_counts: BTreeMap<StrHash, u64>, pub class_counts: BTreeMap<StrHash, u64>, pub subject_cms: CountMinSketch, pub object_cms: CountMinSketch, pub subjects_per_predicate: BTreeMap<StrHash, HyperLogLog>, pub objects_per_predicate: BTreeMap<StrHash, HyperLogLog>, pub subject_domains_per_predicate: BTreeMap<StrHash, u64>, pub object_domains_per_predicate: BTreeMap<StrHash, u64>, pub named_graph_count: u64, pub temporal_histogram: TickHistogram, pub geo_cell_histogram: GeoCellHistogram, pub text_seed_sketch: TextSeedSketch,
}
Expand description

Mergeable statistical profile for one shard or the whole cluster.

§Equality caveat

The derived PartialEq / Eq compares the HLL cardinality cache maps too. Those maps are derived state (see Self::derive_hll_domains), so two profiles with identical sketches but different cache states compare unequal — for example, a serde_bin round trip (empty caches) versus a refresh_stats profile (derived caches). For “same statistics” checks, compare the sketch/count fields or derive both sides first; do not treat a whole-profile == across a decode/derive boundary as statistical equality.

Fields§

§total_puts: u64

Approximate total Put observations in this profile.

§predicate_counts: BTreeMap<StrHash, u64>

Exact predicate frequencies (named-node predicates).

§class_counts: BTreeMap<StrHash, u64>

Exact rdf:type class instance counts (named-node classes only).

§subject_cms: CountMinSketch

Subject frequency CMS.

§object_cms: CountMinSketch

Object frequency CMS.

§subjects_per_predicate: BTreeMap<StrHash, HyperLogLog>

Distinct subjects per predicate (joint S–P cardinality).

§objects_per_predicate: BTreeMap<StrHash, HyperLogLog>

Distinct objects per predicate (joint P–O cardinality).

§subject_domains_per_predicate: BTreeMap<StrHash, u64>

HLL cardinality cache for Self::subjects_per_predicate: cardinality().max(1) per sketch, materialized by Self::derive_hll_domains at the compute boundary (waratah_compute’s stats rollup). NOT serialized: profiles decoded from bytes or built by hand carry empty maps, and the Self::subject_domain / Self::object_domain helpers fall back to computing on the fly (correct, just uncached). Cleared by Self::merge, rollup_cluster, and Self::capped_for_wire_with_budget — a merged or trimmed sketch is not the sketch the cached number came from, so an inherited value would be silently wrong. Direct mutation of Self::subjects_per_predicate or Self::objects_per_predicate likewise invalidates these maps; call Self::derive_hll_domains after such edits.

§object_domains_per_predicate: BTreeMap<StrHash, u64>

Precomputed distinct counts for Self::objects_per_predicate — see Self::subject_domains_per_predicate.

§named_graph_count: u64

Exact count of named graphs whose newest catalog version is Present.

S-axis only (named_graphs_catalog CF). P/O profiles leave this at 0. rollup_cluster copies the S value onto the preferred axis profile.

§temporal_histogram: TickHistogram

Sparse dyadic histogram over the temporal tick axis (postings of the O-axis temporal_index CF). Collected on the O partition only; the estimator consumes it for temporal_scan window row counts — advisory, never pruning (see [crate::tick_histogram]).

§geo_cell_histogram: GeoCellHistogram

Sparse level-11 cell-count histogram over the geo index (postings of the O-axis geo_index CF). Collected on the O partition only; the estimator consumes it for GeoCandidateScan covering row counts — advisory, never pruning (see [crate::geo_cell_histogram]).

§text_seed_sketch: TextSeedSketch

Pruned count tries over the text index’s seed fields (posting counts of first-seed_chars and reversed last-seed_chars characters per indexed literal). Collected on the O partition only, at text rebuild finish, stamped with the index’s build epoch; the text planner consumes it for candidate-drain estimates — advisory, never pruning (see crate::text_seed_sketch::TextSeedSketch).

Implementations§

Source§

impl StatsProfile

Source

pub fn has_predicate_sketch(&self, pattern: &EncodedTriplePattern) -> bool

Whether the profile carries a row sketch for pattern’s bound named predicate — the evidence estimate_pattern consults for such a pattern. A never-observed predicate estimates as 1 (see that function’s doc), not unknown, so fetch-once pricing must not treat a non-empty profile that lacks this key as evidence for the arm’s size. A pattern without a bound named predicate prices from the store-level uniform model (StatsProfile::total_puts), which any non-empty profile carries.

Source

pub fn is_empty(&self) -> bool

Whether this profile has observed any puts or named graphs.

Source

pub fn capped_for_wire(&self) -> Self

Copy truncated to serialize within STATS_WIRE_BUDGET_BYTES.

CORE-ONLY since the frame split: the geo cell-count histogram and the temporal histogram sections arrive EMPTY (they travel in their own frames — see Self::capped_geo_histogram_for_wire), and the per-predicate HLL pairs are ranked-trimmed: the LARGEST predicates by exact count are kept first (the ranking is free — predicate_counts is in the same profile) until the budget, and the smallest are dropped. The estimator’s absent-entry contract makes this safe: a dropped HLL skips the fan-out candidate and degrades the join domain to the existing fallbacks, and because distinct counts never exceed row counts, the single-pattern estimate can only overestimate — bounded by the predicate’s own (small) count. Fixed parts are always kept; SST blobs and shard merges stay full-fidelity, so nothing here is lossy for merging — trim only at transport boundaries.

Source

pub fn capped_geo_histogram_for_wire(&self) -> GeoCellHistogram

The geo cell-count histogram trimmed for its TWO transport frames (GetGeoHistogram): the fine map under GEO_FINE_FRAME_BUDGET_BYTES PLUS the remainder summary under its own GEO_REMAINDER_WIRE_BUDGET_BYTES — independent, ADDITIVE budgets, so a saturated FINE message is 2.25 MiB (1.75 fine + 0.5 remainder); coarse under GEO_COARSE_FRAME_BUDGET_BYTES (rank-and-keep, drop-tail reads empty — the package’s one down-biased trim; see [GeoCellHistogram::capped_coarse_map]). Every message stays individually under the shared 4 MiB gRPC ceiling.

ONE canonical trim both transport sides share: the partition handlers slice the FINE / COARSE frames out of this, and the compute rollup re-trims the merged frames with the same budgets — the same double-trim discipline the core profile has always had.

Source

pub fn capped_for_wire_with_budget(&self, budget: usize) -> Self

Self::capped_for_wire under an explicit byte budget (tests).

CORE-ONLY since the frame split: the geo cell-count histogram and the temporal histogram arrive EMPTY — they travel in their own frames with their own budgets (see Self::capped_geo_histogram_for_wire); the whole core budget spends on fixed parts + CMS + exact maps + the HLL pairs.

Source

pub fn derive_hll_domains(&mut self)

Materialize the HLL cardinality cache from the sketch maps.

Cost: one HyperLogLog::cardinality per surviving sketch — bounded by the wire cap (~3 MiB / ~8.5 KB per subject+object pair ≈ 370 predicates) regardless of dataset size, i.e. low single-digit milliseconds once per refresh. Callers: compute’s stats rollup (waratah_compute::query::refresh_stats), right after Self::capped_for_wire, before the profile becomes visible to any query — never on the query path. Self::merge, rollup_cluster, and the cap clear the maps so a stale cardinality can never survive a merge or trim.

Source

pub fn subject_domain(&self, hash: &StrHash) -> Option<u64>

Distinct subjects of the predicate hash, from the HLL cardinality cache when the profile carries one, else computed on the fly.

The fallback keeps hand-built and decoded profiles (empty caches — the maps are not serialized) correct at today’s per-call cost; refresh-derived profiles answer from a u64 map hit. None when the profile has no subject sketch for this predicate — identical to the sketch maps’ own missing-entry contract.

Source

pub fn object_domain(&self, hash: &StrHash) -> Option<u64>

Self::subject_domain for the objects-per-predicate sketch.

Source

pub fn merge(&mut self, other: &Self) -> Result<(), StatsError>

Algebraic merge (CMS add, HLL register-max, exact maps sum).

Source

pub fn estimate(&self, pattern: &EncodedTriplePattern) -> u64

Estimated matches for an encoded triple pattern.

Source

pub fn estimate_with_bound_slots( &self, pattern: &EncodedTriplePattern, extra: ExtraBoundSlots, ) -> u64

Self::estimate with extra S/P/O slots treated as bound (no ground term).

Source

pub fn join_key_domain( &self, pattern: &EncodedTriplePattern, slot: JoinKeySlot, ) -> Option<u64>

Distinct join-key domain for slot under a bound named-node predicate.

Uses subjects_per_predicate / objects_per_predicate HLL cardinality.

Trait Implementations§

Source§

impl Clone for StatsProfile

Source§

fn clone(&self) -> StatsProfile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StatsProfile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StatsProfile

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&LiveQuadsProfile> for StatsProfile

Source§

fn from(live: &LiveQuadsProfile) -> Self

Converts to this type from the input type.
Source§

impl From<LiveQuadsProfile> for StatsProfile

Source§

fn from(live: LiveQuadsProfile) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for StatsProfile

Source§

fn eq(&self, other: &StatsProfile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for StatsProfile

Source§

impl StructuralPartialEq for StatsProfile

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,