Compositional correctness of the JOIN rewriting for HAVING COUNT(*) #
Provenance.HavingQueryCorrectness proves the join-based rewriting of a
HAVING COUNT(*) op (C+1) correct extensionally: per group key, the sum
of the annotations of the join query's rows is the fused predicate
provenance. This file upgrades that to an intensional, multiset-level
equality, the form needed to substitute the rewriting for the fused
operator inside an arbitrary surrounding query.
The one obstruction to multiset-level equality is the failing groups: the
fused operator emits a π-annotated row for a group that fails the
comparison, while the join query emits no row at all. The rewriting is
therefore padded: joinCountQueryPadded adds to the join query the
self-difference keysQuery q β keysQuery q β one π-annotated row per
group key β and duplicate-eliminates the union, which merges everything
into exactly one row per group key carrying the summed annotation. The
result (joinCountQueryPadded_correct) is equal as a multiset of
annotated tuples to the key projection of the fused HAVING output
(proj_fused_eq_keyed), so the substitution is transparent to every
surrounding operator β including annotation-sensitive ones like Diff
and further HAVINGs, which are not congruences for the naive
βequal up to π-rowsβ relation (a π-annotated row still changes the
deterministic aggregate values of an enclosing group).
AnnotatedRelation is an opaque def over Multiset, so instance
search does not see the multiset membership through it; register it.
Dependency graph
The padded join query #
The canonical key selector of the (key, value, identifier) base
schema.
Equations
- keyIdx xβ = β¨0, keyIdx._proof_2β©
Instances For
Dependency graph
The key column, as a projection term.
Instances For
Dependency graph
The group key of an annotated base row.
Equations
- keyOf p xβ = p.1 β¨0, keyIdx._proof_2β©
Instances For
Dependency graph
One row per distinct group key, annotated by the β-sum of the
group's annotations.
Instances For
Dependency graph
One π-annotated row per distinct group key: the self-difference of
the key query (Ξ± β Ξ± = π).
Equations
- zeroPadQuery q = (keysQuery q - keysQuery q)
Instances For
Dependency graph
The padded join-based rewriting of HAVING COUNT(*) op (C + 1):
the join query, padded with a π-annotated row per group key and
duplicate-eliminated into one row per group key.
Equations
- joinCountQueryPadded q op C = Ξ΅ (q.joinCountQuery op C β zeroPadQuery q)
Instances For
Dependency graph
Dependency graph
Dependency graph
Dependency graph
Key bookkeeping #
Every row of the join chain carries the key of some base row in its key coordinate.
Dependency graph
The key multiset of the base query, through the key projection.
Dependency graph
Every row of the chain-projected key query carries a key of the base query.
Dependency graph
Rows of a difference keep the data parts of its left argument.
Dependency graph
Every row of the join-based query, for any comparison operator, carries a key of the base query.
Dependency graph
Evaluation of the padding #
The key query evaluates to one row per distinct key with the summed annotation.
Dependency graph
The padding query evaluates to one π-annotated row per distinct
key.
Dependency graph
Site correctness: the padded rewriting, row for row #
Multiset-level correctness of the padded JOIN rewriting. In an
absorptive commutative m-semiring whose β distributes over β, the
padded join-based query evaluates to exactly β row for row, annotation
for annotation β one row per group key of the base query, annotated with
the fused COUNT(*) op (C + 1) predicate provenance. The sole hypothesis
is the injective per-group occurrence identifiers (global
row-distinctness of the base query's output).
Dependency graph
The key-projected fused output. Projecting the fused
HAVING COUNT(*) op (C + 1) site output to its group key yields the same
one-row-per-key relation the padded join query evaluates to: combined
with joinCountQueryPadded_correct, the padded rewriting can be
substituted for the key-projected fused operator inside any surrounding
query.
Dependency graph
Site substitution. The key-projected fused
HAVING COUNT(*) op (C + 1) site over the embedded classical query and
the padded join-based rewriting
evaluate to the same multiset of annotated tuples: substituting one for
the other inside any surrounding query preserves the annotated semantics
verbatim.