Documentation

Provenance.AggQueryAdequacy

Data-part adequacy of the general evaluator #

Forgetting the annotations of the general annotated evaluation of a query yields the plain (classical) evaluation of the stripped query on the plain database:

(q.evaluateAnnotated d).toPlain = q.stripAgg.evaluatePlain d.toPlain

This generalizes Query.evaluateAnnotated_toPlain to the kind-indexed syntax. The stripping removes differences (annotated Diff never removes tuple slots) and aggregate-atom selections (the annotated evaluator keeps classically-failing rows annotated šŸ˜, as ProvSQL emits them); on the remaining operators the data parts agree tuple for tuple, the aggregate tokens contributing through their deterministic collapse reading:

Plain readings through collapse #

theorem TermG.eval_eq_evalPlain {T : Type} [ValueType T] {K : Type} {n : ā„•} {Īŗ : Fin n → ColKind} (t : TermG T Īŗ) (u : Tuple (GenValue T K) n) :

A term over regular columns evaluates on a lifted tuple as its plain reading on the collapsed tuple.

Dependency graph
theorem ProjCol.collapseSum_eval {T : Type} [ValueType T] {K : Type} {n : ā„•} {Īŗ : Fin n → ColKind} (p : ProjCol T Īŗ) (u : Tuple (GenValue T K) n) :

A projection column collapses on a lifted tuple to its plain reading on the collapsed tuple.

Dependency graph
theorem GenPred.holds_iff_holdsPlain {T : Type} [ValueType T] {K : Type} {n : ā„•} {Īŗ : Fin n → ColKind} (φ : GenPred T Īŗ) (u : Tuple (GenValue T K) n) :

A predicate holds on a lifted tuple iff its plain reading holds on the collapsed tuple.

Dependency graph
@[simp]
theorem GenRow.plainTuple_ofAnnotated {T K : Type} {n : ā„•} (p : AnnotatedTuple T K n) :

The collapsed tuple of an embedded annotated tuple is its data part.

Dependency graph
theorem GenRow.plainTuple_append {T K : Type} {n₁ nā‚‚ : ā„•} (g : Tuple T n₁) (h : Fin nā‚‚ → AggValue T K) :
plainTuple (Fin.append (fun (k : Fin n₁) => Sum.inl (g k)) fun (j : Fin nā‚‚) => Sum.inr (h j)) = Fin.append g fun (j : Fin nā‚‚) => (h j).collapse

Collapsing distributes over appending a regular and a token part.

Dependency graph
theorem AggValue.collapse_ofGroup {T : Type} [ValueType T] {K : Type} {m : ā„•} (f : SeqAggFunc T) (t : Term T m) (U : List (AnnotatedTuple T K m)) :
(ofGroup f t U).collapse = f (List.map (fun (p : AnnotatedTuple T K m) => t.eval p.1) U)

The collapse of a group token is the plain aggregate of the group's value sequence.

Dependency graph

Multiset helpers #

theorem product_map_map {α₁ α₂ β₁ β₂ : Type} (f : α₁ → β₁) (g : α₂ → β₂) (s : Multiset α₁) (t : Multiset α₂) :
(Multiset.map f s).product (Multiset.map g t) = Multiset.map (fun (x : α₁ Ɨ α₂) => (f x.1, g x.2)) (s.product t)
Dependency graph

The keys of groupByKey are the deduplicated data parts (factored out of the Dedup case of Query.evaluateAnnotated_toPlain).

Dependency graph

The group-sequence bridge #

theorem havingGroup_map_fst {T : Type} [ValueType T] {K : Type} [CommSemiringWithMonus K] [HasAltLinearOrder K] {m n₁ : ā„•} (is : Tuple (Fin m) n₁) (r : AnnotatedRelation T K m) (g : Tuple T n₁) :

The data parts of the fused group sequence form the plain group sequence: both are lists of the same multiset of tuples, sorted by the canonical order on tuples – havingGroup's annotation tie-break is invisible after projection.

Dependency graph

The adequacy theorem #

Data-part adequacy of the general evaluator. Forgetting the annotations of the general annotated evaluation yields the plain evaluation of the stripped query on the plain database.

Dependency graph