Algorithm Search⌘K

Modeladvanced

Provenance semirings

Also called K-relations, how-provenance.

Annotate tuples with elements of a commutative semiring and carry them through positive queries; provenance polynomials are the most general.

Provenance semirings are a model of query evaluation in which each tuple carries an annotation from a commutative semiring, and the operators of the positive relational algebra combine the annotations by the semiring operations: alternative use of data adds them, and joint use multiplies them. Green, Karvounarakis and Tannen introduced the model in 2007. With the Boolean semiring it is set semantics, with the natural numbers it is bag semantics, and with the semiring N[X]\mathbb{N}[X] of polynomials it records how each output was derived. That last case, the provenance polynomials, is the most general one: every other annotation is obtained from it by evaluating the polynomials.

The machine

Semirings. A commutative semiring is a set KK with two operations ++ and ⋅\cdot and two elements 00 and 11 such that ++ and ⋅\cdot are associative and commutative, 00 is the identity of ++, 11 is the identity of ⋅\cdot, ⋅\cdot distributes over ++, and 0⋅a=00 \cdot a = 0 for all aa. There is no subtraction or division in general. The examples used here:

Semiring Set ++ ⋅\cdot 00 11 Use
B\mathbb{B} {false,true}\{\mathit{false}, \mathit{true}\} or and false true set semantics
N\mathbb{N} {0,1,2,…}\{0, 1, 2, \ldots\} sum product 00 11 bag semantics
tropical N∪{∞}\mathbb{N} \cup \{\infty\} min sum ∞\infty 00 cost of the cheapest derivation
Viterbi [0,1][0, 1] max product 00 11 confidence of the best derivation
Why(X)\mathrm{Why}(X) sets of subsets of XX union pairwise union ∅\emptyset {∅}\{\emptyset\} why-provenance
N[X]\mathbb{N}[X] polynomials over XX with coefficients in N\mathbb{N} sum product 00 11 provenance polynomials

In Why(X)\mathrm{Why}(X), the pairwise union of AA and BB is {a∪b∣a∈A,b∈B}\{a \cup b \mid a \in A, b \in B\}.

K-relations. Fix a commutative semiring KK. A K-relation over a set of attributes UU is a function RR from the tuples over UU to KK whose support {t∣R(t)≠0}\{t \mid R(t) \neq 0\} is finite. The value R(t)R(t) is the annotation of tt; a tuple with annotation 00 is absent. A K-instance gives a K-relation to each relation name. For provenance, each input tuple gets its own variable as its annotation, from a set XX of tuple identifiers.

