Provenance of HAVING Queries in Semirings with Monus

Aryak Sen, Pratik Karmakar, Silviu Maniu, Angelo Saadeh, Pierre SenellartarXiv 2026

This paper, recently presented by researchers from Univ. Grenoble Alpes and the National University of Singapore, tackles a long-standing challenge in database theory: how to track the "lineage" or provenance of complex SQL queries that use aggregation and HAVING clauses.

TL;DR

The authors introduce a new, implementable semantics for the provenance of HAVING queries using m-semirings (semirings equipped with a "monus" or subtraction-like operator). This approach allows for efficient provenance tracking and probabilistic query evaluation within existing systems like ProvSQL without requiring complex additional algebraic structures.

What Problem Does This Paper Address?

Data provenance tells us why a piece of data is in a query result by tagging it with annotations (like "this came from Table A and Table B"). The gold standard for this is the semiring framework, which works beautifully for basic operations like joins (multiplication) and unions (addition).

However, real-world SQL often uses GROUP BY and HAVING (e.g., "Find images having at least 3 refrigerators"). Standard semirings struggle here because they don't naturally "know" how to count or sum the annotations themselves. Previous attempts to fix this were either too abstract to implement or required moving outside the standard semiring framework into "semimodules," which broke compatibility with the tools used for probabilistic databases.

Methods

The authors propose using commutative m-semirings. An m-semiring is a semiring with a monus operator ($\ominus$), which behaves like a truncated subtraction (e.g., in natural numbers, $3 \ominus 5 = 0$).

Key Innovations:

  1. Possible-World Semantics: Instead of trying to calculate a single aggregate value for a group's provenance, they define the provenance of a HAVING condition as the sum of the provenances of all "possible worlds" (subsets of the group) that satisfy the condition.
  2. Monus for Negation: The monus operator is used to express that certain tuples are present while others are absent in a specific world.
  3. Formal Verification: The authors used the Lean theorem prover to machine-check the properties of various m-semirings, correcting several errors found in previous literature.
Properties of common commutative m-semirings, including their support for idempotence, absorptivity, and distributivity.

Datasets

The authors evaluated their implementation using a real-world probabilistic image-retrieval database.

  • Source: Objects detected by YOLOv5 on the COCO 2017 dataset.
  • Scale: 239,377 images and over 1.5 million object annotations, each associated with a probability score derived from the detector's confidence.

Key Insights and Ideas

  • The "Compile Once, Evaluate Many" Principle: The authors prove that their semantics commutes with semiring homomorphisms. This means you can compute the provenance once as a symbolic formula and then "specialize" it later to get a probability, a count, or a security clearance level.
  • Equivalence to Self-Joins: For COUNT(*) queries, they show that their new semantics matches the traditional (but often slow) method of rewriting the query as a massive self-join, provided the semiring has specific properties like absorptivity (where $1 + a = 1$).
  • Tractability: While general provenance for HAVING is NP-hard, the authors identified several "safe" cases (like MIN, MAX, and COUNT with fixed constants) that can be computed in polynomial time.

Key Results

The authors implemented their algorithms in ProvSQL, an open-source extension for PostgreSQL.

  • Performance: Their HAVING semantics is significantly more stable and faster than the "self-join" rewriting method as the complexity of the condition (the constant $k$ in COUNT(*) >= k) increases. For $k=15$, the new method was over 100 times faster in planning and execution.
  • Probabilistic Accuracy: The system correctly handles probabilistic query evaluation by leveraging the Poisson-binomial distribution for COUNT and SUM aggregates.

Limitations and Future Work

  • Commutativity: The current framework is restricted to commutative semirings, which excludes some specialized types of provenance (like those tracking the exact order of operations).
  • Nested Aggregates: The current semantics does not support grouping or aggregating over the results of another aggregation (e.g., "Average of counts").
  • Future Directions: The authors suggest extending this work to "safe plans" for more complex query shapes, potentially lifting the polynomial-time bounds to a broader class of HAVING queries.

Summary updated

BibTeX
@misc{sen2026provenance,
  author = {Aryak Sen and Pratik Karmakar and Silviu Maniu and Angelo Saadeh and Pierre Senellart},
  title = {{Provenance of HAVING Queries in Semirings with Monus}},
  year = {2026},
  eprint = {2609.31246},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.31246},
}
Figure