# Verifying SQL Queries using Theories of Tables and Relations

arXiv: https://arxiv.org/abs/2405.03057 · HTML: https://mlsanity.com/paper/2405.03057/

## Key facts

- Cited by 2 papers in the map (data through 14 Oct 2026).
- First posted on arXiv 5 May 2024.

## Built on by (most cited first, 2 of 2)

- [SpotIt: Evaluating Text-to-SQL Evaluation with Formal Verification](https://mlsanity.com/paper/2510.26840/) (2025)
- [NOETHER: A Constructive Framework for Metamorphic Pattern Discovery from Operator Algebras](https://mlsanity.com/paper/2605.17390/) (2026)

## Abstract (arXiv)

We present a number of first- and second-order extensions to SMT theories specifically aimed at representing and analyzing SQL queries with join, projection, and selection operations. We support reasoning about SQL queries with either bag or set semantics for database tables. We provide the former via an extension of a theory of finite bags and the latter via an extension of the theory of finite relations. Furthermore, we add the ability to reason about tables with null values by introducing a theory of nullable sorts based on an extension of the theory of algebraic datatypes. We implemented solvers for these theories in the SMT solver cvc5 and evaluated them on a set of benchmarks derived from public sets of SQL equivalence problems.