The positive algebra on K-relations (Green, Karvounarakis and Tannen 2007). For K-relations R,R1R, R_1 over UU, R2R_2 over U2U_2, and a selection predicate PP that returns 00 or 11:

  • empty relation: ∅(t)=0\emptyset(t) = 0 for every tt;
  • union: (R∪R′)(t)=R(t)+R′(t)(R \cup R')(t) = R(t) + R'(t);
  • projection: (πVR)(t)=∑{ R(t′)∣t′[V]=t, R(t′)≠0 }(\pi_{V} R)(t) = \sum \{\, R(t') \mid t'[V] = t,\ R(t') \neq 0 \,\};
  • selection: (σPR)(t)=R(t)⋅P(t)(\sigma_{P} R)(t) = R(t) \cdot P(t);
  • natural join: (R1⋈R2)(t)=R1(t[U])⋅R2(t[U2])(R_1 \bowtie R_2)(t) = R_1(t[U]) \cdot R_2(t[U_2]), for tt over U∪U2U \cup U_2;
  • renaming: moves the annotation with the tuple.

The sums are finite, because supports are finite. So ++ means "derived in another way" and ⋅\cdot means "derived by using both". Union and projection, which merge tuples, add; join, which needs both inputs, multiplies.

Datalog. A recursive rule can derive a tuple in infinitely many ways, so its annotation is an infinite sum. Green, Karvounarakis and Tannen use omega-continuous semirings: KK is ordered by a≤ba \leq b if b=a+cb = a + c for some cc, every increasing chain a0≤a1≤⋯a_0 \leq a_1 \leq \cdots has a least upper bound, and ++ and ⋅\cdot preserve these bounds. Then the immediate consequence operator of a Datalog program on K-instances is omega-continuous, and the program's meaning is its least fixed point, the limit of the rounds of naive evaluation starting from the empty instance, as in the Kleene fixed-point theorem. B\mathbb{B}, N∞=N∪{∞}\mathbb{N}^{\infty} = \mathbb{N} \cup \{\infty\} and the tropical semiring are omega-continuous; N\mathbb{N} is not, since 1+1+⋯1 + 1 + \cdots has no bound in N\mathbb{N}.

What it counts

The model assigns to each output tuple an element of KK, computed from the annotations of the input tuples. What the element means depends on KK: presence (B\mathbb{B}), multiplicity (N\mathbb{N}), the cost or confidence of the best derivation (tropical, Viterbi), the sets of tuples that witness it (Why(X)\mathrm{Why}(X)), or the full derivation record (N[X]\mathbb{N}[X]). In N[X]\mathbb{N}[X], each monomial is one derivation: its variables are the input tuples it uses, and an exponent counts how many times it uses a tuple. The coefficient counts the derivations that use the same tuples the same number of times.

Example. Let E(src,dst)E(\mathit{src}, \mathit{dst}) have the three edges (a,b)(a, b), (b,a)(b, a), (a,a)(a, a), annotated uu, vv, ww. The query

Q=πsrc(E⋈ρdst→src, src→dst(E))Q = \pi_{\mathit{src}}\big(E \bowtie \rho_{\mathit{dst} \to \mathit{src},\ \mathit{src} \to \mathit{dst}}(E)\big)

returns each node xx with edges (x,y)(x, y) and (y,x)(y, x), that is, each node on a cycle of length 1 or 2. Node aa has two derivations, y=by = b with edges uu and vv, and y=ay = a with the edge ww used twice. Node bb has one, with vv and uu. So in N[X]\mathbb{N}[X]

Q(a)=uv+w2,Q(b)=uv.Q(a) = uv + w^{2}, \qquad Q(b) = uv.

Each other semiring gives its value by substitution:

  • B\mathbb{B} with u=v=w=trueu = v = w = \mathit{true}: both nodes are in the answer, as in set semantics.
  • N\mathbb{N} with u=2u = 2, v=1v = 1, w=3w = 3, that is, two copies of (a,b)(a, b) and three of (a,a)(a, a) in a bag: Q(a)=2⋅1+32=11Q(a) = 2 \cdot 1 + 3^{2} = 11 and Q(b)=2Q(b) = 2. Evaluating the same query on the bag directly gives 11 copies of aa and 2 of bb.
  • Tropical with edge costs u=1u = 1, v=2v = 2, w=5w = 5: Q(a)=min⁡(1+2,5+5)=3Q(a) = \min(1 + 2, 5 + 5) = 3 and Q(b)=3Q(b) = 3.
  • Why(X)\mathrm{Why}(X) with u={{u}}u = \{\{u\}\} and so on: Q(a)={{u,v},{w}}Q(a) = \{\{u, v\}, \{w\}\}. Deleting ww keeps aa in the answer, through {u,v}\{u, v\}; deleting uu also keeps it, through {w}\{w\}.

A recursive example. With two edges (a,b)(a, b) and (b,a)(b, a), annotated xx and yy, the transitive closure program T(s,d)←E(s,d)T(s, d) \leftarrow E(s, d), T(s,d)←T(s,m),E(m,d)T(s, d) \leftarrow T(s, m), E(m, d) derives T(a,b)T(a, b) by the paths aba b, ababa b a b, abababa b a b a b, and so on. Its annotation is the formal power series x+x2y+x3y2+⋯x + x^{2} y + x^{3} y^{2} + \cdots in N∞[[X]]\mathbb{N}^{\infty}[[X]]. In N∞\mathbb{N}^{\infty} with x=y=1x = y = 1 this is ∞\infty, the number of derivations; in B\mathbb{B} it is true; in the tropical semiring with costs xx and yy it is xx, the cost of the shortest path.

Relation to other models

  • Set and bag semantics. A B\mathbb{B}-relation is an ordinary relation, and the positive algebra on B\mathbb{B}-relations is the relational algebra under set semantics. An N\mathbb{N}-relation is a bag, and the positive algebra on N\mathbb{N}-relations is bag semantics, as in SQL without DISTINCT. The model puts the two under one definition.
  • Why-provenance and lineage. Why-provenance is the Why(X)\mathrm{Why}(X) semiring; lineage and the minimal witness basis are two further semirings. Each is a homomorphic image of N[X]\mathbb{N}[X], so how-provenance contains strictly more information than each of them: uv+w2uv + w^{2} and uv+wuv + w have the same why-provenance, {{u,v},{w}}\{\{u, v\}, \{w\}\}, but are different polynomials.
  • Conditional tables and probabilistic databases. The conditional tables of Imielinski and Lipski (1984) annotate tuples with Boolean conditions; for positive queries this is a K-relation over the semiring of positive Boolean expressions. A probabilistic database evaluates a query by computing such an expression for each answer, its lineage formula, and then its probability. Turning the formula into a form where the probability is easy is knowledge compilation.
  • Program analysis and path problems. A Datalog program over an omega-continuous semiring is a system of fixpoint equations over that semiring, as in Datalog-based program analysis and the algebraic path problems: all-pairs shortest paths, as in Floyd-Warshall, is the transitive closure program over the tropical semiring. The equations over the semiring of regular languages are those of Kleene algebra.
  • Incremental maintenance. Counting the derivations of each tuple, the N\mathbb{N} annotation, is the counting algorithm of incremental view maintenance: a deletion subtracts the derivations it removes, and the tuple disappears when its count reaches 0.

Known results in the model

All results are from Green, Karvounarakis and Tannen (2007) and are for the positive relational algebra (union of conjunctive queries) unless they say Datalog.

  • Commutation with homomorphisms. If h:K→K′h : K \to K' is a semiring homomorphism (it preserves ++, ⋅\cdot, 00 and 11) and QQ is a positive algebra query, then Q(h(I))=h(Q(I))Q(h(I)) = h(Q(I)), where h(I)h(I) applies hh to every annotation. Proof. Each operator computes its output annotations by ++ and ⋅\cdot from its inputs, and hh commutes with both; induction on QQ.
  • N[X]\mathbb{N}[X] is the most general. N[X]\mathbb{N}[X] is the free commutative semiring generated by XX: every map ν:X→K\nu : X \to K into a commutative semiring extends to exactly one homomorphism Evalν:N[X]→K\mathrm{Eval}_{\nu} : \mathbb{N}[X] \to K, which substitutes ν(x)\nu(x) for each xx. With the previous result, for every K-instance II whose tuples are annotated ν(x)\nu(x) for tuple variables xx, the K-annotation of each answer is Evalν\mathrm{Eval}_{\nu} of its provenance polynomial. So one evaluation in N[X]\mathbb{N}[X] serves every semiring.
  • Equivalence. Two positive queries return the same N[X]\mathbb{N}[X]-relation on every N[X]\mathbb{N}[X]-instance if and only if they return the same K-relation on every K-instance, for every commutative semiring KK. This follows from the previous result, so equivalence under N[X]\mathbb{N}[X] is the strongest notion of equivalence in the model, stronger than bag equivalence, which is stronger than set equivalence.
  • Which identities hold. The usual identities of the positive algebra, associativity and commutativity of union and join, distributivity of join over union, and the pushing of selections and projections, hold on K-relations because KK is a commutative semiring; Green, Karvounarakis and Tannen showed that the semiring laws are what these identities need. Identities such as R∪R=RR \cup R = R need ++ to be idempotent, so they hold in B\mathbb{B} but not in N\mathbb{N} or N[X]\mathbb{N}[X].
  • Datalog. Over omega-continuous semirings the least fixed point exists and is reached as the limit of the rounds of naive evaluation. The most general annotation domain for Datalog is the semiring N∞[[X]]\mathbb{N}^{\infty}[[X]] of formal power series with coefficients in N∞\mathbb{N}^{\infty}: the coefficient of a monomial is the number of derivation trees of the tuple that use exactly those tuples, and it can be ∞\infty. Green, Karvounarakis and Tannen gave algorithms that decide, for each output tuple, whether its series is a polynomial, and compute it when it is.
  • Limits. Difference and negation are not covered: a commutative semiring has no subtraction, and R−SR - S does not fit the "derived in another way, derived by using both" reading. Aggregation is not covered either. Both need extensions of the model with more structure on KK.

References

  1. Todd J. Green, Grigoris Karvounarakis and Val Tannen, Provenance semirings, Proceedings of the 26th ACM Symposium on Principles of Database Systems (PODS), 31 to 40 (2007), K-relations and the positive algebra on them, commutation with homomorphisms, the provenance polynomials N[X] as the most general annotations, and Datalog over omega-continuous semirings with formal power series
  2. Tomasz Imielinski and Witold Lipski, Incomplete information in relational databases, Journal of the ACM 31(4), 761 to 791 (1984), conditional tables, whose tuples carry Boolean conditions through the algebra, an early case of annotated relations
  3. James Cheney, Laura Chiticariu and Wang-Chiew Tan, Provenance in databases, why, how, and where, Foundations and Trends in Databases 1(4), 379 to 474 (2009), how-provenance and its relation to lineage and why-provenance

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/JN7WRZ/text.yaml