Manuscript Offprint

arXiv:2610.22442

Efficient Dialect-Agnostic SQL Equivalence Refutation

Junwen An, Manuel Rigger

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

JUNWEN AN, National University of Singapore, Singapore

MANUEL RIGGER, National University of Singapore, Singapore

Identifying semantically inequivalent SQL queries is useful for many applications, such as evaluating Text-to-SQL and dialect translation systems. However, existing approaches often struggle with the diversity of SQL features and dialects, requiring significant manual effort and expertise to extend query feature support across Database Management Systems (DBMSs). To address these limitations, we present SQLWitness, an efficient, DBMS-agnostic query equivalence refutation engine. Our core idea is leveraging the DBMS execution engine to determine whether generated instances constitute counterexamples, thereby faithfully capturing the semantics of the SQL dialect and preventing false counterexamples. To efficiently generate test data, our approach explores a constrained data-generation space and uses an integrity-constraint-aware generation strategy. Furthermore, to guide time-efficient termination of this test-data generation process, we pair predicate-coverage signals with a statistical estimator. We extensively evaluated SQLWitness on six benchmark suites across four SQL dialects. SQLWitness refuted 5.34% to 88.4% more pairs than state-of-the-art baselines, and processed query pairs in 0.12 seconds on average, achieving a speedup from 2.1×2.1\times to 16.4×16.4\times over the baselines. Furthermore, in a case study, SQLWitness found 8.4% inconsistent translations within a dialect translation benchmark. We believe SQLWitness could be broadly adopted for many use cases.

CCS Concepts: • Information systems → Query languages; • Software and its engineering → Software testing and debugging.

Additional Key Words and Phrases: SQL, Equivalence Refutation, Fuzz Testing

ACM Reference Format:

Junwen An and Manuel Rigger. 2026. Efficient Dialect-Agnostic SQL Equivalence Refutation. Proc. ACM Manag. Data 4, 6 (SIGMOD), Article 337 (December 2026), 27 pages. https://doi.org/10.1145/3856332

1 Introduction

Identifying when two SQL queries are semantically inequivalent is valuable in many settings. Unlike proving equivalence, which is undecidable in general [7, 8] and requires a formal model to verify that two queries produce identical results on all possible inputs, inequivalence requires only a single concrete counterexample, namely a database instance on which the two queries return different outputs (i.e., a witness). Finding inequivalence witnesses is useful for evaluating Text-to-SQL systems [22], grading SQL assignments [5], and debugging queries [26], where a counterexample exposes semantic differences between a ground-truth query and a candidate. In dialect translation [52], a counterexample between a source and translated query indicates an incorrect translation.

Table 1 summarizes representative existing works that identify semantically inequivalent queries, which can be generally classified into two categories based on their underlying approach. The first is verification-based, relying on formal verification by translating SQL queries into logical formulas and using automated solvers to prove query equivalence or construct counterexamples [10, 21, 39]. However, existing verification-based tools involve tradeoffs in supported features. VeriEQL [21]

Authors' Contact Information: Junwen An, National University of Singapore, Singapore, junwenan@u.nus.edu; Manuel Rigger, National University of Singapore, Singapore, rigger@nus.edu.sg.

Figure

This work is licensed under a Creative Commons Attribution 4.0 International License.

© 2026 Copyright held by the owner/author(s).

ACM 2836-6573/2026/12-ART337

https://doi.org/10.1145/3856332

337:2

Junwen An and Manuel Rigger

Table 1. Comparison of representative tools. IC: Integrity Constraints; Gen W: Concrete Witness Generation. (√ full support, ~ partial support, × no support).

ToolApproachDBMS-AgnosticIC.Gen W.Verify Eq.
SQLWitnessTest-case✓✓✓✕
ParSEVal [9]Test-case~~✓✕
VeriEQL [21]Verification✕✓✓~
QED [39]Verification✕~✕✓

supports witness generation and integrity constraints, but provides only bounded equivalence guarantees, verifying equivalence up to a fixed database size. QED [39] can fully prove equivalence, but lacks witness generation and foreign key constraint support, limiting its applicability. The second category is test-case-based, where, rather than reasoning over logical formulas, these approaches generate test cases from the query structure or semantics to cover a range of query behaviors, such as varying predicate evaluation outcomes, and use execution to detect whether a counterexample exists [4, 9, 47]. While this latter class cannot formally prove equivalence, it can effectively determine the existence of a witness to inequivalence.

