HoTTSQL: Proving Query Rewrites with Univalent SQL Semantics
Not on the map. Why?
Abstract (arXiv)
Every database system contains a query optimizer that performs query rewrites. Unfortunately, developing query optimizers remains a highly challenging task. Part of the challenges comes from the intricacies and rich features of query languages, which makes reasoning about rewrite rules difficult. In this paper, we propose a machine-checkable denotational semantics for SQL, the de facto language for relational database, for rigorously validating rewrite rules. Unlike previously proposed semantics that are either non-mechanized or only cover a small amount of SQL language features, our semantics covers all major features of SQL, including bags, correlated subqueries, aggregation, and indexes. Our mechanized semantics, called HoTTSQL, is based on K-Relations and homotopy type theory, where we denote relations as mathematical functions from tuples to univalent types. We have implemented HoTTSQL in Coq, which takes only fewer than 300 lines of code and have proved a wide range of SQL rewrite rules, including those from database research literature (e.g., magic set rewrites) and real-world query optimizers (e.g., subquery elimination). Several of these rewrite rules have never been previously proven correct. In addition, while query equivalence is generally undecidable, we have implemented an automated decision procedure using HoTTSQL for conjunctive queries: a well-studied decidable fragment of SQL that encompasses many real-world queries.
Key facts. Cited by 10 papers in the map (data through 7 Oct 2026). First posted on arXiv 17 Jul 2016.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2021: 3; 2022: 0; 2023: 0; 2024: 2; 2025: 3; 2026: 2.
10 papers.
- 2021Functional Collection Programming with Semi-Ring Dictionariescited by 6
- 2025QUITE: A Query Rewrite System Beyond Rules with LLM Agentscited by 6
- 2025SpotIt: Evaluating Text-to-SQL Evaluation with Formal Verificationcited by 3
- 2024Can the Rookies Cut the Tough Cookie? Exploring the Use of LLMs for SQL Equivalence Checkingcited by 2
- 2024GEqO: ML-Accelerated Semantic Equivalence Detectioncited by 1
- 2026SpotIt+: Verification-based Text-to-SQL Evaluation with Database Constraintscited by 1
- 2026EXPO-SQL: Execution-based Clause-level Policy Optimization for Text-to-SQLcited by 1
- 2021Semantic Parsing Natural Language into Relational Algebracited by 0
- 2021Fine-Tuning Data Structures for Analytical Query Processingcited by 0
- 2025Polygon: Symbolic Reasoning for SQL using Conflict-Driven Under-Approximation Searchcited by 0
- 2026EXPO-SQL: Execution-based Clause-level Policy Optimization for Text-to-SQL29 Apr 2026
- 2026SpotIt+: Verification-based Text-to-SQL Evaluation with Database Constraints4 Mar 2026
- 2025SpotIt: Evaluating Text-to-SQL Evaluation with Formal Verification30 Oct 2025
- 2025QUITE: A Query Rewrite System Beyond Rules with LLM Agents9 Jun 2025
- 2025Polygon: Symbolic Reasoning for SQL using Conflict-Driven Under-Approximation Search9 Apr 2025
- 2024Can the Rookies Cut the Tough Cookie? Exploring the Use of LLMs for SQL Equivalence Checking7 Dec 2024
- 2024GEqO: ML-Accelerated Semantic Equivalence Detection2 Jan 2024
- 2021Fine-Tuning Data Structures for Analytical Query Processing24 Dec 2021
- 2021Semantic Parsing Natural Language into Relational Algebra25 Jun 2021
- 2021Functional Collection Programming with Semi-Ring Dictionaries10 Mar 2021