The rewriting rules (R1)–(R4), natively on the general syntax #
The rewriting of Sen, Maniu & Senellart, ProvSQL
turns a query over annotated relations into an ordinary query over the
composite encoding: one extra column carries the annotation, of the
lifted value type T ⊕ K. With the three-kind discipline the rewriting
is expressible natively: the annotation column is marked prov
(ColKind.rewKinds), read back by TermG.provIndex terms, aggregated by
AggQuery.ProvSum (the ⊕-gate creation of ε and ∖), and the
value-kind bookkeeping is AggQuery.Retag – semantically the identity.
AggQuery.rewriting below mirrors the classical Query.rewriting
rule for rule on the classical fragment (AggQuery.classical) of the
general syntax. Its correctness against evaluateAnnotated is
assembled in stages: faithfulness of the classical strip, the classical
correctness theorem Query.rewriting_valid, and the plain-semantics
agreement of the two rewritten queries.
The target kind vector #
The kind vector of a rewritten query: n data columns followed by
the provenance column.
Equations
- ColKind.rewKinds n k = if ↑k < n then ColKind.reg else ColKind.prov
Instances For
Dependency graph
Dependency graph
Dependency graph
Dependency graph
Retag any pointwise value-kinded query to the rewriting kinds.
Equations
- AggQuery.retagToRew h q = AggQuery.Retag ⋯ q
Instances For
Dependency graph
The classical fragment #
The classical (R1)–(R4) source fragment of the general syntax: no grouping, no provenance aggregation, no retagging, projections through regular terms only, selections without aggregate atoms.
Equations
- (AggQuery.Rel x✝ a).classical = True
- (AggQuery.Proj ps q).classical = ((∀ (j : Fin x✝), (ps j).kind = ColKind.reg) ∧ q.classical)
- (AggQuery.Sel φ q).classical = (φ.hasAggAtom = false ∧ q.classical)
- (q₁.Prod q₂).classical = (q₁.classical ∧ q₂.classical)
- (q₁.Sum q₂).classical = (q₁.classical ∧ q₂.classical)
- q.Dedup.classical = q.classical
- (q₁.Diff q₂).classical = (q₁.classical ∧ q₂.classical)
- (AggQuery.Gamma is ts fs a).classical = False
- (AggQuery.ProvSum is his t a).classical = False
- (AggQuery.Retag h a).classical = False
- (AggQuery.GammaTok is his ts fs a a_1).classical = False
Instances For
Dependency graph
Classical queries have all-regular kinds (pointwise).
Dependency graph
Casting terms, predicates and columns to the composite domain #
A term over all-regular columns, over the composite domain with its columns shifted into the data block of the rewritten schema.
Equations
- TermG.castComposite hκ (TermG.const a) = TermG.const (Sum.inl a)
- TermG.castComposite hκ (TermG.index k a) = TermG.index (Fin.castLE ⋯ k) ⋯
- TermG.castComposite hκ (TermG.provIndex k h) = absurd ⋯ ⋯
- TermG.castComposite hκ (TermG.cmpAgg k h a a_1) = absurd ⋯ ⋯
- TermG.castComposite hκ (TermG.chiGate a a_1 a_2) = TermG.const (Sum.inl 0)
- TermG.castComposite hκ (t₁.add t₂) = (TermG.castComposite hκ t₁).add (TermG.castComposite hκ t₂)
- TermG.castComposite hκ (t₁.sub t₂) = (TermG.castComposite hκ t₁).sub (TermG.castComposite hκ t₂)
- TermG.castComposite hκ (t₁.mul t₂) = (TermG.castComposite hκ t₁).mul (TermG.castComposite hκ t₂)
Instances For
Dependency graph
An aggregate-atom-free predicate, over the composite domain.
Equations
- GenPred.castComposite hκ (GenPred.cmp op t₁ t₂) x_2 = GenPred.cmp op (TermG.castComposite hκ t₁) (TermG.castComposite hκ t₂)
- GenPred.castComposite hκ (GenPred.aggCmp k a a_1 a_2) hφ = Bool.noConfusion hφ
- GenPred.castComposite hκ (φ.and ψ) hφ = (GenPred.castComposite hκ φ ⋯).and (GenPred.castComposite hκ ψ ⋯)
- GenPred.castComposite hκ (φ.or ψ) hφ = (GenPred.castComposite hκ φ ⋯).or (GenPred.castComposite hκ ψ ⋯)
- GenPred.castComposite hκ φ.not hφ = (GenPred.castComposite hκ φ hφ).not
Instances For
Dependency graph
A regular projection column, over the composite domain.
Equations
- ProjCol.castComposite hκ (ProjCol.term t) x_2 = ProjCol.term (TermG.castComposite hκ t)
- ProjCol.castComposite hκ (ProjCol.token k a) hp = ColKind.noConfusion hp
- ProjCol.castComposite hκ (ProjCol.provTerm a) hp = ColKind.noConfusion hp
Instances For
Dependency graph
The composite cast emits no indicator gate: a source gate, whose generic semantics is the junk constant, casts to that constant.
Dependency graph
The composite cast of a predicate emits no indicator gate.
Dependency graph
The composite cast of a projection column emits no indicator gate.
Dependency graph
Dependency graph
Join conditions on key columns #
The conjunction of equalities between two blocks of regular columns
(the join condition of the Diff rewriting).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The join condition is a conjunction of column equalities: no indicator gate.
Dependency graph
The rewriting #
The (R1)–(R4) rewriting, natively on the general syntax. Each
rule mirrors the classical Query.rewriting: the base relation exposes
its provenance column (R1), projections keep it verbatim (R2, key case),
selections filter the data columns (R2), joins multiply the two
provenance columns (R3), unions concatenate (R4, first case),
deduplication ⊕-sums the provenance per surviving tuple (R4, ε), and
difference combines the unmatched branch with the matched branch's
α ⊖ Σβ (R4, ∖).
Equations
- One or more equations did not get rendered due to their size.
- (AggQuery.Rel x s).rewriting x_4 = AggQuery.retagToRew ⋯ (AggQuery.Rel (x + 1) s)
- (AggQuery.Sel φ q).rewriting hq = AggQuery.Sel (GenPred.castComposite ⋯ φ ⋯) (q.rewriting ⋯)
- (q₁.Sum q₂).rewriting hq = (q₁.rewriting ⋯).Sum (q₂.rewriting ⋯)
- q.Dedup.rewriting hq = AggQuery.retagToRew ⋯ (AggQuery.ProvSum (fun (k : Fin x) => Fin.castLE ⋯ k) ⋯ (TermG.provIndex (Fin.last x) ⋯) (q.rewriting hq))
Instances For
Dependency graph
Stripping to the classical syntax #
The classical fragment of the general syntax maps back to the classical
Query syntax; the correctness of the native rewriting is assembled
through this strip, the classical correctness theorem, and the
plain-semantics agreement of the two rewritten queries.
Strip a term over regular columns to a classical term (the
provIndex arm is unreachable on the classical fragment and mapped
harmlessly).
Equations
- (TermG.const a).strip = Term.const a
- (TermG.index k a).strip = #k
- (TermG.provIndex k h).strip = #k
- (TermG.cmpAgg k h a a_1).strip = Term.const 0
- (TermG.chiGate a a_1 a_2).strip = Term.const 0
- (t₁.add t₂).strip = t₁.strip.add t₂.strip
- (t₁.sub t₂).strip = t₁.strip.sub t₂.strip
- (t₁.mul t₂).strip = t₁.strip.mul t₂.strip
Instances For
Dependency graph
Plain evaluation factors through the strip.
Dependency graph
Strip an aggregate-atom-free predicate to a classical selection.
Equations
- (GenPred.cmp CompOp.eq t₁ t₂).strip = Selection.BT (BoolTerm.EQ t₁.strip t₂.strip)
- (GenPred.cmp CompOp.ne t₁ t₂).strip = Selection.BT (BoolTerm.NE t₁.strip t₂.strip)
- (GenPred.cmp CompOp.le t₁ t₂).strip = Selection.BT (BoolTerm.LE t₁.strip t₂.strip)
- (GenPred.cmp CompOp.lt t₁ t₂).strip = Selection.BT (BoolTerm.LT t₁.strip t₂.strip)
- (GenPred.cmp CompOp.ge t₁ t₂).strip = Selection.BT (BoolTerm.GE t₁.strip t₂.strip)
- (GenPred.cmp CompOp.gt t₁ t₂).strip = Selection.BT (BoolTerm.GT t₁.strip t₂.strip)
- (GenPred.aggCmp k a a_1 a_2).strip = Selection.True
- (φ.and ψ).strip = φ.strip.And ψ.strip
- (φ.or ψ).strip = φ.strip.Or ψ.strip
- φ.not.strip = φ.strip.Not
Instances For
Dependency graph
Classical truth factors through the strip, on aggregate-atom-free predicates.
Dependency graph
Strip a regular projection column to a classical term.
Equations
- (ProjCol.term t).strip = t.strip
- (ProjCol.token k a).strip = Term.const 0
- (ProjCol.provTerm t).strip = t.strip
Instances For
Dependency graph
Strip a classical-fragment query to the classical syntax.
Equations
- (AggQuery.Rel x s).strip x_4 = Query.Rel x s
- (AggQuery.Proj ps q).strip hq = (Π fun (j : Fin x) => (ps j).strip) (q.strip ⋯)
- (AggQuery.Sel φ q).strip hq = σ φ.strip (q.strip ⋯)
- (q₁.Prod q₂).strip hq = q₁.strip ⋯ × q₂.strip ⋯
- (q₁.Sum q₂).strip hq = (q₁.strip ⋯ ⊎ q₂.strip ⋯)
- q.Dedup.strip hq = ε (q.strip hq)
- (q₁.Diff q₂).strip hq = (q₁.strip ⋯ - q₂.strip ⋯)
- (AggQuery.Gamma is ts fs a).strip hq = False.elim hq
- (AggQuery.ProvSum is his t a).strip hq = False.elim hq
- (AggQuery.Retag h a).strip hq = False.elim hq
- (AggQuery.GammaTok is his ts fs a a_1).strip hq = False.elim hq
Instances For
Dependency graph
The strip is aggregation-free.
Dependency graph
Faithfulness of the strip #
The collapsed data part of an invariant row is its classical counterpart's data part.
Dependency graph
Row-wise faithfulness of the strip: on the classical fragment, the general evaluator produces rows satisfying the embedding invariant against the classical annotated evaluation of the stripped query.
Dependency graph
Faithfulness of the strip: on the classical fragment the general annotated evaluator computes the classical annotated semantics of the stripped query.
Dependency graph
Plain-semantics agreement of the two rewritten queries #
The composite cast of a term agrees with the classical cast of its strip.
Dependency graph
The composite cast of a predicate agrees with the classical cast of its strip.
Dependency graph
The composite cast of a projection column agrees with the classical cast of its strip.
Dependency graph
Dependency graph
Dependency graph
Dependency graph
Dependency graph
Plain-semantics agreement: the native rewriting and the classical rewriting of the stripped query evaluate identically on any composite database.
Dependency graph
Rewriting correctness #
Correctness of the native rewriting. For a classical query in the
general syntax, evaluating the annotated semantics and folding the result
into composite T ⊕ K tuples agrees with evaluating the rewritten query
under the plain semantics over the composite database. This is the
general-syntax form of the classical rewriting correctness.