Two main challenges in equivalence refutation are the diversity of SQL features and the efficiency of the tools. A DBMS typically contains many dialect-specific SQL features, such as functions and data types, which require developers of query refutation and reasoning tools to manually implement support for such features. Across different DBMS vendors, this problem is further compounded, as varying SQL dialects can introduce semantic differences such as inconsistent data type conversion behaviors [43] and incompatible dialect-specific features [48]. There has been a sustained effort to push the boundaries of supported features in existing tools. For example, ParSEval [9] applies symbolic analysis on query plans as a DBMS-agnostic intermediate representation while also supporting more features than previous tools, yet still fails on complex features such as string comparisons and window functions. More broadly, existing approaches, whether verification-based or test-case-based, typically operate on a fixed semantic model of queries and therefore might fail to distinguish semantic differences across DBMSs or require significant manual effort to support the semantics of each system. Beyond SQL feature support, efficiency remains a concern. Verification-based approaches in particular can struggle to scale, as reasoning over logical formulas becomes computationally expensive for complex queries, such as when multiple tables are joined [21]. Test-case-based approaches are generally more efficient, but when run until a timeout or until full branch coverage is achieved [9, 47], they can still consume significant time.

In this paper, we propose SQLWitness, a DBMS-agnostic and efficient query equivalence refutation engine that executes candidate queries against a DBMS, allowing each DBMS to interpret query semantics in its own dialect. SQLWitness provides no guarantee of finding a counterexample for every inequivalent query pair, but every counterexample it reports is genuine, meaning that the result difference can be observed when the two queries are executed on the target DBMS. To facilitate database generation, we leverage fuzzing [15], a biased randomized search technique, to efficiently explore query execution behaviors, eschewing explicitly modeling SQL features. We make three core technical contributions. First, SQLWitness constructs a minimal data-generation space containing a set of values designed to help explore query execution behaviors, which we term candidate pools. These include initial values based on three-valued logic (3VL) to explore structural behaviors (e.g., table joins), alongside literal values extracted from the queries to satisfy predicates. Second, SQLWitness uses an integrity-constraint-aware sampling strategy over candidate pools to generate valid database instances. Third, SQLWitness measures fuzzing progress by running

337:3

predicate coverage queries on the instances and employing a statistical estimator to terminate fuzzing once exploration saturates.

We extensively evaluated SQLWitness on six benchmark suites comprising 26,665 query pairs across four dialects. SQLWitness supported all query pairs and outperformed state-of-the-art approaches across all benchmarks, with 5.34% to 88.4% more refuted query pairs. Furthermore, SQLWitness proved highly efficient, as it processed a query pair in 0.12 seconds on average, achieving a 2.1×2.1\times to 16.4×16.4\times speedup over all existing baselines. Additionally, we conducted a case study using SQLWitness to evaluate the semantic equivalence of queries in dialect translation benchmarks. We found that 19.6% of the translated queries contained execution errors, and 8.4% failed to account for semantic differences.

We believe that SQLWitness can be broadly adopted for many use cases due to its DBMS-agnostic nature. For example, it can be used to evaluate dialect translation tools [52] and Text-to-SQL systems, where benchmarks are becoming increasingly diverse in their dialects [31]. Additionally, since it is highly efficient, users can pair SQLWitness with constraint-solver-based tools, running SQLWitness for fast refutation before invoking a more heavyweight solver without causing significant performance overhead. Our artifact is publicly available. 1^{1}

To summarize, we make the following contributions:

• We propose the novel idea of query-aware fuzzing to refute SQL query equivalence in a DBMS-agnostic manner.

  • We present SQLWitness, a query equivalence refutation engine that implements this idea through candidate pools, a constraint-aware data generation strategy, and a predicate coverage mechanism with a statistical termination estimator.

• We extensively evaluated SQLWitness on over 26,000 query pairs across six benchmarks and a real-world case study.

References (30)