LLM-SQL-Solver: Can LLMs Determine SQL Equivalence?
Authors:
- 8 December 2025
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 1887-1894
Abstract
Judging the equivalence between two SQL queries is a fundamental problem with many practical applications in data management and text-to-SQL generation. While the research community has reasoned about SQL equivalence for decades, it poses considerable difficulties and no complete solutions exist. Recently, Large Language Models (LLMs) have shown strong reasoning capability in conversation, question answering and mathematics challenges. In this paper, we study if LLMs can be used to determine the equivalence between SQL queries under two notions of SQL equivalence (semantic equivalence and pragmatic equivalence). To assist LLMs in generating high quality responses, we present two prompting techniques: Miniature & Mull and Explain & Compare. The former technique is used to evaluate the semantic equivalence in which it asks LLMs to execute a query on a simple database instance and then explore if a counterexample exists by modifying the database. The latter technique is used to evaluate the pragmatic equivalence in which it asks LLMs to explain the queries and then compare if they contain significant logical differences. Our experiments demonstrate that using our techniques, LLMs are promising tools to help data engineers in writing semantically equivalent SQL queries, however challenges still persist, and have better alignment with human preference on text-to-SQL generations than execution accuracy.Keywords
All Related Versions
This publication has 31 references indexed in Scilit:
- Is ChatGPT better than Human Annotators? Potential and Limitations of ChatGPT in Explaining Implicit Hate Speech2023
- Schema Matching using Pre-Trained Language Models2023
- A survey on deep learning approaches for text-to-SQLThe VLDB Journal, 2023
- WeTune: Automatic Discovery and Verification of Query Rewrite Rules2022
- Apache Calcite2018
- Elements of Finite Model Theory2004
- Rewriting aggregate queries using views1999
- Extensible/rule based query rewrite optimization in StarburstACM SIGMOD Record, 1992
- Equivalences Among Relational Expressions with the Union and Difference OperatorsJournal of the ACM, 1980
- Impossibility of an algorithm for the decision problem in finite classes1963