Query-level counterexamples for the HAVING / JOIN correspondence #
The correspondence between the possible-world semantics of HAVING
comparisons on COUNT(*) and the JOIN-based rewriting holds in
commutative m-semirings that are absorptive and whose ⊗ distributes over
⊖. This file witnesses, at the level of queries evaluated on concrete
annotated databases (not merely of the underlying algebraic identities),
that both hypotheses are needed. All facts are checked by decide.
The instances share the base relation R(g, v) of arity 2, grouped by the
first column; on the fused side the query is
the general HAVING site for COUNT(*) op C and on the join side
the queries are
Q₂^{≥1} = ε(Π_{#0}(R)),Q₂^{≥2} = ε(Π_{#0}(σ_{#0=#2 ∧ #1<#3}(R × R))), andQ₂^{=1} = Q₂^{≥1} - Q₂^{≥2},
the tie-broken comparison of the general construction degenerating to the
plain < because the second attributes of the instances are pairwise
distinct. The fused operator's output carries the group key and the
aggregate value while the join queries return the key only, so the
comparison is on the multisets of annotations.
Distributivity is needed (
HavingQueryCounterexamples.ChainFive.query_counterexample): in the five-element chain semiring – absorptive, hence idempotent, but not⊗-over-⊖distributive (ChainFive.not_mul_sub_left_distributive) – with annotations(mid, hi, hi)on one group,COUNT(*) = 1yields annotationhion the fused side but𝟘on the join side.Absorptivity is needed (
HavingQueryCounterexamples.TropicalZ.query_counterexample): in the tropical semiring overℤ ∪ {∞}– idempotent and distributive (TropicalZ.mul_sub_left_distributive) but not absorptive (TropicalZ.not_absorptive_witness) – with two occurrences annotatedtrop (-1)in one group,COUNT(*) ≥ 1yields annotationtrop (-2)on the fused side buttrop (-1)on the join side.
The two-column base relation R(g, v).
Equations
Instances For
Dependency graph
The same base relation as a general query, for the HAVING site.
Equations
Instances For
Dependency graph
Q₂^{≥1} = ε(Π_{#0}(R)).
Equations
Instances For
Dependency graph
Q₂^{≥2} = ε(Π_{#0}(σ_{#0=#2 ∧ #1<#3}(R × R))).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
Q₂^{=1} = Q₂^{≥1} - Q₂^{≥2}.
Equations
Instances For
Dependency graph
One group with key 0, values 1, 2, 3, annotations mid, hi, hi.
Equations
Instances For
Dependency graph
Fused side: COUNT(*) = 1 has predicate provenance hi (each
singleton world contributes its own annotation, the factored
discarded-occurrence factor 𝟙 ⊖ hi being 𝟙 in the chain).
Dependency graph
Join side: Q₂^{=1} has annotation 𝟘 (hi ⊖ hi).
Dependency graph
Query-level part of the distributivity necessity: in the
absorptive but non-distributive ChainFive, the fused COUNT(*) = 1
query and its join-based rewriting disagree on a concrete instance.
Dependency graph
Absorptivity is needed: the tropical instance over ℤ ∪ {∞} #
The tropical semiring over ℤ ∪ {∞} is not absorptive:
𝟙 ⊕ trop (-1) = trop (-1) ≠ 𝟙.
Dependency graph
The tropical semiring over ℤ ∪ {∞} is ⊗-over-⊖ distributive.
Dependency graph
One group with key 0, values 1, 2, both annotated trop (-1).
Equations
Instances For
Dependency graph
Fused side: COUNT(*) ≥ 1 has predicate provenance trop (-2): the
two singleton worlds have annotation trop (-1) ⊗ (𝟙 ⊖ trop (-1)) = 𝟘,
and only the full world trop (-1) ⊗ trop (-1) = trop (-2) survives.
Dependency graph
Join side: Q₂^{≥1} has annotation trop (-1) ⊕ trop (-1) = trop (-1).
Dependency graph
Query-level part of the absorptivity necessity: in the idempotent
and distributive but non-absorptive tropical semiring over ℤ ∪ {∞}, the
fused COUNT(*) ≥ 1 query and its join-based rewriting disagree on a
concrete instance. Same phenomenon as the algebra-level
TropicalR.F_ne_S, here at the level of evaluated queries.