Genericity of the minimal universe: a query reads its parameters only up to order #
The order-type lemma: a recursion-free query of the minimal signature, with parameters, answers up to the substitution of its parameters the same on any two parameter tuples that fall the same way among a finite set of values the query and the instance fix. This module builds the pieces: a faithful value map – a function of values that keeps the null apart and the order among the values it is read on – and the fact that every comparison the evaluator makes commutes with one.
Faithful value maps #
A value map faithful on a set: it keeps the null and the order among the values of the set. Every comparison the minimal signature makes between values of the set is preserved by it.
- isNull (a : T) : a ∈ W → ValueType.isNull (τ a) = ValueType.isNull a
Instances For
Dependency graph
The constants a query names, all of them #
AggQueryIn.consts lists a projection's constants only, which is what the
value analysis needs; a value map that is to commute with the evaluator has
to fix the constants of every comparison too.
The constants of a Boolean term.
Equations
- b.consts = TermIn.consts b.args.1 ∪ TermIn.consts b.args.2
Instances For
Dependency graph
The constants of a classical selection.
Equations
Instances For
Dependency graph
The constants of a clause, or none.
Equations
Instances For
Dependency graph
The constants of a predicate of the general syntax.
Equations
Instances For
Dependency graph
The constants of a family of terms.
Equations
- TermIn.constsFam ts = Finset.univ.biUnion fun (j : Fin m) => (ts j).consts
Instances For
Dependency graph
Every constant a query names, in its columns, its predicates, its clauses and the terms its aggregates read.
Equations
- (AggQueryIn.Rel x✝ a).allConsts = ∅
- (AggQueryIn.Hole x✝¹ s x✝).allConsts = ∅
- (AggQueryIn.Param pv x✝).allConsts = Finset.univ.biUnion fun (k : Fin x✝¹) => Sum.elim (fun (a : T) => {a}) (fun (x : Fin x✝²) => ∅) (pv k)
- AggQueryIn.Empty.allConsts = ∅
- (AggQueryIn.Proj ps q).allConsts = (Finset.univ.biUnion fun (j : Fin x✝¹) => (ps j).consts) ∪ q.allConsts
- (AggQueryIn.Sel φ q hφ).allConsts = φ.consts ∪ q.allConsts
- (q₁.Prod q₂).allConsts = q₁.allConsts ∪ q₂.allConsts
- (q₁.Apply q₂).allConsts = q₁.allConsts ∪ q₂.allConsts
- (q₁.Sum q₂).allConsts = q₁.allConsts ∪ q₂.allConsts
- q.Dedup.allConsts = q.allConsts
- (q₁.Diff q₂).allConsts = q₁.allConsts ∪ q₂.allConsts
- (AggQueryIn.Explode k a q).allConsts = q.allConsts
- (AggQueryIn.Retag h q).allConsts = q.allConsts
- (AggQueryIn.Mu s q₀ q₁).allConsts = q₀.allConsts ∪ q₁.allConsts
- (AggQueryIn.MuSet s q₀ q₁).allConsts = q₀.allConsts ∪ q₁.allConsts
- (AggQueryIn.Gamma is ts fs q keep ord).allConsts = (TermIn.constsFam ts ∪ Finset.univ.biUnion fun (j : Fin n₂) => Selection.constsOpt (keep j)) ∪ q.allConsts
- (AggQueryIn.GammaScalar ts fs q ord).allConsts = TermIn.constsFam ts ∪ q.allConsts
- (AggQueryIn.GammaNest is his p f q).allConsts = p.consts ∪ q.allConsts
- (AggQueryIn.ProvSum is his t q).allConsts = t.consts ∪ q.allConsts
- (AggQueryIn.GammaTok is his ts fs a q keep).allConsts = (TermIn.constsFam ts ∪ a.consts ∪ Finset.univ.biUnion fun (j : Fin n₂) => Selection.constsOpt (keep j)) ∪ q.allConsts
- (AggQueryIn.Win P O o w t f q a dist keep).allConsts = t.consts ∪ Selection.constsOpt keep ∪ q.allConsts
- (AggQueryIn.WinExpr P O o ws ts fs g q_1 keeps).allConsts = (TermIn.constsFam ts ∪ Finset.univ.biUnion fun (j : Fin q) => Selection.constsOpt (keeps j)) ∪ q_1.allConsts
Instances For
Dependency graph
Terms, predicates and selections under a faithful map #
A function-free term is a column, an outer column or a constant, so a map fixing the constants commutes with it; a comparison between values of the set the map is faithful on reads alike.
What a count reads #
A count is a function of how many non-null values its sequence holds
(SeqAggFunc.ReadsCount), so it reads a listing of a bag through the bag's
non-null count alone, and a faithful map of the bag's rows keeps that
count.
The non-null count of a term over a bag of rows.
Equations
- Multiset.nonNullCount t γ S = Multiset.countP (fun (u : Tuple T m) => ValueType.isNull (t.eval u γ) = false) S
Instances For
Dependency graph
Frames and window values under a faithful map #
The values a query computes #
In the minimal signature a query builds a value only by counting: every
other value of its result is read off the instance, off the context or off
its own constants. AggQueryIn.countValsAll collects the counts – the
values of the aggregate columns of every aggregating node, at every
context and, under a recursion, at every round – so that the value lemma
AggQueryIn.valsIn_evaluatePlain can say where every value of a result
comes from.
A relation with every value mapped.
Equations
- Relation.mapVals τ r = Multiset.map (fun (u : Fin n → T) => τ ∘ u) r
Instances For
Dependency graph
The counts a query computes: the values of the aggregate columns of each of its aggregating nodes, over every context, and, under a recursion, over every relation the recursive name may be bound to. It is the set a faithful map must fix for the query to commute with it.
Equations
- One or more equations did not get rendered due to their size.
- (AggQueryIn.Rel x✝¹ a).countValsAll x✝ = ∅
- (AggQueryIn.Hole x✝² s x✝¹).countValsAll x✝ = ∅
- (AggQueryIn.Param pv x✝¹).countValsAll x✝ = ∅
- AggQueryIn.Empty.countValsAll x✝ = ∅
- (AggQueryIn.Proj ps q).countValsAll x✝ = q.countValsAll x✝
- (AggQueryIn.Sel φ q hφ).countValsAll x✝ = q.countValsAll x✝
- (q₁.Prod q₂).countValsAll x✝ = q₁.countValsAll x✝ ∪ q₂.countValsAll x✝
- (q₁.Apply q₂).countValsAll x✝ = q₁.countValsAll x✝ ∪ q₂.countValsAll x✝
- (q₁.Sum q₂).countValsAll x✝ = q₁.countValsAll x✝ ∪ q₂.countValsAll x✝
- q.Dedup.countValsAll x✝ = q.countValsAll x✝
- (q₁.Diff q₂).countValsAll x✝ = q₁.countValsAll x✝ ∪ q₂.countValsAll x✝
- (AggQueryIn.Explode k a q).countValsAll x✝ = q.countValsAll x✝
- (AggQueryIn.Retag h q).countValsAll x✝ = q.countValsAll x✝
- (AggQueryIn.Mu s q₀ q₁).countValsAll x✝ = q₀.countValsAll x✝ ∪ ⋃ (X : Relation T x✝²), q₁.countValsAll (Database.assign s X x✝)
- (AggQueryIn.MuSet s q₀ q₁).countValsAll x✝ = q₀.countValsAll x✝ ∪ ⋃ (X : Relation T x✝¹), q₁.countValsAll (Database.assign s X x✝)
- (AggQueryIn.ProvSum is his t q).countValsAll x✝ = q.countValsAll x✝
- (AggQueryIn.GammaTok is his ts fs a q keep).countValsAll x✝ = q.countValsAll x✝
- (AggQueryIn.WinExpr P O o ws ts fs g q_1 keeps).countValsAll x✝ = q_1.countValsAll x✝
Instances For
Dependency graph
Where every value of a result comes from: the instance at the relations the query reads (its holes included), the context, the query's constants, or a count the query computes. No settling is asked: a recursion's junk value is a sum of its rounds, which read like the rest.
Dependency graph
A query commutes with a faithful map #
A map that is faithful on the values a query reads, fixes its constants and fixes the counts it computes commutes with its evaluation: the result on the mapped instance in the mapped context is the mapped result. The counts have to be fixed because the query recomputes them – a count is the number of non-null values read, which the map preserves, so the mapped result holds the count and not its image. Nothing is asked of the recursions: their rounds correspond one by one, settling or not.
A query of the minimal signature commutes with a faithful map that fixes its constants and its counts: on an instance whose relations at the query's leaves are the mapped ones, in the mapped context, it returns the mapped result.
Dependency graph
Order types #
Two parameter tuples have the same order type over a finite set of values when each parameter falls at the same place among the set's values and the parameters compare alike pairwise. A map sending one to the other and fixing the set is then faithful on the set and on the first tuple, which is what the commutation theorem asks; over a set holding the null, the order type decides nullness too. There are finitely many order types over a set, polynomially many in its size, which is what bounds the counts a query can compute as its parameters vary.
How many values of S are at most x.
Instances For
Dependency graph
Dependency graph
The order types over S of tuples of c parameters.
Instances For
Dependency graph
The order type of a parameter tuple over S: for each parameter,
how many values of S are at most it and whether it is one of them, and
how the parameters compare pairwise.
Equations
Instances For
Dependency graph
Two tuples of one order type are related by a faithful map fixing the set, where the set holds the null.
Dependency graph
A representative parameter tuple of an order type, where one exists.
Equations
Instances For
Dependency graph
The values a relation holds at some of its columns.
Equations
- Relation.valsAtCols r J = J.biUnion fun (j : Fin n) => (Multiset.map (fun (u : Tuple T n) => u j) r).toFinset
Instances For
Dependency graph
The values at some columns of a query's result at a representative of
each order type over S.
Equations
- AggQueryIn.repVals S Q J D = Finset.univ.biUnion fun (ω : OrdType S c) => Relation.valsAtCols (Q.evaluatePlain D (ordRep S c ω)) J
Instances For
Dependency graph
The count types of a query over a base set B: at each
aggregating node, the values of its aggregate columns at a representative
of each order type of its context over B and the count types of its
input. Every count the query computes is one of these, and there are
polynomially many in |B|.
Equations
- One or more equations did not get rendered due to their size.
- AggQueryIn.countTypes B (AggQueryIn.Rel x✝¹ a) x✝ = ∅
- AggQueryIn.countTypes B (AggQueryIn.Hole x✝² s x✝¹) x✝ = ∅
- AggQueryIn.countTypes B (AggQueryIn.Param pv x✝¹) x✝ = ∅
- AggQueryIn.countTypes B AggQueryIn.Empty x✝ = ∅
- AggQueryIn.countTypes B (AggQueryIn.Proj ps q) x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (AggQueryIn.Sel φ q hφ) x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (q₁.Prod q₂) x✝ = AggQueryIn.countTypes B q₁ x✝ ∪ AggQueryIn.countTypes B q₂ x✝
- AggQueryIn.countTypes B (q₁.Apply q₂) x✝ = AggQueryIn.countTypes B q₁ x✝ ∪ AggQueryIn.countTypes B q₂ x✝
- AggQueryIn.countTypes B (q₁.Sum q₂) x✝ = AggQueryIn.countTypes B q₁ x✝ ∪ AggQueryIn.countTypes B q₂ x✝
- AggQueryIn.countTypes B q.Dedup x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (q₁.Diff q₂) x✝ = AggQueryIn.countTypes B q₁ x✝ ∪ AggQueryIn.countTypes B q₂ x✝
- AggQueryIn.countTypes B (AggQueryIn.Explode k a q) x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (AggQueryIn.Retag h q) x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (AggQueryIn.Mu s q₀ q₁) x✝ = AggQueryIn.countTypes B q₀ x✝ ∪ AggQueryIn.countTypes B q₁ x✝
- AggQueryIn.countTypes B (AggQueryIn.MuSet s q₀ q₁) x✝ = AggQueryIn.countTypes B q₀ x✝ ∪ AggQueryIn.countTypes B q₁ x✝
- AggQueryIn.countTypes B (AggQueryIn.ProvSum is his t q) x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (AggQueryIn.GammaTok is his ts fs a q keep) x✝ = AggQueryIn.countTypes B q x✝
- AggQueryIn.countTypes B (AggQueryIn.WinExpr P O o ws ts fs g q_1 keeps) x✝ = AggQueryIn.countTypes B q_1 x✝
Instances For
Dependency graph
Every count is a count type #
At an aggregating node, the counts at a context are the counts at the representative of its order type: the two contexts are related by a faithful map fixing the base set and the input's count types, with which the input commutes.
Every count a query computes is a count type: over a base set holding the instance's values at the query's leaves, its constants, the zero and the null, the counts of a hygienic query of the minimal signature lie in the base set and its count types. The instance it is read at may differ from the one the count types are taken over at the holes, which is what a recursion's rounds need.
Dependency graph
There are polynomially many count types #
An aggregating node's count types at one order type are the values of its aggregate columns at one context, no more than its groups, which are tuples over the base set, the count types of its input and the context; and there are polynomially many order types.
A function of a natural number bounded by a polynomial.
Instances For
Dependency graph
There are (2(|S|+1))^c · 2^(c·c) order types over S of c parameters.
Dependency graph
There are polynomially many count types: the count types of a hygienic query of the minimal signature over a base set holding its instance values, its constants, the zero and the null number at most a polynomial, fixed by the query, in the size of the base set.
Dependency graph
A set recursion's fixpoint is polynomially bounded in the number of values it may read: its rows are duplicate-free tuples over the base set and the count types, of which there are polynomially many.