LLM-SQL-Solver: Can LLMs Determine SQL Equivalence?

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Zhao, Fuheng, Chen, Jiayue, Lim, Lawrence, Ahmad, Ishtiyaque, Agrawal, Divyakant, Abbadi, Amr El
Format: Preprint
Published: 2023
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916650461167616
author Zhao, Fuheng
Chen, Jiayue
Lim, Lawrence
Ahmad, Ishtiyaque
Agrawal, Divyakant
Abbadi, Amr El
author_facet Zhao, Fuheng
Chen, Jiayue
Lim, Lawrence
Ahmad, Ishtiyaque
Agrawal, Divyakant
Abbadi, Amr El
contents Judging the equivalence between two SQL queries is a fundamental problem with many practical applications in data management and SQL generation (i.e., evaluating the quality of generated SQL queries in text-to-SQL task). 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 solving 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 relaxed 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 relaxed equivalence in which it asks LLMs to explain the queries and then compare if they contain significant logical differences. Our experiments demonstrate using our techniques, LLMs is a promising tool to help data engineers in writing semantically equivalent SQL queries, however challenges still persist, and is a better metric for evaluating SQL generation than the popular execution accuracy.
format Preprint
id arxiv_https___arxiv_org_abs_2312_10321
institution arXiv
publishDate 2023
record_format arxiv
spellingShingle LLM-SQL-Solver: Can LLMs Determine SQL Equivalence?
Zhao, Fuheng
Chen, Jiayue
Lim, Lawrence
Ahmad, Ishtiyaque
Agrawal, Divyakant
Abbadi, Amr El
Databases
Computation and Language
Judging the equivalence between two SQL queries is a fundamental problem with many practical applications in data management and SQL generation (i.e., evaluating the quality of generated SQL queries in text-to-SQL task). 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 solving 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 relaxed 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 relaxed equivalence in which it asks LLMs to explain the queries and then compare if they contain significant logical differences. Our experiments demonstrate using our techniques, LLMs is a promising tool to help data engineers in writing semantically equivalent SQL queries, however challenges still persist, and is a better metric for evaluating SQL generation than the popular execution accuracy.
title LLM-SQL-Solver: Can LLMs Determine SQL Equivalence?
topic Databases
Computation and Language
url https://arxiv.org/abs/2312.10321