Embedding the classical query syntax into the general evaluator #
Query.toAgg embeds a non-aggregating classical query into the
kind-indexed general syntax AggQuery, over all-regular kinds:
terms, selection predicates and every operator translate one to one.
Query.toAgg_bridge proves the embedding faithful – the general
evaluator computes the classical annotated semantics – via a row-wise
invariant GenRow.Inv (regular data, finalized annotation) that absorbs
the bookkeeping differences of the factored annotations (a pending
multiset that stays empty, bases multiplied by empty products).
On top of the embedding, Query.toAggHaving_input reads the input
relation of a general HAVING site over an embedded subquery off the
classical query's annotated semantics, which is what the query-level
HAVING correctness results consume.
This module sits below the classical HAVING correctness files
(Provenance.HavingQueryCorrectness,
Provenance.HavingJoinCompositional) so that they can state their
theorems over the embedded general query directly, with no side
hypothesis. The compositional JOIN rewriting built on top of the
embedding lives in Provenance.AggQueryEmbedding.
Terms and selections over all-regular kinds #
A classical term, as a term over all-regular columns.
Equations
Instances For
Dependency graph
The embedded term evaluates on a regular-values row as the original term on the underlying tuple.
Dependency graph
A comparison atom, as a generalized regular atom.
Equations
- (BoolTerm.EQ t₁ t₂).toGenPred = GenPred.cmp CompOp.eq t₁.toGenReg t₂.toGenReg
- (BoolTerm.NE t₁ t₂).toGenPred = GenPred.cmp CompOp.ne t₁.toGenReg t₂.toGenReg
- (BoolTerm.LE t₁ t₂).toGenPred = GenPred.cmp CompOp.le t₁.toGenReg t₂.toGenReg
- (BoolTerm.LT t₁ t₂).toGenPred = GenPred.cmp CompOp.lt t₁.toGenReg t₂.toGenReg
- (BoolTerm.GE t₁ t₂).toGenPred = GenPred.cmp CompOp.ge t₁.toGenReg t₂.toGenReg
- (BoolTerm.GT t₁ t₂).toGenPred = GenPred.cmp CompOp.gt t₁.toGenReg t₂.toGenReg
Instances For
Dependency graph
A classical selection predicate, as a generalized predicate without
aggregate atoms (Selection.True becomes the tautology 𝟘 = 𝟘).
Equations
Instances For
Dependency graph
Embedded selections have no aggregate atoms: the evaluator filters classically.
Dependency graph
The embedded predicate holds on a regular-values row exactly when the original selection accepts the underlying tuple.
Dependency graph
The embedding #
Appending all-regular kind vectors.
Dependency graph
The embedding of the non-aggregating fragment: every classical operator translates to its general counterpart, over all-regular kinds.
Equations
- (Query.Rel x s).toAgg x_3 = AggQuery.Rel x s
- (Π ts q).toAgg hq = AggQuery.castKind ⋯ (AggQuery.Proj (fun (j : Fin x) => ProjCol.term (ts j).toGenReg) (q.toAgg ⋯))
- (σ φ q).toAgg hq = AggQuery.Sel φ.toGenPred (q.toAgg ⋯)
- (q₁ × q₂).toAgg hq = hn ▸ AggQuery.castKind ⋯ ((q₁.toAgg ⋯).Prod (q₂.toAgg ⋯))
- (q₁ ⊎ q₂).toAgg hq = (q₁.toAgg ⋯).Sum (q₂.toAgg ⋯)
- (ε q).toAgg hq = (q.toAgg ⋯).Dedup
- (q₁ - q₂).toAgg hq = (q₁.toAgg ⋯).Diff (q₂.toAgg ⋯)
- (Query.ProvSum a a_1 a_2).toAgg hq = ⋯.elim
- (Query.Having a a_1 a_2 a_3 a_4 a_5 a_6).toAgg hq = ⋯.elim
Instances For
Dependency graph
Faithfulness #
The row invariant of the embedding: regular data over the classical
tuple, a factored annotation finalizing to the classical one, and no
pending group factors (the embedding image contains no Gamma).
Equations
Instances For
Dependency graph
Invariant rows finalize to their classical counterparts.
Dependency graph
Embedded classical rows satisfy the invariant.
Dependency graph
Faithfulness of the embedding, row for row: the general evaluator on the embedded query produces rows satisfying the invariant against the classical annotated evaluation.
Dependency graph
Faithfulness of the embedding: the general evaluator computes the classical annotated semantics on embedded queries.
Dependency graph
An invariant row is the embedding of its classical counterpart: the pending multiset is empty, so the base coincides with the finalized annotation.
Dependency graph
The embedding at the row level: the general evaluator on an embedded query produces exactly the embedded classical rows.
Dependency graph
The fused HAVING, in context #
The fused HAVING site over an embedded subquery: its input
relation is the classical subquery's annotated evaluation, so the closed
form AggQuery.havingSite_evaluateAnnotated specializes to the
classical setting with no side hypothesis.