Skip to main content
QUICK REVIEW

[Paper Review] Axiomatic Foundations and Algorithms for Deciding Semantic Equivalences of SQL Queries

Shumo Chu, Murphy, Brendan|arXiv (Cornell University)|Feb 6, 2018
Advanced Database Systems and QueriesComputer Science39 references5 citations
TL;DR

This paper introduces U-semiring, a minimal axiomatic framework for modeling SQL query semantics that supports set, bag, and mixed semantics, including integrity constraints. It proposes the UDP algorithm to automatically verify semantic equivalence of SQL queries using a small set of axioms, successfully proving 62 real-world rewrite rules—many formally verified for the first time—demonstrating soundness and completeness for key query classes.

ABSTRACT

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 Coq 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 39 query rewrite rules from both classical data management research papers and real-world SQL engines, where many of them have never been proven correct before.

Motivation & Objective

  • To address the lack of formal verification tools for SQL query equivalence in modern database systems, especially in open-source engines like Calcite with unverified rewrite rules.
  • To overcome the limitations of prior systems like Cosette, which rely on complex type theories (e.g., HoTT) and cannot handle foreign keys or general integrity constraints.
  • To develop a lightweight, axiomatic foundation that supports both set and bag semantics, including mixed semantics with DISTINCT, and integrates integrity constraints such as keys and foreign keys.
  • To design an algorithm (UDP) that is sound for general SQL and complete for unions of conjunctive queries under set and bag semantics.
  • To enable automated, machine-checkable proofs of semantic equivalence using proof assistants like Coq, reducing the trusted code base and increasing reliability in query optimization.

Proposed method

  • Propose U-semiring as an extension of commutative semirings with unbounded summation and duplicate elimination, defined by only a few simple axioms.
  • Model SQL queries as U-expressions, transforming them into algebraic forms that can be reasoned about using equational reasoning.
  • Express integrity constraints (e.g., keys, foreign keys) as identities within the U-semiring framework, enabling their integration into equivalence proofs.
  • Design the UDP algorithm to decide equivalence by performing rewrites analogous to the chase procedure, but using U-expressions and testing for isomorphisms or homomorphisms.
  • Integrate the framework with proof assistants like Coq to generate machine-checkable proofs, ensuring correctness and minimizing trusted code base.
  • Support mixed semantics (set/bag) by modeling DISTINCT as a form of duplicate elimination within the U-semiring structure.

Experimental results

Research questions

  • RQ1Can a minimal axiomatic system be defined that captures the essential semantics of SQL queries under set, bag, and mixed semantics, including integrity constraints?
  • RQ2Is it possible to design an algorithm that automatically verifies semantic equivalence of SQL queries using only a small, trusted set of axioms?
  • RQ3How can integrity constraints such as foreign keys and primary keys be formally encoded and reasoned about within a unified query equivalence framework?
  • RQ4To what extent can the proposed framework handle real-world query rewrite rules from production database systems, especially those unverified in prior work?
  • RQ5Can the framework be extended to support complex SQL features like arithmetic, string operations, and type conversions, or are these fundamentally undecidable?

Key findings

  • The U-semiring framework successfully models a wide range of SQL features, including set and bag semantics, mixed semantics with DISTINCT, and integrity constraints such as keys and foreign keys.
  • The UDP algorithm is sound for general SQL queries and complete for Unions of Conjunctive Queries (UCQ) under both set and bag semantics.
  • The authors formally verified 62 real-world query rewrite rules from production systems, including 62 out of 68 rules from classical research and real-world engines, many of which had not been proven correct before.
  • The framework’s minimal axiom set—only a few identities—enables efficient integration with proof assistants like Coq, significantly reducing the trusted code base compared to prior systems like Cosette.
  • The approach successfully handles 68 out of 74 rewrite rules from the Calcite optimizer, with the remaining 6 failing due to unsupported features like integer arithmetic and string-to-date conversion, which are not fundamental barriers but require future extension.
  • The system demonstrates that formal verification of query equivalences is feasible and scalable for practical use in modern database engines, especially open-source systems lacking dedicated verification teams.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.