Axiomatic foundations and algorithms for deciding semantic equivalences of SQL queries
Shumo Chu, Brendan Murphy, Jared Roesch, Alvin Cheung, Dan Mircea Suciu · 2018 · 61 citationsRead the paper
Deciding the equivalence of SQL queries is a fundamental problem in data management. As prior work has mainly focused on studying the theoretical limitations of the problem, very few implementations for checking such equivalences exist. In this paper, we present a new formalism and implementation for reasoning about the equivalences of SQL queries. Our formalism, U-semiring, extends SQL's semiring semantics with unbounded summation and duplicate elimination. U-semiring is defined using only very few axioms and can thus be easily implemented using proof assistants such as Lean for automated query reasoning. Yet, they are sufficient enough to enable us reason about sophisticated SQL queries that are evaluated over bags and sets, along with various integrity constraints. To evaluate the effectiveness of U-semiring, we have used it to formally verify 68 equivalent queries and rewrite rules from both classical data management research papers and real-world SQL engines, where many of them have never been proven correct before.
What the full text shows
Working prototype- Automatically proved a majority of supported rewrite rules from Apache Calcite. — 33 out of 39 (85%) (Queries using SQL features supported by UDP)
- Automatically proved all conditional query rewrites from literature. — 6 out of 6 (Rules requiring integrity constraints expressible in SQL)
- Formally verified a total of equivalent queries and rewrite rules. — 62 (Combined from literature and Calcite datasets)
- Failed to prove equivalence for specific known bugs. — 3 (Includes the 'count bug' and NULL semantics bugs)
- Setup
- Evaluation used 29 rules from literature and 232 test cases from Apache Calcite, with a trusted code base consisting of a Haskell parser and Lean converter/axioms.
- How
- The authors developed U-semiring, a formalism extending semiring semantics with unbounded summation and duplicate elimination. They implemented a decision procedure (UDP) in the Lean proof assistant that compiles SQL queries into U-expressions and checks their equivalence using a set of axioms.
- Limitations
- Does not support SQL features: CASE, UNION (set semantics), NULL, and PARTITION BY. · Cannot handle integer arithmetic, string casting, or string concatenation. · Performance timeout (30 minutes) for very long queries.
Summarized by Gemma 4 from the open-access full text · 1 Nov 2026. Read it