The rewritten world's evaluator: tokens as ordinary column values #
ProvSQL evaluates rewritten plans over a value universe that contains,
next to the regular values and the provenance identifiers, the aggregate
tokens produced by its provsql_agg gate; the provsql_having gate then
reads a token and produces the predicate provenance of an aggregate
comparison. The formal counterpart is the evaluator AggQuery.evaluateRew
defined here: it runs a rewritten query (a AggQuery over the composite
value type T ⊕ K) over rows Tuple (GenValue (T ⊕ K) K) n – the
lifted-column carrier of the general evaluator, instantiated at the
composite value type – with the kind vector saying which columns hold
tokens.
- On the value-kinded operators the evaluator is the plain semantics
through the
inlembedding (Dedup,DiffandGammacollapse their statically all-regular rows to plain tuples, exactly as the general evaluator reads them throughGenRow.toAnnotated). AggQuery.GammaTokbuilds tokens: oneAggValue.ofGroupper(term, aggregate)pair over the group's occurrence sequence, whose annotations are the values of the explicit annotation term – in rewritten plans, the provenance column of the subquery – and writes the group-existence guardδ(⊕ occs)into itsprovoutput column.TermG.cmpAggis the cmp gate:TermG.evalRewinterprets it byAggValue.predProv, the primitive the rewriting's correctness is stated against, faithfully to ProvSQL's own gate-relative correctness.TermG.chiGateis the indicator gate aHAVINGpredicate needs for its regular atoms:TermG.evalRewinterprets it byHaving.chi, the characteristic valuepredsemgives such an atom. Having no kind constraint to keep it off plain columns, it is whatAggQuery.chiFreeexcludes below.
The rewriting rules built on this evaluator live downstream:
Provenance.AggQueryGroupRewriting (the bare grouping and the HAVING
site) and Provenance.AggQueryClosure (the compositional closure).
Terms and predicates in the rewritten world #
The annotation part of a composite value (𝟘 on data values: a
malformed provenance read carries no worlds).
Instances For
Dependency graph
Term evaluation in the rewritten world: as TermG.eval on the
value-reading constructors, with the cmpAgg gate interpreted by the
predicate provenance of the token against the comparison term, and the
chiGate gate by the characteristic value of its comparison.
Equations
- (TermG.const a).evalRew x✝ = a
- (TermG.index k a).evalRew x✝ = AggValue.collapseSum (x✝ k)
- (TermG.provIndex k a).evalRew x✝ = AggValue.collapseSum (x✝ k)
- (TermG.cmpAgg k a op c).evalRew x✝ = match x✝ k with | Sum.inl val => Sum.inr 0 | Sum.inr a => Sum.inr (a.predProv op (c.evalRew x✝))
- (TermG.chiGate op t₁ t₂).evalRew x✝ = Sum.inr (Having.chi op (t₁.evalRew x✝) (t₂.evalRew x✝))
- (t₁.add t₂).evalRew x✝ = t₁.evalRew x✝ + t₂.evalRew x✝
- (t₁.sub t₂).evalRew x✝ = t₁.evalRew x✝ - t₂.evalRew x✝
- (t₁.mul t₂).evalRew x✝ = t₁.evalRew x✝ * t₂.evalRew x✝
Instances For
Dependency graph
Projection-column evaluation in the rewritten world.
Equations
- (ProjCol.term t).evalRew u = Sum.inl (t.evalRew u)
- (ProjCol.token k a).evalRew u = u k
- (ProjCol.provTerm t).evalRew u = Sum.inl (t.evalRew u)
Instances For
Dependency graph
Classical truth of a predicate in the rewritten world (compared
tokens read through their deterministic collapse, as in
GenPred.holds).
Equations
- (GenPred.cmp op t₁ t₂).holdsRew x✝ = op.eval (t₁.evalRew x✝) (t₂.evalRew x✝)
- (GenPred.aggCmp k a op t).holdsRew x✝ = op.eval (AggValue.collapseSum (x✝ k)) (t.evalRew x✝)
- (φ.and ψ).holdsRew x✝ = (φ.holdsRew x✝ ∧ ψ.holdsRew x✝)
- (φ.or ψ).holdsRew x✝ = (φ.holdsRew x✝ ∨ ψ.holdsRew x✝)
- φ.not.holdsRew x✝ = ¬φ.holdsRew x✝
Instances For
Dependency graph
Structural decidability of holdsRew.
Equations
- (GenPred.cmp op a a_1).decHoldsRew u = GenPred.decHoldsRew._aux_1 u op a a_1
- (GenPred.aggCmp k a op a_1).decHoldsRew u = GenPred.decHoldsRew._aux_3 u k a op a_1
- (φ_2.and ψ).decHoldsRew u = instDecidableAnd
- (φ_2.or ψ).decHoldsRew u = instDecidableOr
- φ_2.not.decHoldsRew u = instDecidableNot
Instances For
Dependency graph
Equations
- φ.instDecidableHoldsRew u = φ.decHoldsRew u
Dependency graph
The evaluator #
The rewritten world's evaluator: plain multiset semantics over
token-bearing rows. Value-kinded operators act through the inl
embedding; GammaTok builds tokens and the group guard; the gates
inside terms are interpreted by predProv and Having.chi.
Equations
- One or more equations did not get rendered due to their size.
- (AggQuery.Rel x✝¹ s).evaluateRew x✝ = match Database.find x✝¹ s x✝ with | none => 0 | some rn => Multiset.map (fun (t : Tuple (T ⊕ K) x✝¹) (k : Fin x✝¹) => Sum.inl (t k)) rn
- (AggQuery.Proj ps q).evaluateRew x✝ = Multiset.map (fun (u : Tuple (GenValue (T ⊕ K) K) n_1) (j : Fin x✝¹) => (ps j).evalRew u) (q.evaluateRew x✝)
- (AggQuery.Sel φ q).evaluateRew x✝ = Multiset.filter φ.holdsRew (q.evaluateRew x✝)
- (q₁.Sum q₂).evaluateRew x✝ = q₁.evaluateRew x✝ + q₂.evaluateRew x✝
- (AggQuery.Retag h q).evaluateRew x✝ = q.evaluateRew x✝
Instances For
Dependency graph
Agreement with the plain semantics off the gates #
No token-building grouping: together with gate-freeness, this cuts
out the fragment on which the rewritten world's evaluator is the plain
semantics through the inl embedding.
Equations
- (AggQuery.Rel x✝ a).noGammaTok = True
- (AggQuery.Proj ps q).noGammaTok = q.noGammaTok
- (AggQuery.Sel a q).noGammaTok = q.noGammaTok
- (q₁.Prod q₂).noGammaTok = (q₁.noGammaTok ∧ q₂.noGammaTok)
- (q₁.Sum q₂).noGammaTok = (q₁.noGammaTok ∧ q₂.noGammaTok)
- q.Dedup.noGammaTok = q.noGammaTok
- (q₁.Diff q₂).noGammaTok = (q₁.noGammaTok ∧ q₂.noGammaTok)
- (AggQuery.Gamma is ts fs q).noGammaTok = q.noGammaTok
- (AggQuery.ProvSum is his t q).noGammaTok = q.noGammaTok
- (AggQuery.Retag h q).noGammaTok = q.noGammaTok
- (AggQuery.GammaTok is his ts fs a a_1).noGammaTok = False
Instances For
Dependency graph
No indicator gate anywhere in a query's terms and predicates.
Equations
- (AggQuery.Rel x✝ a).chiFree = True
- (AggQuery.Proj ps q).chiFree = ((∀ (j : Fin x✝), (ps j).chiFree) ∧ q.chiFree)
- (AggQuery.Sel a q).chiFree = (a.chiFree ∧ q.chiFree)
- (q₁.Prod q₂).chiFree = (q₁.chiFree ∧ q₂.chiFree)
- (q₁.Sum q₂).chiFree = (q₁.chiFree ∧ q₂.chiFree)
- q.Dedup.chiFree = q.chiFree
- (q₁.Diff q₂).chiFree = (q₁.chiFree ∧ q₂.chiFree)
- (AggQuery.Gamma is ts fs q).chiFree = q.chiFree
- (AggQuery.ProvSum is his t q).chiFree = (t.chiFree ∧ q.chiFree)
- (AggQuery.Retag h q).chiFree = q.chiFree
- (AggQuery.GammaTok is his ts fs a a_1).chiFree = (a.chiFree ∧ a_1.chiFree)
Instances For
Dependency graph
On inl-embedded rows a gate-free term evaluates in the rewritten
world as its plain evaluation – including the cmpAgg gate, whose junk
reading 𝟘 is definitionally the composite zero on a row with no
token. The indicator gate has no such escape: it returns a genuine
annotation, which is why it is excluded here.
Dependency graph
Gate-free projection columns on inl-embedded rows evaluate to the
embedded plain reading.
Dependency graph
Gate-free predicates on inl-embedded rows hold as their plain
reading.
Dependency graph
Maps push through the multiset product.
Dependency graph
Collapsing inl-embedded rows is the identity.
Dependency graph
Plain agreement. Off the token-building operator, the rewritten
world's evaluator is the plain semantics through the inl embedding.
Dependency graph
The fused predicate provenance under the composite embedding #
The rewritten site groups composite rows – the inl-embedded data with
the annotation appended as the provenance column – while the annotated
site groups the original annotated tuples. The fused predicate
provenance is invariant under this embedding: comparisons restrict along
inl, the lifted aggregate computes on the embedded values, and the
occurrence annotations are read off unchanged.
Lift a sequence aggregate to the composite domain (junk on the
annotation arm, faithful on inl-embedded values).
Instances For
Dependency graph
The lifted aggregate on inl-embedded values.
Dependency graph
Comparison operators restrict along the inl embedding.
Dependency graph
The comparison indicator restricts along the inl embedding.
Dependency graph
The classical rewriting stays off the token operators #
The classical rewriting emits no token-building grouping.
Dependency graph
The classical rewriting emits no indicator gate: its terms are
column reads, their ⊗/⊖ combinations, and composite casts of the
source terms – the gate is introduced only by the HAVING site.
Dependency graph
The group sequence under the composite embedding #
Coordinates of the composite embedding of an annotated tuple.
Dependency graph
The composite order restricts to the value order on inl.
Dependency graph
The composite order restricts to the alternative order on inr.
Dependency graph
The group sequence under the composite embedding: embedding the
relation and the key inl-wise embeds the group sequence. The embedding
is monotone for the sort's tie-break order (data columns compare on the
inl arm, the appended provenance column and the annotation both by the
alternative order), and sorted lists of the same multiset are unique.
Dependency graph
Reading a rewritten evaluation back as an annotated relation #
Mapping a key-only function over a grouped relation is mapping it over the deduplicated keys (the accumulated annotations are unread).
Dependency graph
The rewritten world reads back as an annotated relation. Pairing the collapsed data columns of the rewritten evaluation of a classical rewriting with the annotation read off its provenance column recovers the composite embedding of the classical annotated semantics – the input the token-building groupings of the rewritten world consume.