Skip to main content

estimate_vocabulary_overlap

Function estimate_vocabulary_overlap 

Source
pub fn estimate_vocabulary_overlap(
    profile: &StatsProfile,
    driver_pattern: &EncodedTriplePattern,
    driver_slot: JoinKeySlot,
    probe_pattern: &EncodedTriplePattern,
    probe_slot: JoinKeySlot,
) -> Option<u64>
Expand description

Vocabulary containment between the two arms of one join key, milli-scaled |A ∩ B| / |A| (A = the driver arm’s key vocabulary, B = the probe arm’s).

The per-predicate HLL pairs (subjects_per_predicate / objects_per_predicate) summarize each arm’s distinct key values. Cardinalities alone cannot answer containment — |A| = 300 and |B| = 3 are consistent with any intersection in 0..=3 — but the sketches themselves support union: a register-max merge gives |A ∪ B|, and inclusion–exclusion gives the overlap. That merge is the one operation the seating model never performed; this function is its single definition.

Consumers:

  • the coverage verdict (push_list_covers_domain): a pushed list covers the probe’s key space when list × r reaches the probe domain — at r = full this reduces to the historical count comparison;
  • the probe broadcast price (probe_broadcast_price): the matched-rows fraction scales by the same r.

Error contract: inclusion–exclusion carries roughly twice a single HLL’s relative error (σ ≈ 1.6% at p=12, so ±3–4% typical), coarser on tiny domains. Verdicts stay advisory-only (§10): a wrong overlap changes plan choice and fetch selectivity, never results — the join applies the same predicate downstream regardless of what the push carried.

Returns None (→ the consumer degrades to VOCABULARY_OVERLAP_FULL_MILLI) when either arm presents no vocabulary: an unbound predicate, a missing or wire-trimmed sketch, a precision mismatch, an empty driver cardinality, the rdf:type family (its domains short-circuit through the exact class map — kept byte-identical on the count rule), or an unknown hash. The same-predicate/same-slot pair is the one positive short-circuit: both arms read the same sketch, so containment is full by identity (the self-merge is a register no-op) and the merge work is skipped.

Slots must be resolved for UNBOUND positions only (a ground key is a constant — no vocabulary question; callers mirror estimate_join_key_domain’s ground check before calling).