Two Structural Axes of SQL Bag Equivalence: Graph Dichotomies, Guarded Counting, and Ordered Two-Variable Counting Ideals
SQL bag equivalence asks whether two queries return each row with the same multiplicity on every legal finite database. We separate the support of a database from the positive multiplicities of its stored tuples. After this separation, equivalence reduces to a finite family of equalities between counts of satisfying assignments. On the data axis, for a fixed minor-closed class of support graphs, the resulting decidability thresholds are bounded treewidth with equality, bounded matching number with a free linear order, and bounded vertex count with Presburger comparisons. Each decidable case has a computable bound on counterexample rows per table. One outermost bag difference or bag intersection separates freely repeatable inputs from key-controlled inputs. On the query axis, we prove decidability of assignment-count comparison in guarded-negation logic with constants, and obtain undecidability when selected functionality or comparison features are added. Two-variable counting logic recovers decidability for several key and foreign-key constraints. In this logic, with equality or one linear order and its successor, we compute a finite basis for all polynomial identities among given counts of unary and binary definable sets. The ordered construction preserves the entire word of vertex colors and computes its ordered-pair statistics by unipotent matrix products.
Authors
- Yang Li (ORCID: https://orcid.org/0009-0008-1301-0917)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-12-02
- DOI
- https://doi.org/10.5281/zenodo.24742146
- Primary Topic
- Advanced Graph Theory Research
- Type
- preprint