Aggregate columns read as keys: the alternatives #
An operator reads a column either as a value, in a term, or as a
key, compared syntactically – the grouping indices of γ, the
partition and order of a window, the tuples ε merges and the
difference matches. Over a plain relation an aggregate value is a
value and both readings are the ordinary ones. Over an annotated
relation a key is read in each world, and an occurrence whose column
i holds an aggregate value a is read through its alternatives,
one for each value a takes:
(u[i ↦ v], α ⊗ [a ≐ v]) for v ∈ Val(a),
where [a ≐ v] is the predicate provenance of the atom a = v –
AggValue.altProv, read with SQL's null-safe equality so that the case
v = NULL is the atom a IS NULL and needs no separate clause. The
column of an alternative is regular, and the operator applies to the
alternatives. A GROUP BY on a count has thus one group per count the
groups can take, and a DISTINCT, a difference or a union over an
aggregate column is read likewise.
Two facts make the reading a reading of the worlds and not a way of
enumerating values. AggValue.sum_altProv: the alternatives' shares
add up to the whole of what the aggregate value's worlds carry, so
nothing is lost and nothing is invented. AggValue.altProv_mul_eq_zero:
distinct alternatives of one occurrence exclude each other where K is
exclusive, since distinct values come from distinct worlds – which is
the remark that in 𝔹[X] exactly one alternative of a present
occurrence holds under each valuation, and that over ℕ[X], where
exclusivity fails, an operator combining two alternatives of one
occurrence counts worlds that do not exist.