Query semantics over annotated databases #
This file defines the evaluation of relational algebra queries over annotated databases.
Query operators are lifted to annotated relations using the m-semiring operations of the
annotation domain K: addition corresponds to union, multiplication to join, and
monus to difference. This is the algebra of Section IV-B of
Sen, Maniu & Senellart, ProvSQL: A General System for Keeping Track of the
Provenance and Probability of Data, itself an adaptation of
Green, Karvounarakis & Tannen, Provenance Semirings to
multiset semantics with explicit duplicate elimination and multiset difference.
Main definitions #
Query.evaluateAnnotated– evaluates a query over anAnnotatedDatabase T K, propagating annotations through each relational operator according to the semiring structure ofK
References #
Equations
- φ.evalDecidableAnnotated t = match φ.evalDecidable t.1 with | isTrue h => isTrue h | isFalse h => isFalse ⋯
Instances For
Equations
Instances For
Annotated (m-semiring) semantics of a non-aggregation query.
The Diff case follows ProvSQL: every tuple slot (u, α) of r₁ is kept,
with its annotation rewritten to α ⊖ Σ β where Σ β is the semiring sum of
the annotations of all copies of u in r₂. Two consequences worth noting:
- difference never removes tuple slots (only annotations change, possibly to
0), so the data part of the result is insensitive toDiff– this is made precise inProvenance.QueryAdequacy; - each copy of
uinr₁separately gets the full grouped sum subtracted, so the result is not invariant under regrouping extensionally equal annotated relations: overℕ,{(t,1),(t,1)} ∖ {(t,1)}has total annotation0while{(t,2)} ∖ {(t,1)}has total annotation1. As a consequence, overℕthe annotated semantics agrees with the all-or-nothing plain difference ofQuery.evaluateon0/1-annotated inputs, but not onceDeduphas accumulated annotations (seeNat.counterexample_diff_adequacy).
Equations
- One or more equations did not get rendered due to their size.
- (Query.Rel n s).evaluateAnnotated hq_2 d = match h : AnnotatedDatabase.find n s d with | none => ∅ | some rn => rn
- (Π ts q').evaluateAnnotated hq_2 d = Multiset.map (fun (t : AnnotatedTuple T K n_2) => (fun (k : Fin n) => (ts k).eval t.1, t.2)) (q'.evaluateAnnotated ⋯ d)
- (σ φ q_2).evaluateAnnotated hq_2 d = Multiset.filter (fun (ta : AnnotatedTuple T K n) => φ.eval ta.1) (q_2.evaluateAnnotated ⋯ d)
- (q₁ ⊎ q₂).evaluateAnnotated hq_2 d = q₁.evaluateAnnotated ⋯ d + q₂.evaluateAnnotated ⋯ d
- (ε q_2).evaluateAnnotated hq_2 d = ↑↑(groupByKey (q_2.evaluateAnnotated ⋯ d))
- (Query.Agg a a_1 a_2 a_3).evaluateAnnotated hq_2 d = ⋯.elim