Conceptio › Archive › arXiv CS
arXiv CS open access

Bound to be Complete: Efficient Verification for SQL Equivalence via U-Expressions

Haoran Ding et al. · arxiv_cs
arXiv CS · Papers
Open Source ↗Direct PDF ↓
data-managementdatabasessqlstorage
Automated verification of SQL query equivalence is a fundamental problem in database area. Recent works developed verifiers with guaranteed completeness, which can generate counterexamples to disprove non-equivalent queries and are useful in various scenarios. However, they have to solve complex for
Conceptio Open Archive

Analyze & explore related research in Conceptio

Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.

Bound to be Complete: Efficient Verification for SQL Equivalence via U-Expressions Haoran Ding1,2,∗ , Zhaoguo Wang1,† , Zuming Jiang3 , Haibo Chen1 , Jinyang Li4 , Ruzica Piskac5 1 Institute of Parallel and Distributed Systems, Shanghai Jiao Tong University 3 The University of Hong Kong

4 New York University

arXiv:2611.28516v1 [cs.DB] 21 Nov 2026

ABSTRACT Automated verification of SQL query equivalence is a fundamental problem in database research. Recent works developed verifiers with guaranteed completeness, which can generate counterexamples to disprove non-equivalent queries and are useful in various scenarios. However, they have to solve complex formulas and can fail to produce counterexamples within a reasonable time budget. This paper presents a new complete verifier called SQLution, which not only greatly reduces the verification time, but also supports more SQL features. The key insight is to represent SQL semantics using U-expressions, a functional algebra that can model SQL with significantly simpler formulas than prior works, thereby leading to more efficient SMT solving. To turn this insight into a practical verifier, SQLution further tackles two technical challenges associated with modeling SQL using U-expressions, namely, the lack of tuple ordering and the presence of unbounded summations. In particular, to support tuple ordering, SQLution proposes order semantics encoding which combines U-expressions with firstorder logic (FOL). To handle unbounded summations, SQLution introduces unbounded summation expansion to transform them into bounded summations, which can be directly encoded into FOL formulas. Compared with state-of-the-art verifiers, SQLution supports all 271 non-equivalent query pairs derived from Spider and reduces verification time by up to 98.6%.

1

INTRODUCTION

Automated verification of SQL query equivalence is one of the fundamental problems in database theory [4]. Two queries are considered equivalent if they yield identical results for all possible database instances. Developing a verifier for such equivalence is crucial across a wide range of scenarios. For example, such verifiers can help automatically discover rewrite rules [7, 22, 33, 42, 55], which transform a given query into another equivalent but faster query. Verifiers can also help detect database bugs [30, 44]. Some bugs cause query optimizers to rewrite queries into non-equivalent ones [30]. However, the SQL equivalence problem is undecidable [17, 20], so no verifier can ensure both soundness and completeness. Recently, there has been a rising interest in building complete verifiers [21, 30, 60] that automatically search for such counterexamples. This is useful in several important scenarios, such as database bug detection [30], example-based query synthesis [5, 13, 14, 28, 51, 52, 59], query disambiguation [57], and SQL grading [18, 19]. In contrast, sound verifiers [20, 21, 27, 54, 55, 61, 62] usually cannot * This research was completed when Haoran Ding was a PhD student in Shanghai Jiao

Tong University. He is currently a postdoctoral associate of MIT. † Corresponding author.

2 MIT CSAIL

5 Yale University

provide counterexamples because they are inherently incomplete and may falsely treat equivalent queries as non-equivalent. State-of-the-art complete verifiers [30, 60] model SQL tables as lists and propose list-based bounded symbolic reasoning. In particular, the verifier sets a bound 𝑏 on table size, which allows it to represent each input table using a list of 𝑏 symbolic tuples. By symbolically evaluating a SQL query on these symbolic lists, the verifier can systematically encode the query into a first-order logic (FOL) formula, thus enabling the use of an SMT solver [8, 9, 26] to produce concrete assignments to symbolic tuples as a counterexample that demonstrates non-equivalence. Despite its promise, the existing approach for complete verification is inefficient: the list-based encoding yields complex formulas, resulting in a long running-time for SMT solvers. For example, for a pair of queries with a total of 29 AST nodes from the Spider benchmark, the resulting formula has 2,916 AST nodes even if the table size bound is only 1. When the bound increases to 3, the number of AST nodes in the formula increases to 18,001. The inefficiency is due to two fundamental causes. First, symbolic execution leads to complex encoding. In addition to modeling the input tables and final query result, existing verifiers also generate a symbolic list for the intermediate result of each SQL operator, which significantly increases the number of symbolic variables. Moreover, for each tuple in the query result, the verifier generates a separate formula describing how that tuple is derived from the inputs. The overall encoding is then expressed as the conjunction of all such formulas, resulting in expressions with numerous logical and arithmetic operators. Second, aligning list semantics with SQL’s bag semantics also results in complex encoding. Under SQL’s bag semantics, tuples in a table do not have a fixed order, and duplicates are allowed. Consequently, when comparing query results under bag semantics, existing verifiers need to consider all possible permutations of tuples in the lists, producing large and complex formulas that challenge SMT solvers. To overcome these limitations, our key insight is to encode query equivalence in a lightweight way, which is based on an algebra called U-expression [20]. Based on the key insight, we develop a new complete verifier called SQLution. The existing sound verifier SQLSolver [27] demonstrates that U-expressions can model a broad range of SQL features, including features unsupported by prior works [30, 60]. A U-expression formulates a SQL query as a function 𝑓 (𝑡), which returns the multiplicity of any tuple 𝑡 in the query result. This formulation compactly captures query semantics and enables equivalence reasoning using significantly fewer variables and simpler formulas. Because the multiplicity of any tuple can be computed directly, SQLution avoids generating separate formulas for each output tuple. Moreover, query equivalence can be expressed

in a particularly elegant form: two queries are equivalent if and only if their corresponding U-expressions yield the same integer value for any input tuple. Formally, for U-expressions 𝑓1 (𝑡) and 𝑓2 (𝑡), equivalence checking reduces to proving the unsatisfiability of the formula ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡). Unlike comparing two symbolic lists, comparing two integer values is an encoding that is far simpler and more efficient to solve. Although SQLSolver [27] already uses U-expressions for sound verification, its algorithm to check the equivalence of U-expressions is inherently incomplete and cannot generate counterexamples for non-equivalent queries. It is non-trivial to extend SQLSolver to a complete verifier because query equivalence verification is undecidable. Realizing a complete automated verifier based on Uexpressions therefore requires solving two challenges that cannot be handled by SQLSolver: reasoning about ordered bag semantics and encoding unbounded summations in U-expressions. The first arises from the semantics of U-expression itself: by definition, U-expression captures only bag semantics and therefore cannot directly model queries with ordered bag semantics. Those queries contain clauses such as ORDER BY, LIMIT, or OFFSET [45], for which the order among tuples in query results is significant. Because U-expressions reason about the multiplicity of individual tuples rather than their relative order, they provide no native mechanism for expressing ordering among tuples. SQLSolver supports ORDER BY through a syntax-matching algorithm, which cannot ensure completeness. Specifically, it requires that: 1) The two queries contain the same number of ORDER BY clauses. 2) Each ORDER BY clause in one query matches another ORDER BY clause in the other query in terms of ordering directions and attributes. 3) The subqueries of each pair of matched ORDER BY clauses are equivalent. This procedure is incomplete because semantically equivalent queries need not have matching syntactic structures. Failure to find such a match therefore does not establish non-equivalence or yield a counterexample. Because SQLution must reason completely about ordered semantics, it cannot reuse this syntax-matching algorithm. To overcome this challenge, we introduce an order semantics encoding technique for handling ORDER BY, LIMIT, and OFFSET, which reasons about query equivalence by encoding the semantics rather than syntactic comparison, thereby ensuring completeness. Specifically, it systematically rewrites SQL queries to eliminate LIMIT and OFFSET while preserving query semantics. ORDER BY cannot be removed in general, because ordered bag semantics cannot be reduced to pure bag semantics. Fortunately, we observe that while U-expressions can represent the multiplicity of only a single tuple in the query result, we can combine them with firstorder logic formulas that explicitly encode the ordering relations between tuples. Thus, we encode the existence of tuples 𝑡 1 and 𝑡 2 in the query result with two U-expressions. Then, we encode that 𝑡 1 precedes 𝑡 2 in one query result but the ordering is opposite in another query result based on first-order logic. If the above constraint is satisfiable, queries are non-equivalent, and we will use SMT solvers to produce a counterexample. For brevity, ordered bag semantics will be abbreviated as order semantics if the context is clear. The second challenge is that there is no decision procedure to reason about U-expressions while ensuring completeness. The main P difficulty stems from unbounded summations ( ) in U-expressions,

which are hard to be directly encoded in first-order logic. In an P unbounded summation 𝑡 𝑒(𝑡), the variable 𝑡 ranges over all possible tuples rather than a statically bounded set, which means the summation domain is unbounded. Such summations are necessary to model SQL constructs such as PROJECTION and aggregate functions. However, a FOL formula cannot directly express the sum of unbounded expressions. SQLSolver proposes an approximationbased method to encode U-expressions with unbounded summations, which cannot ensure completeness. Specifically, the encoding result is an over-approximation formula such that if the formula is unsatisfiable, the original U-expressions are treated as equivalent. However, if the formula is satisfiable, the original U-expressions may be either equivalent or non-equivalent. Thus, SQLSolver’s method cannot determine whether two queries are non-equivalent and cannot produce a counterexample. To ensure completeness, SQLution cannot reuse SQLSolver’s encoding algorithm. To address unbounded summations with a completeness guarantee, we introduce a new verification algorithm for U-expressions that extends the classical bounded verification idea [10, 32, 34– 37, 46]. By assuming that each table contains a bounded number of distinct tuples, we observe that every unbounded summation becomes equivalent to a bounded one, which can be directly encoded into FOL formulas. Intuitively, we find that only a finite set of tuples can yield non-zero 𝑒(𝑡). So enumerating all possible tuples in the unbounded summation domain is not really necessary. Based on the observation, we propose unbounded summation expansion to precisely construct a bounded domain for each unbounded summation, which covers each tuple 𝑡 that can make 𝑒(𝑡) non-zero. Then, an unbounded summation can be expanded into an equivalent bounded summation. We evaluated SQLution on 997 SQL query pairs derived from Spider [58], a widely used benchmark for LLM-based query synthesis [40, 41, 48]. SQLution successfully handles all test cases, including 271 non-equivalent pairs. In contrast, the state-of-the-art complete verifier Polygon supports only 716 cases, of which 162 are non-equivalent. For non-equivalent queries disproved by both verifiers, SQLution achieves substantial performance gains: it reduces verification time by over 50% in 92.9% of cases and by over 80% in 43.6% of cases, with a maximum time reduction of 98.6% (from 802 ms to 11 ms).

2 BACKGROUND AND MOTIVATION 2.1 Sound verifiers vs. Complete verifiers The SQL query equivalence problem is undecidable [17, 20], which means it is impossible for a verifier to ensure both soundness and completeness. A sound verifier, such as SQLSolver, guarantees that every query pair it proves equivalent is indeed equivalent over all database instances. However, some queries may fail to pass the verification even if they are equivalent due to the inherent incompleteness of sound verifiers. Thus, sound verifiers generally cannot produce a counterexample when they fail to prove equivalence. In contrast to sound verifiers, this paper targets complete verifiers, which guarantee that queries that fail verification are indeed non-equivalent. Complete verifiers produce a counterexample to demonstrate non-equivalence, i.e., a set of concrete database tables

create table hotel ( id int , star int , price int ) ; 𝑄 1 : ( select * from hotel where star < 4) union all ( select * from hotel where price < 500) 𝑄 2 : select * from hotel where star < 4

Figure 1: An example of two non-equivalent SQL queries.

on which the two queries yield different results. Due to undecidability, complete verifiers and sound verifiers usually adopt rather different algorithms. It is intractable to extend a sound verifier, such as SQLSolver, to a complete one. To generate a counterexample to demonstrate the non-equivalence, complete verifiers typically use a bounded verification approach. Given a bound 𝑏, a complete verifier searches for input tables such that each table size is within the bound and two queries produce different results. If such a counterexample exists, the verifier demonstrates that the queries are non-equivalent. Otherwise, the verifier concludes that the queries are equivalent when each table size is within the bound. Increasing the bound 𝑏 allows the verifier to consider larger tables.

2.2

Application of SQL Equivalence Verifiers

SQL equivalence verifiers are useful in various scenarios. For example, sound verifiers can help automatically discover new rewrite rules [33, 55]. Query optimizers typically apply rewrite rules to transform a query into another equivalent but faster one. Existing works [33, 55] discover new rules automatically by first enumerating possible rewrite rules and using verifiers to identify ones that can ensure query equivalence before and after rewriting. Complete verifiers are also useful in multiple scenarios. First, they can help detect and understand bugs in database optimizers [30, 44, 60]. Although queries are equivalent by construction, the implementation of optimizers may have bugs [1–3]. Prior works [30] have found such bugs in Apache Calcite and MySQL. The counterexamples generated by complete verifiers can help developers understand and locate the bugs. Second, the counterexamples generated by complete verifiers can be used to guide LLMs in rewriting SQL queries. For example, GenRewrite [43] proposes a counterexample-guided approach that leverages an LLM to rewrite a given SQL query into an equivalent but faster query. When the rewritten query is not equivalent to the original one, GenRewrite uses counterexamples to guide LLMs in correcting the rewrite. Third, complete verifiers can help assess LLMs’ capabilities in text-to-SQL tasks. Text-to-SQL tasks require an LLM to translate natural-language questions into SQL queries. Popular text-to-SQL benchmarks (e.g., Spider) can use complete verifiers to check whether generated SQL queries are equivalent to the reference SQL queries. Effectively applying complete verifiers in these scenarios is outside the scope of this paper and remains an interesting topic for future work.

2.3

List-based Verification for SQL Equivalence

We illustrate how a list-based complete SQL equivalence verifier operates on the example in Figure 1. In this example, the first query uses UNION ALL to concatenate the hotels whose star rating is below 4 with those whose price is below 500, duplicating tuples

that satisfy both conditions. The second query returns only hotels whose star rating is below 4. Thus, the two queries are not equivalent. We begin with a bound of 1. The list-based approach proceeds as follows. The verifier first constructs symbolic lists to represent the input tables and query outputs. Under a bound of 1, the symbolic list for the table hotel contains at most one symbolic tuple: 𝑙 0 := [(𝑑𝑒𝑙 0, 𝑖𝑑 0, 𝑠𝑡𝑎𝑟 0, 𝑝𝑟𝑖𝑐𝑒 0 )]. Here, the boolean variable 𝑑𝑒𝑙 0 indicates tuple deletion (i.e., the tuple does not exist if and only if 𝑑𝑒𝑙 0 is true), while the integer variables 𝑖𝑑 0 , 𝑠𝑡𝑎𝑟 0 , and 𝑝𝑟𝑖𝑐𝑒 0 correspond to the tuple attributes. Given this bound, the result of 𝑄 1 contains at most two tuples, and that of 𝑄 2 at most one. Accordingly, the symbolic lists for the query results are defined as 𝑙 1 := [(𝑑𝑒𝑙 1, 𝑖𝑑 1, 𝑠𝑡𝑎𝑟 1, 𝑝𝑟𝑖𝑐𝑒 1 ), (𝑑𝑒𝑙 2, 𝑖𝑑 2, 𝑠𝑡𝑎𝑟 2, 𝑝𝑟𝑖𝑐𝑒 2 )] for 𝑄 1 , and 𝑙 2 := [(𝑑𝑒𝑙 3, 𝑖𝑑 3, 𝑠𝑡𝑎𝑟 3, 𝑝𝑟𝑖𝑐𝑒 3 )] for 𝑄 2 , where 𝑑𝑒𝑙 1 , 𝑑𝑒𝑙 2 , and 𝑑𝑒𝑙 3 denote the existence of the corresponding tuples. Next, the semantics of 𝑄 1 is encoded as 𝐹 1 . 𝐹 1 := (𝑑𝑒𝑙 1 ↔ (𝑑𝑒𝑙 0 ∨ ¬(𝑠𝑡𝑎𝑟 0 < 4))) ∧ (𝑖𝑑 1 = 𝑖𝑑 0 ) ∧ (𝑠𝑡𝑎𝑟 1 = 𝑠𝑡𝑎𝑟 0 ) ∧ (𝑝𝑟𝑖𝑐𝑒 1 = 𝑝𝑟𝑖𝑐𝑒 0 ) ∧ (𝑑𝑒𝑙 2 ↔ (𝑑𝑒𝑙 0 ∨ ¬(𝑝𝑟𝑖𝑐𝑒 0 < 500))) ∧ (𝑖𝑑 2 = 𝑖𝑑 0 ) ∧ (𝑠𝑡𝑎𝑟 2 = 𝑠𝑡𝑎𝑟 0 ) ∧ (𝑝𝑟𝑖𝑐𝑒 2 = 𝑝𝑟𝑖𝑐𝑒 0 ) The resulting formula is a conjunction of two components. The first component encodes the semantics of the first sub-query: when the tuple in table hotel exists and satisfies the predicate 𝑠𝑡𝑎𝑟 < 4, the corresponding output tuple in 𝑄 1 must exist, and it is the output of the first sub-query. The second line encodes the semantics of the second sub-query in the same manner. Similarly, the semantics of 𝑄 2 is encoded as 𝐹 2 . 𝐹 2 := (𝑑𝑒𝑙 3 ↔ (𝑑𝑒𝑙 0 ∨ ¬(𝑠𝑡𝑎𝑟 0 < 4))) ∧ (𝑖𝑑 3 = 𝑖𝑑 0 ) ∧ (𝑠𝑡𝑎𝑟 3 = 𝑠𝑡𝑎𝑟 0 ) ∧ (𝑝𝑟𝑖𝑐𝑒 3 = 𝑝𝑟𝑖𝑐𝑒 0 ) Finally, the equality of two lists 𝑙 1 and 𝑙 2 is encoded as 𝐹 3 : ∑︁ ∑︁ 𝐹 3 := ( 𝑖𝑛𝑡(𝑡𝑖 .𝑑𝑒𝑙) = 𝑖𝑛𝑡(𝑡 𝑗 .𝑑𝑒𝑙)) 𝑡𝑖 ∈𝑙 1

∧

𝑡 𝑗 ∈𝑙 2

^  ∑︁

𝑖𝑛𝑡((𝑡𝑖 = 𝑡) ∧ ¬𝑡𝑖 .𝑑𝑒𝑙 ∧ ¬𝑡 .𝑑𝑒𝑙)

𝑡 ∈𝑙 1 𝑡𝑖 ∈𝑙 1

=

∑︁

𝑖𝑛𝑡((𝑡 𝑗 = 𝑡) ∧ ¬𝑡 𝑗 .𝑑𝑒𝑙 ∧ ¬𝑡 .𝑑𝑒𝑙)



𝑡 𝑗 ∈𝑙 2

For simplicity, we use 𝑖𝑛𝑡(𝑝) to represent 𝑖𝑡𝑒(𝑝, 1, 0). If the formula 𝑝 is true, then 𝑖𝑛𝑡(𝑝) returns 1. Otherwise, it returns 0. The term 𝑡 .𝑎 represents the symbolic attribute of the symbolic tuple 𝑡. 𝐹 3 consists P P of two parts. The first part 𝑡𝑖 ∈𝑙1 𝑖𝑛𝑡(𝑡𝑖 .𝑑𝑒𝑙) = 𝑡 𝑗 ∈𝑙2 𝑖𝑛𝑡(𝑡 𝑗 .𝑑𝑒𝑙) represents that the query results of 𝑄 1 and 𝑄 2 should have the same number of tuples. The second part means that for each tuple 𝑡 in the list 𝑙 1 , its multiplicity in the query result of 𝑄 1 and 𝑄 2 should be the same. The multiplicity of 𝑡 in the result of 𝑄 1 is calculated P by 𝑡𝑖 ∈𝑙1 𝑖𝑛𝑡((𝑡𝑖 = 𝑡) ∧ ¬𝑡𝑖 .𝑑𝑒𝑙 ∧ ¬𝑡 .𝑑𝑒𝑙). The multiplicity of 𝑡 in the result of 𝑄 2 is expressed similarly. In the final step, the list-based verifier invokes an SMT solver to check the satisfiability of 𝐹 1 ∧ 𝐹 2 ∧ ¬𝐹 3 . If the formula is satisfiable, the two queries are not equivalent, and the resulting model serves as a counterexample. Even for this simple example, with a bound of 1 and only four SQL operations, the generated formula contains 179 AST nodes, including 78 variables and 101 operators. In realistic

scenarios, both the queries and the corresponding formulas grow substantially in complexity.

3

OVERVIEW OF SQLUTION

We develop a new complete verifier, SQLution, that overcomes the limitations of existing list-based approaches. Unlike prior methods, SQLution employs a novel encoding based on U-expressions [20], which results in significantly simpler formulas. Because no complete verification algorithm previously existed for U-expressions, SQLution introduces a new decision procedure for reasoning about the generated formulas. Beyond improved verification efficiency, SQLution also supports a broader range of SQL features than existing verifiers. U-expressions. Introduced by Chu et al. [20], a U-expression is an algebraic representation of a query as a function 𝑓 (𝑡) mapping each tuple 𝑡 to its multiplicity in the query result. U-expressions capture a wide range of SQL features, including aggregate functions, OUTER JOIN, and UNION [20, 27, 54]. They also support features beyond previous approaches, such as INTERSECT and EXCEPT. The main terms/operators of U-expressions are summarized in Table 1. Each term returns a non-negative integer value and is connected by “×” or “+” in the U-expression. Specifically, for each relation name 𝑅, there is a pre-defined function ⟦𝑅⟧(𝑡) that returns the multiplicity of tuple 𝑡 in the relation 𝑅. For each predicate 𝑏, the U-expression [𝑏] is either 1 (𝑏 is true) or 0 (𝑏 is false). For brevity, we omit ⟦⟧ in U-expressions if there is no ambiguity. To illustrate U-expressions, we encode several core SQL features following the algorithm in SQLSolver [27]. • SELECTION: 𝑆𝑒𝑙𝑝 (𝑄) denotes a selection over the sub-query 𝑄 with predicate 𝑝. Assume the U-expression of 𝑄 is 𝑓𝑙 . The U-expression for the selection is 𝑓 (𝑡) := 𝑓𝑙 (𝑡) × [𝑝(𝑡)]. This preserves the multiplicity of 𝑡 if it satisfies 𝑝, and sets it to 0 otherwise. • PROJECTION: 𝑃𝑟𝑜 𝑗𝑎 (𝑄) denotes returning the attributes 𝑎 from the result of the sub-query 𝑄. Assume the U-expression of 𝑄 is 𝑓𝑙 . The U-expression is ∑︁ 𝑓 (𝑡) := 𝑓𝑙 (𝑡𝑙 ) × [𝑡 = 𝑡𝑙 .𝑎]. 𝑡𝑙

P The unbounded summation 𝑡𝑙 aggregates multiplicities of all tuples 𝑡𝑙 whose projected attributes 𝑎 match 𝑡. • UNION ALL: 𝑈 𝑛𝑖𝑜𝑛𝐴𝑙𝑙(𝑄𝑙 , 𝑄𝑟 ) denotes the union of the sub-queries 𝑄𝑙 and 𝑄𝑟 . Assume the U-expressions of 𝑄𝑙 and 𝑄𝑟 are 𝑓𝑙 and 𝑓𝑟 , respectively. The U-expression for the union is 𝑓 (𝑡) := 𝑓𝑙 (𝑡) + 𝑓𝑟 (𝑡), summing the multiplicities of 𝑡 from both sub-queries. Basic idea of SQLution. Our complete SQL equivalence verifier, SQLution, is based on U-expressions. Given two queries 𝑄 1 and 𝑄 2 , SQLution first translates them into U-expressions 𝑓1 (𝑡) and 𝑓2 (𝑡), respectively. It then encodes the formula ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) into firstorder logic, which can be automatically checked by an SMT solver. If the formula is satisfiable, there exists a tuple whose multiplicities differ between the two query results; the SMT solver returns a model that can be used to construct a counterexample database.

Motivating Example. We now show how SQLution disproves the queries in Figure 1 and compare the resulting formula with that of existing works. First, the U-expressions for the queries 𝑄 1 and 𝑄 2 are 𝑓1 (𝑡) and 𝑓2 (𝑡), respectively. 𝑓1 (𝑡) := (ℎ𝑜𝑡𝑒𝑙(𝑡) × [𝑡 .𝑠𝑡𝑎𝑟 < 4]) + (ℎ𝑜𝑡𝑒𝑙(𝑡) × [𝑡 .𝑝𝑟𝑖𝑐𝑒 < 500]) 𝑓2 (𝑡) := (ℎ𝑜𝑡𝑒𝑙(𝑡) × [𝑡 .𝑠𝑡𝑎𝑟 < 4]) Specifically, 𝑓1 (𝑡) is the addition of two sub-expressions, which represents the multiplicity of 𝑡 in each sub-query. Then, SQLution converts ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) to a FOL formula. According to the schema of the hotel table, 𝑡 is a tuple with three integer variables (𝑖𝑑 1, 𝑠𝑡𝑎𝑟 1, 𝑝𝑟𝑖𝑐𝑒 1 ). The resulting FOL formula is  (ℎ𝑜𝑡𝑒𝑙(𝑖𝑑 1, 𝑠𝑡𝑎𝑟 1, 𝑝𝑟𝑖𝑐𝑒 1 ) × 𝑖𝑛𝑡(𝑠𝑡𝑎𝑟 1 < 4))+  (ℎ𝑜𝑡𝑒𝑙(𝑖𝑑 1, 𝑠𝑡𝑎𝑟 1, 𝑝𝑟𝑖𝑐𝑒 1 ) × 𝑖𝑛𝑡(𝑝𝑟𝑖𝑐𝑒 1 < 500)) ̸=(ℎ𝑜𝑡𝑒𝑙(𝑖𝑑 1, 𝑠𝑡𝑎𝑟 1, 𝑝𝑟𝑖𝑐𝑒 1 ) × 𝑖𝑛𝑡(𝑠𝑡𝑎𝑟 1 < 4)) Finally, an SMT solver checks the formula and reports that the queries are not equivalent. In this example, SQLution generates a formula with only 26 AST nodes, consisting of 15 variables and 11 operators, which is substantially smaller than the 179-node formula produced by a list-based verifier. Our evaluation of test cases derived from Spider shows that SQLution achieves a median verification time reduction of 83.1% compared to Polygon. Challenges. Directly applying U-expressions to construct a complete verifier is a non-trivial task. First, U-expressions alone cannot capture queries with ordered bag semantics. Second, encoding the unbounded summations in U-expressions into first-order logic is challenging, since FOL operators cannot express sums over unbounded terms. We address these issues with an ordered-bag encoding (Section 4) and a complete procedure for unbounded summations (Section 5).

4

ORDER SEMANTICS ENCODING

We propose order semantics encoding to fill the semantics gap between U-expressions and SQL queries that sort tuples. The order semantics of SQL queries can be involved by LIMIT, OFFSET, and ORDER BY clauses. To handle order semantics, our approach consists of two parts: (1) SQL query preprocessing, which eliminates all LIMIT and OFFSET clauses; and (2) query equivalence encoding, which handles the order semantics involved by ORDER BY. The proof for the correctness of handling LIMIT/OFFSET/ORDER BY can be found in Section 2 of supplementary material [6].

4.1

SQL Query Preprocessing

The method of eliminating LIMIT and OFFSET clauses is to transform a SQL query with these clauses into another new query without these clauses, while preserving the query semantics. LIMIT and OFFSET clauses select tuples whose rankings are within the specific range. Without loss of generality, assume the tuples are sorted based on their values of attribute 𝑎 in descending order. Our key insight is that the ranking of each tuple can be calculated by aggregating the multiplicity of other tuples that have a larger attribute 𝑎. The calculation can be naturally implemented by the aggregate

Term/Operator ⟦R⟧(𝑡) [b]

P

𝑡 𝑒(𝑡)

Table 1: The terms/operators of U-expressions. Example Query Concept ⟦R⟧(𝑡) is a function that returns the multiplicity of the tuple 𝑡 select ∗ from R in the relation 𝑅. [b] returns 1 if the predicate 𝑏 is select ∗ from R true. Otherwise, it returns 0. where R.x < 500 P 𝑒(𝑡) returns the sum of 𝑒(𝑡 ) for 𝑖 𝑡 each possible tuple 𝑡𝑖 , where 𝑒 is a U-expression in the type of tuple → N. select R.x from R Since there may be unbounded 𝑡𝑖 , P 𝑡 𝑒(𝑡) is called an unbounded summation.

-- Rule 1 𝑄 1 : R order by R . attr desc limit m offset n 𝑄 2 : select R1 .* from ( select R1 .* , sum ( case when R1 . attr < R2 . attr then 1 else 0 end ) as s from R as R1 full join R as R2 group by R1 . attr having s < m + n and s >= n ) order by R1 . attr desc -- Rule 2 𝑄 3 : R order by R . attr asc limit m offset n 𝑄 4 : select R1 .* from ( select R1 .* , sum ( case when R1 . attr > R2 . attr then 1 else 0 end ) as s from R as R1 full join R as R2 group by R1 . attr having s < m + n and s >= n ) order by R1 . attr asc

Figure 2: The preprocessing rules that remove LIMIT and OFFSET in the given SQL query. Each rule transforms the first SQL query into the second SQL query; the two queries are equivalent.

function “sum”. Thus, we can produce the result of LIMIT and OFFSET clauses with aggregate functions. Although we can completely remove LIMIT and OFFSET clauses, it is noteworthy that we cannot completely remove ORDER BY clauses in general. Otherwise, the query after transformation will have only bag semantics, which will be non-equivalent to the original query with order semantics. Figure 2 illustrates two preprocessing rules designed to remove all LIMIT and OFFSET clauses from a query generally. The first rule is designed to handle descending order, while the second rule is for ascending order. For the first rule, the original query 𝑄 1 first sorts the tuples in the result of 𝑅 by attribute attr in descending order, then skips the first 𝑛 tuples and returns the next 𝑚 tuples. Note that 𝑅 can be a sub-query or a table. The SQL query 𝑄 2 achieves the same result by using a self-join and the aggregate function “sum”. Specifically, for each tuple in 𝑅, the aggregate function “sum” counts how many tuples in 𝑅 have larger values in attribute attr. Based on this count, it filters out tuples to retain only those that would appear between positions 𝑛 + 1 and 𝑚 + 𝑛 in the sorted sequence. Then, the result is sorted by the attribute attr. Note

Example U-expression 𝑓 (𝑡) ⟦R⟧(𝑡) ⟦R⟧(𝑡) × [𝑡 .𝑥 < 500]

𝑡 1 ([𝑡 = 𝑡 1 .𝑥] × ⟦R⟧(𝑡 1 ))

P

that the rule works when the attribute attr is unique. Otherwise, 𝑄 1 is ambiguous because the order of tuples with the same value in attr is not defined. SQLution does not consider ambiguous queries because their semantics are nondeterministic and difficult to formulate precisely. The second rule for ascending order is symmetric, which counts tuples with smaller rather than larger values. NULL ordering can be captured similarly. After removing all LIMIT and OFFSET, SQLution further removes ORDER BY in some subqueries (e.g., FROM subquery). It does not change the query result, because SQL ignores such ORDER BY according to SQL standard and mainstream database manuals [50, 55]. In other cases, SQLution promotes ORDER BY from sub-queries to the outermost level, which does not change the query semantics either. Finally, each query will have at most one ORDER BY clause at the outermost level.

4.2

Query Equivalence Encoding

Given two preprocessed SQL queries 𝑄 1 and 𝑄 2 , SQLution further encodes their equivalence. Specifically, SQLution checks whether 𝑄 1 and 𝑄 2 have ORDER BY at the outermost level. SQLution uses different methods to encode SQL pairs into formulas for three possible cases: (1) both queries do not have ORDER BY; (2) only one query has ORDER BY; (3) both queries have ORDER BY. If the resulting formula is satisfiable, the two SQL queries are not equivalent. Importantly, like existing works [30, 60], SQLution does not depend on executing queries on actual data. All entities in the formulas, including tuples and input tables, are symbolic, so the check considers every possible input database subject to the bound and integrity constraints. If the formula is satisfiable, the SMT solver returns concrete table contents on which the queries produce different results; these contents are generated by the solver rather than supplied to SQLution. Case 1: Both queries do not have ORDER BY. In this case, two SQL queries are under bag semantics rather than order semantics. Suppose 𝑓1 and 𝑓2 are the U-expressions modeling the two SQL queries, respectively. The formula for verification is as follows: ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) The formula specifies that there is a tuple 𝑡 such that its multiplicities in the result of 𝑄 1 and 𝑄 2 are different. If the formula is proved

to be unsatisfiable, it means the SQL queries are equivalent. Otherwise, it means that there exists a tuple 𝑡 such that the multiplicities of 𝑡 in the two query results are different. The two queries are nonequivalent and SQLution will return a counterexample. SQLution proves the formula using a new complete decision procedure, which will be discussed in Section 5. Case 2. Only one query has ORDER BY. Step 1: SQLution takes two SQL queries 𝑄 1 and 𝑄 2 as the input. Suppose 𝑄 1 has ORDER BY and 𝑄 2 does not have ORDER BY. 𝑓2 is the U-expression of 𝑄 2 . SQLution reasons about the following formula to check whether there exists a symbolic input database, within the bound, on which 𝑄 2 produces two distinct tuples. ∃𝑡 1, 𝑡 2 .((𝑡 1 ̸= 𝑡 2 ) ∧ (𝑓2 (𝑡 1 ) > 0) ∧ (𝑓2 (𝑡 2 ) > 0))

Algorithm 1: Decision Procedure Input: A formula 𝐹 with first-order logic terms and U-expressions. 2 Output: The satisfiability of the formula. 3 Prove(𝐹 ): 4 𝑏 := GetBoundConfig() 5 𝑀 := ConstructTableToTuples(𝐹 , 𝑏 ) 6 𝐹 1 := ExpandUnboundedSummations(𝐹 , 𝑀 ) 7 𝑟𝑒𝑠𝑢𝑙𝑡 := SMTSolve(𝐹 1 ) 8 if 𝑟𝑒𝑠𝑢𝑙𝑡 = UNSAT then 9 return EQ 10 else 11 return 𝑟𝑒𝑠𝑢𝑙𝑡 1

(1)

• If 𝑑𝑖𝑟 1 is the same as 𝑑𝑖𝑟 2 , the formula for verification is

If the formula is satisfiable, the SMT solver returns concrete table contents on which 𝑄 2 produces two distinct tuples 𝑡 1 and 𝑡 2 . If 𝑄 1 ’s result also has the two different tuples 𝑡 1 and 𝑡 2 , the tuples in 𝑄 1 ’s result are ordered but the tuples in 𝑄 2 ’s result are unordered. Two queries are non-equivalent. If 𝑄 1 ’s result does not have 𝑡 1 or 𝑡 2 , the two queries are still non-equivalent. Step 2: If Equation (1) is unsatisfiable, then on every input database within the bound, 𝑄 2 returns either an empty result or tuples with the same value. For example, if the schema declares a primary key and the query specifies its exact value, the query returns at most one tuple on every valid input database. Thus, if the sub-query followed by ORDER BY in 𝑄 1 is equivalent to 𝑄 2 , 𝑄 1 and 𝑄 2 are also equivalent. This is because ordering an empty result or equalvalued tuples does not change the result. Otherwise, 𝑄 1 and 𝑄 2 are non-equivalent. Based on the above analysis, SQLution extracts the sub-query followed by ORDER BY in 𝑄 1 . Suppose the extracted sub-query is 𝑄 1′ and the U-expression of 𝑄 1′ is 𝑓1 . SQLution checks whether the following formula is satisfiable.

∃𝑡 1, 𝑡 2 .((𝑓1 (𝑡 1 ) > 0) ∧ (𝑓1 (𝑡 2 ) > 0) ∧ (𝑡 1 .𝑎 1 > 𝑡 2 .𝑎 1 ) ∧ (𝑡 1 .𝑎 2 < 𝑡 2 .𝑎 2 )) It means that there exist two tuples 𝑡 1 and 𝑡 2 such that: 1) 𝑡 1 is in the result of two SQL queries (𝑓1 (𝑡 1 ) > 0); 2) 𝑡 2 is in the result of two SQL queries (𝑓1 (𝑡 2 ) > 0); 3) their relative orders in the results of 𝑄 1 and 𝑄 2 are different ((𝑡 1 .𝑎 1 > 𝑡 2 .𝑎 1 ) ∧ (𝑡 1 .𝑎 2 < 𝑡 2 .𝑎 2 )). If the above formula is satisfiable, 𝑄 1 and 𝑄 2 are non-equivalent. Otherwise, they are equivalent. Note that as we have proved the equivalence between sub-queries of 𝑄 1 and 𝑄 2 (i.e., U-expressions 𝑓1 and 𝑓2 are equivalent), (𝑓1 (𝑡 1 ) > 0) ∧ (𝑓1 (𝑡 2 ) > 0) alone can infer that both 𝑡 1 and 𝑡 2 exist in the results of both 𝑄 1 and 𝑄2. • If 𝑑𝑖𝑟 1 is different from 𝑑𝑖𝑟 2 , the formula for verification is ∃𝑡 1, 𝑡 2 .((𝑓1 (𝑡 1 ) > 0) ∧ (𝑓1 (𝑡 2 ) > 0) ∧ (𝑡 1 .𝑎 1 > 𝑡 2 .𝑎 1 ) ∧ (𝑡 1 .𝑎 2 > 𝑡 2 .𝑎 2 )) The meaning of the above formula is similar to the previous formula except for 𝑡 1 .𝑎 2 > 𝑡 2 .𝑎 2 . This is because one query now sorts tuples in ascending order and the other sorts them in descending order.

∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) The formula specifies that there is a tuple 𝑡 such that its multiplicities in the result of 𝑄 1′ and 𝑄 2 are different. If it is satisfiable, SQLution will return the counterexample. Otherwise, two queries are equivalent. Case 3. Both queries have ORDER BY. Step 1: SQLution first checks whether the SQL queries 𝑄 1 and 𝑄 2 have equivalent sub-queries. If not, 𝑄 1 and 𝑄 2 are non-equivalent. Suppose 𝑄 1′ and 𝑄 2′ are the sub-queries of 𝑄 1 and 𝑄 2 , respectively. 𝑓1 and 𝑓2 are the corresponding U-expressions of 𝑄 1′ and 𝑄 2′ . If ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) is satisfiable, there exists a tuple 𝑡 such that 𝑄 1′ and 𝑄 2′ are non-equivalent. SQLution will return the counterexample for 𝑄 1′ and 𝑄 2′ , which is also the counterexample for the original queries 𝑄 1 and 𝑄 2 . Because ORDER BY only sorts tuples without changing tuples. Step 2: If the sub-queries of 𝑄 1′ and 𝑄 2′ are equivalent, SQLution will further check whether 𝑄 1 and 𝑄 2 sort the tuples in the same order. In other words, SQLution needs to check whether there exist two tuples 𝑡 1 and 𝑡 2 such that: 1) 𝑡 1 is before 𝑡 2 in the result of 𝑄 1 , and 2) 𝑡 1 is after 𝑡 2 in the result of 𝑄 2 . Assume that 𝑄 1 and 𝑄 2 sort the tuples produced by their sub-queries according to the attribute 𝑎 1 with order 𝑑𝑖𝑟 1 and 𝑎 2 with order 𝑑𝑖𝑟 2 , respectively. Here 𝑑𝑖𝑟 1 and 𝑑𝑖𝑟 2 can be either ascending order or descending order.

5

UNBOUNDED SUMMATION EXPANSION

This section introduces how we enable the conversion of U-expressions with unbounded summations to pure FOL formulas without losing completeness. Our basic idea is to integrate bounded verification [12, 35, 38, 47, 49] into U-expressions. We propose some rules to expand unbounded summations into bounded summations with specific symbolic tuples.

5.1

Basic Idea

The challenge of handling unbounded summations stems from the unknown number of distinct tuples in each table. An unbounded summation needs to enumerate all possible tuples because it is unknown which tuples can make the summation body not zero. However, we observe that if the number of distinct tuples in each table is known, the number of tuples that make the summation body non-zero will be bounded, and thus the unbounded summation can be expanded to a bounded summation. Based on this insight, we propose unbounded summation expansion, which combines U-expressions with bounded verification to better model the summation semantics of U-expressions and facilitates the capability of complete verification for SQL equivalence. Algorithm 1 shows the overall workflow of our approach. The basic

create table stu ( id int , age int ) ; 𝑄 1 : select id from stu where age > 18 𝑄 2 : select id from stu where age + 4 > 22

Their corresponding U-expressions are: 𝑓1 (𝑡) :=

∑︁ ([𝑡 = 𝑡 1 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18])

𝑓2 (𝑡) :=

∑︁ ([𝑡 = 𝑡 2 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 2 ) × [𝑡 2 .𝑎𝑔𝑒 + 4 > 22])

𝑡1

𝑡2

Figure 3: An example of two equivalent SQL queries along with their U-expressions.

idea is to set the maximum number of distinct tuples in each table as a bound and perform verification under the bound. The value of the bound can be read from a configuration file by invoking GetBoundConfig (Line 4). The workflow consists of the following steps. First, we construct a mapping 𝑀 based on the bound 𝑏, which maps a table name to a list of 𝑏 distinct symbolic tuples. Second, based on 𝑀, we replace all unbounded summations in the formula 𝐹 with bounded summations (detailed in Section 5.2). Finally, we use an off-the-shelf SMT solver to check the satisfiability of the resulting pure first-order logic formula. If the verification condition is satisfiable under a certain bound, the two SQL queries are not equivalent. SMT solvers will provide a counterexample. Otherwise, users can iteratively increase the bound and rerun the verifier until it finds a counterexample or the verification times out. To reason about the equivalence of U-expressions under integrity constraints, SQLution adopts a method similar to those in prior work [30]. Assume the encoding of query equivalence without integrity constraints is 𝐹 . It first encodes the integrity constraints into a firstorder logic formula 𝑃 without quantifiers. Then, SQLution checks the satisfiability of 𝑃 ∧ 𝐹 with Algorithm 1. Since the encoding of integrity constraints is similar to that in prior work [30, 60], we omit the details here. Note that although bounded verification has been adopted in prior works on SQL query verification [30, 60], their bound has a different meaning from ours. In prior works, the bound means the size of the entire table, while our bound is set on the number of distinct tuples rather than all tuples. For example, if the bound is set to one, existing works assume that each table contains at most one tuple, while we assume that each table contains at most one distinct tuple but can have multiple tuples with the same value. Thus, with the same bound, SQLution may find counterexamples that existing works cannot find. For example, consider the SQL queries “select a from r” and “select distinct a from r”. When the bound is one, existing verifiers cannot find counterexamples because they assume the table r has at most one tuple. Both queries will return the tuple. However, with the same bound, SQLution can find the counterexample, which is a table 𝑟 consisting of two tuples with the same value. Then, “select a from r” will return two tuples, while “select distinct a from r” will return only one because “distinct” removes duplicate tuples. Thus, SQLution can prove that these queries are non-equivalent. By determining the number of distinct tuples in each table, our approach can accurately (i.e., without approximation [39]) represent

the unbounded summations with the terms that can be formulated into first-order logic. This means that the approach preserves verification completeness. Our approach iteratively repeats the following three steps until all unbounded summations have been expanded into bounded summations. First, the algorithm finds the innermost P unbounded summation. A summation 𝑡 𝑒(𝑡) is innermost if 𝑒(𝑡) does not have any summation. Second, the algorithm will construct a bounded summation domain by recursively analyzing the sumP mation body. Finally, assume the summation domain for 𝑡 𝑒(𝑡) P is {𝑡 1, . . . , 𝑡𝑛 }. The summation 𝑡 𝑒(𝑡) in the original U-expression will be expanded into 𝑒(𝑡 1 ) + . . . + 𝑒(𝑡𝑛 ). P For each unbounded summation 𝑡 𝑒(𝑡), it is intuitive to set the summation domain as a bounded set consisting of new symbolic tuples. However, this intuitive method has two problems. First, it is hard to determine the size of the summation domain. The domain size should be larger than the number of distinct tuples that can make the summation body non-zero. Otherwise, the original summation will not be equivalent to the bounded summation. However, an overly large domain may contain unnecessary tuples, resulting in overly long formulas and slow verification. Second, the above method needs to introduce a constraint with quantifiers, which specifies that any tuple outside the domain will make the summation body zero. Specifically, for the unbounded summaP tion 𝑡 𝑒(𝑡) and summation domain {𝑡 1, . . . , 𝑡𝑛 }, the constraint is ∀𝑡 .((𝑡 ̸= 𝑡 1 ∧ . . . ∧ 𝑡 ̸= 𝑡𝑛 ) → (𝑒(𝑡) = 0)). Quantifiers are notoriously difficult for SMT solvers to handle. However, omitting the quantifiers loses completeness, which means that an unsatisfiable formula may be incorrectly judged as satisfiable. For example, Figure 3 shows two equivalent queries and their U-expressions 𝑓1 and 𝑓2 . To prove their equivalence, we need to prove that ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) P is unsatisfiable. Assume that the summation domain of 𝑡1 in 𝑓1 P is {𝑎 1, 𝑎 2, . . . , 𝑎𝑚 } and that the summation domain of 𝑡2 in 𝑓1 is {𝑏 1, 𝑏 2, . . . , 𝑏𝑛 }. Then, the formula will be as follows. 𝑚 ∑︁ ∃𝑡 . ([𝑡 = 𝑎𝑖 .𝑖𝑑] × 𝑠𝑡𝑢(𝑎𝑖 ) × [𝑎𝑖 .𝑎𝑔𝑒 > 18]) 𝑖=1

̸=

𝑛 ∑︁ ([𝑡 = 𝑏𝑖 .𝑖𝑑] × 𝑠𝑡𝑢(𝑏𝑖 ) × [𝑏𝑖 .𝑎𝑔𝑒 + 4 > 22]) 𝑖=1

The original formula is unsatisfiable, while the above formula is satisfiable because the latter holds when each 𝑠𝑡𝑢𝑑𝑒𝑛𝑡𝑠(𝑎𝑖 ) is zero and each 𝑠𝑡𝑢𝑑𝑒𝑛𝑡𝑠(𝑏𝑖 ) is one.

5.2

Bounded Summation Domain

To address the challenge, the basic idea is to precisely find each tuple that can make the summation body non-zero rather than directly using new symbolic tuples. Before going into the details, we first consider the example in Figure 3. Assume that the bound is 1, which means the table has at most one distinct tuple. We use 𝑥 to represent the tuple. Then, it is clear that the summation domain P of 𝑡1 in 𝑓1 is {𝑥 }. Because 𝑠𝑡𝑢(𝑡 1 ) can be non-zero only when 𝑡 1 equals 𝑥, which infers that the summation body can be non-zero P only when 𝑡 1 equals 𝑥. The summation domain of 𝑡2 in 𝑓2 is also {𝑥 } due to the same reason. Then, ∃𝑡 .𝑓1 (𝑡) ̸= 𝑓2 (𝑡) will become the following formula. ∃𝑡 .([𝑡 = 𝑥 .𝑖𝑑] × 𝑠𝑡𝑢(𝑥) × [𝑥 .𝑎𝑔𝑒 > 18]) ̸= ([𝑡 = 𝑥 .𝑖𝑑] × 𝑠𝑡𝑢(𝑥) × [𝑥 .𝑎𝑔𝑒 + 4 > 22])

Table 2: The rules of constructing a bounded summation domain 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀), which is a finite set covering all values of the tuple 𝑡 that can make 𝑒 non-zero. 𝑀 is a mapping from a table name to a set of symbolic tuples in the table, which is created at Line 5 in Algorithm 1. 𝑒 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) 𝑟 (𝑡) 𝑀(𝑟 ) [𝑡 = 𝑡 ′ ] {𝑡 ′ } [𝐼𝑠𝑁𝑢𝑙𝑙(𝑡)] {𝑁𝑈 𝐿𝐿} ∥𝑒 1 ∥ 𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀) 𝑒 1 × . . . × 𝑒𝑖 × . . . × 𝑒𝑛 , where 𝑑𝑜𝑚(𝑒𝑖 , 𝑡, 𝑀) 𝑑𝑜𝑚(𝑒𝑖 , 𝑡, 𝑀) ̸= ∅ [𝑡 .𝑎 1 = 𝑣 1 ] × . . . × [𝑡 .𝑎𝑛 = 𝑣𝑛 ] × 𝑒 ′ , {(𝑣 1, . . . , 𝑣𝑛 )} where 𝑡 = (𝑎 1, . . . , 𝑎𝑛 ) and 𝑛𝑜𝑡𝑢𝑠𝑒(𝑣 1, 𝑡) ∧ . . . ∧ 𝑛𝑜𝑡𝑢𝑠𝑒(𝑣𝑛 , 𝑡) 𝑒 1 + 𝑒 2 , where 𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀) ̸= ∅ and 𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀) ∪ 𝑑𝑜𝑚(𝑒 2, 𝑡, 𝑀) ̸= ∅ 𝑑𝑜𝑚(𝑒 2, 𝑡, 𝑀) P P 𝑑𝑜𝑚( 𝑣 ∈𝑆 𝑒 1 (𝑣), 𝑡, 𝑀) 𝑡 1 𝑒 1 (𝑡 1 ), where 𝑑𝑜𝑚(𝑒 1 , 𝑡 1 , 𝑀) = 𝑆 and 𝑆 ̸= ∅ Others ∅

The formula is unsatisfiable because [𝑥 .𝑎𝑔𝑒 > 18] is equivalent to [𝑥 .𝑎𝑔𝑒 + 4 > 22], which infers that the two U-expressions are equivalent. Based on the above observation, we present rules to systematically construct a bounded summation domain, as shown in Table 2. P Given unbounded summation 𝑡 𝑒(𝑡), our rules construct a bounded set of tuples denoted as 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀). 𝑀 is a mapping from a table name to a set of symbolic tuples, which is created at Line 5 in Algorithm 1. Each table 𝑟 only contains tuples in 𝑀(𝑟 ). The purpose of 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is to return a finite set covering all values of 𝑡 such that 𝑒(𝑡) ̸= 0. It can contain 𝑡 s.t. 𝑒(𝑡) = 0 because this does not P P break 𝑡 𝑒(𝑡) = 𝑣 ∈𝑑𝑜𝑚(𝑒,𝑡,𝑀) 𝑒(𝑣). If 𝑒(𝑡) is always zero or there are infinitely many 𝑡 such that 𝑒(𝑡) ̸= 0, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) returns ∅. These rules consider all possible structures of U-expressions and do not create any new symbolic variables. Here is the detailed explanation: • DOM-Rel: Assume 𝑒 is in the form of 𝑟 (𝑡), where 𝑟 is an uninterpreted function that returns the multiplicity of 𝑡 in the table 𝑟 . 𝑟 (𝑡) is non-zero if and only if 𝑡 is a tuple in the table 𝑟 . Thus, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is 𝑀(𝑟 ). • DOM-Eq: Assume 𝑒 is in the form of [𝑡 = 𝑡 ′ ], where 𝑡 ′ is another symbolic tuple. It is non-zero if and only if the predicate 𝑡 = 𝑡 ′ is true. Thus, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is {𝑡 ′ }. • DOM-Null: Assume 𝑒 is in the form of [𝐼𝑠𝑁𝑢𝑙𝑙(𝑡)], where the predicate 𝐼𝑠𝑁𝑢𝑙𝑙 means 𝑡 is NULL. It is non-zero if and only if 𝐼𝑠𝑁𝑢𝑙𝑙(𝑡) holds. Thus, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is {𝑁𝑈 𝐿𝐿}. • DOM-Squash: Assume 𝑒 is in the form of ∥𝑒 1 ∥, where 𝑒 1 is another U-expression. It is non-zero if and only if 𝑒 1 is nonzero. Thus, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is equivalent to 𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀). For example, 𝑑𝑜𝑚(∥𝑠𝑡𝑢(𝑡)∥, 𝑡, 𝑀) is equivalent to 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡), 𝑡, 𝑀), which is 𝑀(𝑠𝑡𝑢). This means that only tuples in the table 𝑠𝑡𝑢 can make ∥𝑠𝑡𝑢(𝑡)∥ non-zero. • DOM-Mul1: Assume 𝑒 is the multiplication of U-expressions 𝑒 1, . . . , 𝑒𝑛 . 𝑒 is not zero if and only if each 𝑒𝑖 ∈ {𝑒 1, . . . , 𝑒𝑛 }

is not zero. Thus, if ∃𝑒𝑖 .(𝑒 = 𝑒 1 × . . . × 𝑒𝑖 × . . . × 𝑒𝑛 ) ∧ (𝑑𝑜𝑚(𝑒𝑖 , 𝑡, 𝑀) ̸= ∅), then 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) = 𝑑𝑜𝑚(𝑒𝑖 , 𝑡, 𝑀). SQLution checks each 𝑒𝑖 sequentially and picks the first 𝑒𝑖 s.t. 𝑑𝑜𝑚(𝑒𝑖 , 𝑡, 𝑀) ̸= ∅. Note that although 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) may contain some tuples that can make some other 𝑒 𝑗 (𝑖 ̸= 𝑗) zero, it does not corrupt completeness, because the rule will not miss any tuples that can make 𝑒 non-zero. For example, 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18], 𝑡 1, 𝑀) is equivalent to 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀), which is 𝑀(𝑠𝑡𝑢). This means that only tuples in the table 𝑠𝑡𝑢 can make 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18] non-zero. • DOM-Mul2: Assume the tuple 𝑡 is a list of symbolic attributes 𝑎 1, . . . , 𝑎𝑚 and 𝑒 is in the form of [𝑡 .𝑎 1 = 𝑣 1 ] × . . . × [𝑡 .𝑎𝑛 = 𝑣𝑛 ] × 𝑒 ′ . Specifically, 𝑡 .𝑎𝑖 is the attribute 𝑎𝑖 of the tuple 𝑡. 𝑒 ′, 𝑣 1, . . . , 𝑣𝑛 are U-expressions. The rule returns (𝑣 1, . . . , 𝑣𝑛 ), because only the tuple (𝑣 1, . . . , 𝑣𝑛 ) can enable 𝑒 ̸= 0. Note that since the U-expression 𝑒 should not contain 𝑡 after expansion, the constructed summation domain also should not contain any attributes in 𝑡. Thus, this rule also requires that each 𝑣𝑖 (1 ≤ 𝑖 ≤ 𝑛) must not use the attributes in 𝑡, which is represented by 𝑛𝑜𝑡𝑢𝑠𝑒(𝑣 1, 𝑡)∧. . .∧𝑛𝑜𝑡𝑢𝑠𝑒(𝑣𝑛 , 𝑡). For example, 𝑑𝑜𝑚([𝑡 1 .𝑖𝑑 = 3] × [𝑡 1 .𝑎𝑔𝑒 = 18], 𝑡 1, 𝑀) is equivalent to {(3, 18)}. This means that only the tuple (3, 18) can make [𝑡 1 .𝑖𝑑 = 3] × [𝑡 1 .𝑎𝑔𝑒 = 18] non-zero. • DOM-Add: Assume 𝑒 is in the form of 𝑒 1 +𝑒 2 , where 𝑒 1 and 𝑒 2 are two other U-expressions. It is non-zero if and only if 𝑒 1 is non-zero or 𝑒 2 is non-zero. Thus, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is equivalent to 𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀) ∪𝑑𝑜𝑚(𝑒 2, 𝑡, 𝑀). For example, 𝑑𝑜𝑚([𝑡 1 = 𝑡] + [𝐼𝑠𝑁𝑢𝑙𝑙(𝑡 1 )], 𝑡 1, 𝑀) is equivalent to {𝑡, 𝑁𝑈 𝐿𝐿}, which means both 𝑡 and 𝑁𝑈 𝐿𝐿 can make [𝑡 1 = 𝑡] + [𝐼𝑠𝑁𝑢𝑙𝑙(𝑡 1 )] non-zero. Note that it requires (𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀) ̸= ∅) ∧ (𝑑𝑜𝑚(𝑒 2, 𝑡, 𝑀) ̸= ∅) rather than (𝑑𝑜𝑚(𝑒 1, 𝑡, 𝑀) ̸= ∅) ∨ (𝑑𝑜𝑚(𝑒 2, 𝑡, 𝑀) ̸= ∅). For example, 𝑑𝑜𝑚(1 + [𝑡 = 0], 𝑡, 𝑀) should be ∅, meaning 1 + [𝑡 = 0] is always non-zero regardless of 𝑡. If the rule uses ∨ rather than ∧, it would incorrectly return 0, which further makes 𝑑𝑜𝑚((1 + [𝑡 = 0]) × 𝑟 (𝑡), 𝑡, 𝑀) equal 0 rather than 𝑀(𝑟 ). • DOM-Sum: Assume 𝑒 is in the form of an unbounded sumP mation 𝑡1 𝑒 1 (𝑡 1 ) and 𝑆 = 𝑑𝑜𝑚(𝑒 1, 𝑡 1, 𝑀). Then, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) = P 𝑑𝑜𝑚( 𝑣 ∈𝑆 𝑒(𝑣), 𝑡, 𝑀). It means SQLution recursively handles the innermost unbounded summation. For example, P assume 𝑀(𝑠𝑡𝑢) = {𝑥 1 } and consider 𝑑𝑜𝑚( 𝑡1 (𝑠𝑡𝑢(𝑡 1 ) × [𝑡 = 𝑡 1 .𝑖𝑑]), 𝑡, 𝑀). For the summation body 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 = 𝑡 1 .𝑖𝑑], DOM-Rel infers that 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀) = 𝑀(𝑠𝑡𝑢), which is {𝑥 1 }. Then, DOM-Mul1 infers that 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ) × [𝑡 = 𝑡 1 .𝑖𝑑], 𝑡 1, 𝑀) is also {𝑥 1 }. Thus, DOM-Sum rewrites the unbounded summation as 𝑠𝑡𝑢(𝑥 1 ) × [𝑡 = 𝑥 1 .𝑖𝑑], after which the remaining rules infer that 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑥 1 ) × [𝑡 = 𝑥 1 .𝑖𝑑], 𝑡, 𝑀) is P {𝑥 1 .𝑖𝑑 }. This means that 𝑡1 (𝑠𝑡𝑢(𝑡 1 )×[𝑡 = 𝑡 1 .𝑖𝑑]) is non-zero only when 𝑡 equals 𝑥 1 .𝑖𝑑. • DOM-Other: If 𝑒 does not match any of the above forms, such as constants or negations, 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is ∅. For example, 𝑑𝑜𝑚(1, 𝑡, 𝑀) = ∅ because the constant 1 is non-zero for every possible value of 𝑡. To further illustrate the rules, we provide two more complex examples below.

P Example 1. Consider the unbounded summation 𝑡1 ([𝑡 = 𝑡 1 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18]) of the U-expression 𝑓1 (𝑡) in Figure 3. Assume the bound is 2 and 𝑀(𝑠𝑡𝑢) is {𝑥 1, 𝑥 2 }, where 𝑥 1 and 𝑥 2 are two distinct symbolic tuples. According to DOM-Rel, 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀) is 𝑀(𝑠𝑡𝑢). By further applying DOM-Mul1, 𝑑𝑜𝑚([𝑡 = 𝑡 1 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18], 𝑡 1, 𝑀) is also 𝑀(𝑠𝑡𝑢). Then, 𝑓1 (𝑡) is transformed to P 𝑡 1 ∈ {𝑥 1 ,𝑥 2 } ([𝑡 = 𝑡 1 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18]), which is a bounded P summation. Similarly, 𝑓2 (𝑡) is transformed to 𝑡2 ∈ {𝑥 1 ,𝑥 2 } ([𝑡 = 𝑡 2 .𝑖𝑑]× 𝑠𝑡𝑢(𝑡 2 ) × [𝑡 2 .𝑎𝑔𝑒 + 4 > 22]). Finally, SQLution will check the satisfiability of the following formula: ∑︁ ([𝑡 = 𝑡 1 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 1 ) × [𝑡 1 .𝑎𝑔𝑒 > 18]) 𝑡 1 ∈ {𝑥 1 ,𝑥 2 }

̸=

∑︁

([𝑡 = 𝑡 2 .𝑖𝑑] × 𝑠𝑡𝑢(𝑡 2 ) × [𝑡 2 .𝑎𝑔𝑒 + 4 > 22])

𝑡 2 ∈ {𝑥 1 ,𝑥 2 }

summations with bounded summations based on rules, then 𝑓 (𝑡) = 𝑓 ′ (𝑡).

6

SOUNDNESS AND COMPLETENESS

This section provides some theorems about the soundness and completeness of our verification method. The proof can be found in Section 4 of supplementary materials [6]. Theorem 6.1 (Guarantee of Completeness). For any queries 𝑄 1 , 𝑄 2 , integrity constraints IC, and a bound 𝑏, if SQLution finds a counterexample, then 𝑄 1 ̸= 𝑄 2 . Theorem 6.2. There exist non-equivalent queries 𝑄 1 , 𝑄 2 , integrity constraints IC, and a bound 𝑏 such that SQLution cannot find counterexamples.

We additionally add 𝑥 1 ̸= 𝑥 2 to specify that they are distinct tuples in the set 𝑀(𝑠𝑡𝑢). This formula is apparently unsatisfiable, which infers that two queries are equivalent. Example 2. Consider the query “select id from (select ∗ from stu union all select ∗ from stu)”, which uses the same schema as in Figure 3. This query is simple for illustration P purpose. The U-expression is 𝑓 (𝑡) := 𝑡1 ((𝑠𝑡𝑢(𝑡 1 ) + 𝑠𝑡𝑢(𝑡 1 )) × [𝑡 = 𝑡 1 .𝑖𝑑]). Assume the bound is 2 and 𝑀(𝑠𝑡𝑢) is {𝑥 1, 𝑥 2 }. By applying DOM-Rel, 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀) is 𝑀(𝑠𝑡𝑢). Then, DOM-Add infers that 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ) + 𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀) is 𝑀(𝑠𝑡𝑢) ∪ 𝑀(𝑠𝑡𝑢), which is 𝑀(𝑠𝑡𝑢). Since 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ) + 𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀) is not ∅, DOM-Mul1 further infers that 𝑑𝑜𝑚((𝑠𝑡𝑢(𝑡 1 ) + 𝑠𝑡𝑢(𝑡 1 )) × [𝑡 = 𝑡 1 .𝑖𝑑], 𝑡 1, 𝑀) is 𝑑𝑜𝑚(𝑠𝑡𝑢(𝑡 1 ) + 𝑠𝑡𝑢(𝑡 1 ), 𝑡 1, 𝑀), which is also 𝑀(𝑠𝑡𝑢). Finally, the unbounded summaP tion becomes a bounded summation 𝑡1 ∈ {𝑥 1 ,𝑥 2 } ((𝑠𝑡𝑢(𝑡 1 ) + 𝑠𝑡𝑢(𝑡 1 )) × [𝑡 = 𝑡 1 .𝑖𝑑]).

Theorem 6.3. For any queries 𝑄 1 , 𝑄 2 , integrity constraints IC, and a bound 𝑏, if there exists database data DB such that 1) each table in DB has at most 𝑏 distinct rows, and 2) 𝑄 1 (𝐷𝐵) ̸= 𝑄 2 (𝐷𝐵), then SQLution will return a counterexample. We assume the SQL queries do not have SQL features unsupported by SQLution, and SMT solvers can solve the generated SMT formula.

5.3

SQLution reuses SQL parser and U-expression encoder of SQLSolver [27]. However, SQLution adds ordered bag semantics and unbounded-summation expansion modules. Finally, SQLution encodes bounded U-expressions as a pure FOL formula and checks it with Z3 [25]. A satisfiable formula yields a counterexample distinguishing the queries; otherwise, they are equivalent.

Theoretical Analysis

For any unbounded summation in the U-expression of a given SQL query, the rules in Table 2 can always infer a non-empty and bounded set, which can help transform it to an equivalent bounded summation. Note that although it is easy to construct a summaP tion 𝑡 𝑒(𝑡) such that 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) is ∅, such summation will not exist in U-expressions of valid SQL queries. Here are theorems that formalize the above statements. Due to space limitation, we omit the proof, which can be found in Section 3 of supplementary materials [6]. P Theorem 5.1. For any unbounded summation 𝑡 𝑒(𝑡) in the Uexpression of a SQL query and a mapping 𝑀, if the rules in Table 2 generate a set 𝑆 := 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀), 𝑆 is bounded. Theorem 5.2. For any U-expression of a SQL query 𝑄, a bound 𝑏, and a mapping 𝑀, the following properties hold: P (1) For any unbounded summation 𝑡 𝑒(𝑡) in the U-expression, the rules in Table 2 will generate a set 𝑆 := 𝑑𝑜𝑚(𝑒, 𝑡, 𝑀) such that 𝑆 ̸= ∅ P P and 𝑡 𝑒(𝑡) = 𝑣 ∈𝑆 𝑒(𝑣). (2) If replacing all unbounded summations with bounded summaP P tions (i.e., replacing 𝑡 𝑒(𝑡) with 𝑣 ∈𝑆 𝑒(𝑣) above) via the rules in Table 2 will generate a new U-expression 𝑓 ′ (𝑡), then 𝑑𝑜𝑚(𝑓 ′, 𝑡, 𝑀) ̸= ∅ and ∀𝑣 .((𝑓 ′ (𝑣) ̸= 0) → (𝑣 ∈𝑑𝑜𝑚(𝑓 ′, 𝑡, 𝑀))). Theorem 5.3. For any U-expression 𝑓 (𝑡) of a SQL query, a bound 𝑏, and a mapping 𝑀, if 𝑓 (𝑡) becomes 𝑓 ′ (𝑡) after replacing unbounded

Theorem 6.4. (1) For any queries 𝑄 1 and 𝑄 2 , integrity constraint IC, and a bound 𝑏, if Polygon finds a counterexample, SQLution can find a counterexample. We assume that SMT solvers can successfully solve the generated formulas. (2) There exist queries 𝑄 1 and 𝑄 2 , integrity constraint IC, and a bound 𝑏 such that SQLution can find a counterexample and Polygon can’t.

7

8

IMPLEMENTATION

EVALUATION

In the evaluation, we answer the following questions: 1) Does SQLution have better verification capability than prior work? 2) Does SQLution have faster verification speed than prior work? 3) What are the main reasons for SQLution’s advantages?

8.1

Experimental Setup

Baseline. To answer the above questions, we compare SQLution with VeriEQL [30] and Polygon [60], which are the state-of-theart complete verifiers for SQL equivalence. The evaluation does not compare SQLution with sound verifiers because they are incomplete and therefore are not helpful baselines for counterexample generation. For example, the recent sound verifier SQLSolver cannot generate counterexamples for any query pair, regardless of whether the queries are equivalent. For an applesto-apples comparison, we do not compare SQLution with testing tools for SQL equivalence. Note that prior evaluations have compared our baselines, VeriEQL and Polygon, with various testing tools [16, 18, 19, 23]. The results demonstrate that these verifiers

have a stronger ability to identify non-equivalent query pairs than testing tools. Thus, we do not repeat the comparison with testing tools and instead compare SQLution directly with VeriEQL and Polygon. Moreover, testing tools do not provide the theoretical guarantees offered by complete verifiers. Benchmark. To evaluate the verification capability and efficiency of each approach, we use three benchmarks. The first benchmark contains 997 pairs of SQL queries derived from Spider [58], which is a popular benchmark for the text-to-SQL task. Each test case in Spider requires an LLM to translate a natural-language question about a database into a SQL query. Since Spider is widely used to evaluate LLM-based text-to-SQL models, it represents realistic SQL queries and covers commonly used SQL features. We use the translation results of DAIL-SQL [29], the top model on the Spider leaderboard [56]. Then, we pair the generated query with the corresponding correct answer provided by Spider to form a test case of equivalence verification. The benchmark contains both equivalent and non-equivalent SQL query pairs. To check whether two queries in each test case are indeed equivalent or non-equivalent, we combine sound verifiers (e.g., SQLSolver [27]) and complete verifiers (e.g., Polygon). If a pair of SQL queries is verified to be nonequivalent by complete verifiers or equivalent by sound verifiers, we directly adopt the verification result. Otherwise, we manually check the queries. Among the original 1,034 query pairs, 726 are equivalent and 271 are non-equivalent. We discard the other 37 pairs because they are ambiguous for the reason described in Section 4.1. The second benchmark contains 127 query pairs derived from the Spark SQL benchmark used by SQLSolver [27]. Seventeen of the 127 cases use SQL features unsupported by SQLution, such as window functions. The original benchmark contains equivalent pairs extracted from Spark SQL optimizer rewrites. To evaluate counterexample generation, we use an LLM to mutate one query in each pair, making the pair non-equivalent. We confirm non-equivalence by finding a counterexample for every pair. The number of cases containing SQL features unsupported by SQLution increases from 14 to 17 after mutation. This increase indicates that the mutation does not construct only favorable cases and that the benchmark reflects the limitations of SQLution. To further evaluate the verification efficiency on more complex verification tasks, we adopt another benchmark with 1,000 test cases derived from Cubes, which was crafted by Polygon [60]. We do not consider the benchmarks used in VeriEQL, such as Calcite, because most cases in the Calcite benchmark are equivalent [30]. VeriEQL finds only 4 pairs of non-equivalent queries from this benchmark. Thus, Calcite is not suitable to reflect the benefit of finding counterexamples faster. Unlike the Spider and Spark SQL benchmarks, each test case in Cubes contains 100 SQL queries rather than two SQL queries. For each test case, the verifier needs to encode the semantics of 100 SQL queries into only one formula and find a counterexample that can classify these queries into different equivalence classes. It means that when running the 100 SQL queries on the counterexample, some queries will produce the same result, while the other SQL queries will produce a different result. This benchmark demonstrates that, in addition to the traditional task of verifying equivalence between two SQL queries, SQLution can reason about multiple SQL queries. Polygon also crafts another

Table 3: The comparison among SQLution, VeriEQL, and Polygon on the Spider and Spark SQL benchmarks. The table shows the total number of test cases proved to be nonequivalent under each bound. Bound Benchmark

Verifier 1

2

3

4

Spider

SQLution VeriEQL Polygon

191 70 105

257 79 138

265 81 140

269 81 140

Spark SQL

SQLution VeriEQL Polygon

63 41 45

90 54 83

110 55 84

110 55 84

benchmark, each test case of which contains 50 SQL queries. However, we do not use it in the evaluation because it is similar to the above benchmark and each test case contains fewer SQL queries. Note that the Cubes benchmark was crafted by Polygon and uses only SQL features supported by Polygon and SQLution. Thus, it is mainly used to evaluate the verification efficiency. Testbed. We run all experiments on a machine with 16 vCPUs and 32 GiB of memory. It uses a third-generation Intel Xeon Scalable processor and runs 64-bit Ubuntu 24.04 Server. Both SQLution and Polygon use Z3 4.15.4 [25, 26] as the underlying SMT solver. SQLution reuses the SQL parser of Apache Calcite [11, 15] to parse SQL queries.

8.2

Verification Capability

Capability of identifying non-equivalent queries. We evaluate the capability of SQLution, VeriEQL, and Polygon to identify nonequivalent queries. Specifically, we vary the bound from 1 to 4 and check how many test cases each verifier can prove non-equivalent at the same bound. The maximal bound is 4 because the number of non-equivalent cases identified by each verifier does not change when we continue to increase the bound. To fully reflect the verification capabilities of all three verifiers, we wait until each verifier finishes normally without timing out. As shown in Table 3, on both the Spider and Spark SQL benchmarks, SQLution disproves more non-equivalent test cases than VeriEQL and Polygon. VeriEQL disproves fewer non-equivalent cases than Polygon at all bounds, confirming the stronger verification capability of Polygon reported by Zhao et al. [60]. Compared with Polygon, SQLution disproves 86, 115, 125, and 129 more non-equivalent test cases in the Spider benchmark at bounds 1, 2, 3, and 4, respectively. On the Spark SQL benchmark, SQLution disproves 18, 7, 26, and 26 more non-equivalent test cases at bounds 1, 2, 3, and 4, respectively. Among 271 non-equivalent cases in the Spider benchmark, SQLution can disprove 269 (99.3%) of them at bound 4, while Polygon can disprove only 140 (51.7%). We find that the remaining two cases can be disproved at bound 10. Among all 127 cases in the Spark SQL benchmark, SQLution can disprove 110 (86.6%) of them at bound 4, while Polygon can disprove only 84 (66.1%). The remaining 17 non-equivalent cases cannot be disproved by SQLution because of unsupported SQL features, such as window functions. The main

8.3

Verification Efficiency

Since VeriEQL can disprove only a small proportion of non-equivalent test cases, we mainly compare the verification time of SQLution and Polygon to demonstrate the efficiency advantage of SQLution. We only consider the test cases supported by both SQLution and Polygon for fairness. Among these cases, we consider only nonequivalent test cases because complete verifiers output “equivalent” by default when they cannot finish within the predefined time limit. Thus, verification efficiency is meaningful only for non-equivalent cases. For test cases from Spider and Spark SQL, we increase the bound from 1 until the verifier can disprove it or the bound reaches the maximal value, 4, which is the same as the setting of Section 8.2. For test cases from Cubes, we increase the bound from 1 to 3 because neither verifier identifies new non-equivalent test cases when the bound is increased from 2 to 3. Table 4 compares verification efficiency and test-case complexity in terms of the number of AST nodes. Specifically, for each test case, we parse all its queries with the popular SQL parser SQLGlot [24] and count the nodes in the generated AST. SQLution brings more performance benefits on the Cubes benchmark. The

Table 4: The complexity of benchmarks and median verification time (ms) of SQLution and Polygon. “# AST Nodes of SQL” is the sum of AST nodes of all queries in a test case. For fairness, we only compare the verification time of the test cases that are supported by both verifiers and contains non-equivalent queries. # AST Nodes of SQL

Spider Spark SQL Cubes

Avg.

Med.

Max.

43 46 4251

36 41 4219

158 98 7233

SQLution

Polygon

8.0 12.0 95.0

47.4 53.5 13426.3

×105 800

Same performance (y = x)

500 400 300 200

800 600 400 200

100 0

1.2

Pol gon time (ms)

Polygon time (ms)

600

0

200

400

600

SQLution time (ms)

(a) Spider

800

0

Same performance (y = x)

Same performance (y = x)

1000

700

Pol gon time (ms)

reason for the advantage of SQLution is that SQLution can support more SQL features than Polygon, as discussed above. Most cases are due to this reason. Another reason is that for some nonequivalent SQL queries, SQLution requires a smaller bound than Polygon to disprove them. For the Cubes benchmark, since it uses only SQL features supported by SQLution, VeriEQL, and Polygon, we mainly use it to evaluate verification speed, as presented in Section 8.3. Capability of supporting SQL features. We also demonstrate that SQLution supports more SQL features by comparing the numbers of test cases supported by SQLution and Polygon; Polygon has stronger verification capability than VeriEQL. SQLution supports all SQL features supported by Polygon, including SELECTION, PROJECTION, CTEs, subqueries, aggregate functions, UNION, UNION ALL, VALUES, INNER JOIN, CROSS JOIN, FULL JOIN, OUTER JOIN, ORDER BY, LIMIT, CASE WHEN, and EXISTS. Some features are unsupported by Polygon but supported by SQLution, such as INTERSECT, EXCEPT, and OFFSET. Specifically, we set the bound to one and run each verifier until it finishes normally. If the verifier finishes normally on a test case, it means that the verifier can support it. Among 1,124 test cases in the Spider and Spark SQL benchmarks, SQLution supports 1,107, which is 337 more than Polygon supports. Some cases unsupported by Polygon use SQL features, such as INTERSECT and EXCEPT. In contrast, these SQL features can be directly encoded with U-expressions in SQLution. The result demonstrates the expressiveness of Uexpressions for bag semantics. Note that although U-expressions are very powerful, they still cannot realize a complete verifier without our decision procedure (Section 5). Besides, there are 178 cases using ORDER BY/LIMIT/OFFSET, which cannot be supported by a U-expression alone. SQLution can support them due to the encoding method for ordered bag semantics (Section 4). The Cubes benchmark was crafted by Polygon and uses only SQL features supported by Polygon. Thus, SQLution supports all features in the Cubes benchmark.

0

200

400

600

800 1000

SQLution time (ms)

(b) Spark SQL

0.9 0.6 0.3 0.0 0.0

0.3

0.6

0.9

1.2

SQLution time (ms)

×105

(c) Cubes

Figure 4: Per-case verification time of SQLution and Polygon on the Spider, Spark SQL, and Cubes benchmarks. Each point represents the verification times for one test case shown to be non-equivalent by both verifiers. The dashed lines indicate equal performance.

median verification time is reduced from 13.4 seconds to only 95 ms, a speedup of more than 100×. This is because the test cases in the Cubes benchmark are much more complex. The median number of AST nodes in the Cubes benchmark is > 100× that in the other two benchmarks. Figure 4 compares the verification times of all cases disproved by both SQLution and Polygon. Each point represents one test case. The x-axis shows the verification time of SQLution, while the y-axis shows that of Polygon. The 𝑦 = 𝑥 line indicates equal performance. Points above the dashed 𝑦 = 𝑥 lines indicate cases in which SQLution is faster than Polygon. For the non-equivalent cases in the Spider benchmark, SQLution reduces the verification time of 92.9% of test cases by ≥ 50%. The verification time of 43.6% of test cases can be reduced by ≥ 80%. For the Spark SQL benchmark, SQLution reduces the verification time of 95.2% of test cases by ≥ 50%, and reduces the verification time of 51.2% of test cases by ≥ 80%. For the Cubes benchmark, SQLution reduces the verification time of 94.1% of test cases by ≥ 50%. The verification time of 82.3% of test cases can be reduced by ≥ 90%. The median time reduction ratios of SQLution over Polygon are 78.7%, 82.1%, and 97.2% on Spider, Spark SQL, and Cubes, respectively. Among all test cases that can be disproved by both SQLution and Polygon, SQLution is faster than Polygon in 1,124/1,140 cases (98.6%). SQLution is faster when 1) SQLution generates a simpler SMT formula than Polygon, and 2) solving a simpler formula is faster for SMT solvers. These two conditions do not always hold. The first condition may

Table 5: Reduction of formula complexity of SQLution over Polygon. For each bound value, we collect test cases that: (1) both verifiers can disprove it, and (2) it cannot be disproved with a smaller bound. We report the median reduction of complexity. Spider

Spark SQL

Cubes

Bound Size

# AST Nodes

# Operators

Size

# AST Nodes

# Operators

Size

# AST Nodes

# Operators

1 2 3

-53.0% -87.6% -81.6%

-82.8% -96.0% -94.2%

-83.1% -95.0% -93.7%

-72.0% -82.1% -80.3%

-88.9% -93.8% -93.3%

-88.9% -92.6% -91.8%

-97.0% -98.8% /

-98.7% -99.6% /

-98.4% -99.4% /

Med.

-59.2%

-85.6%

-86.0%

-76.8%

-91.5%

-90.4%

-97.7%

-99.1%

-98.8%

fail when the SQL queries are very simple and the number of table columns and the bound are very small. The second condition does not always hold because of SMT instability [63]. It means that even two semantically equivalent SMT queries may sometimes have rather different performance on the same SMT solver. We further analyze the reason for the efficiency advantage of SQLution over Polygon. We use three metrics to measure the complexity of a formula, including size, the number of AST nodes, and the number of operators. The size is the length of the formula string in the SMT-LIB format [31]. For each bound, we consider only non-equivalent test cases satisfying two conditions: 1) both SQLution and Polygon can disprove the case at this bound; and 2) neither verifier can disprove it at a smaller bound. Thus, for the Spider and Spark SQL benchmarks, we do not consider bound 4 because Polygon does not disprove new non-equivalent cases when the bound increases from 3 to 4. For the Cubes benchmark, we do not consider bound 3 because neither verifier disproves new non-equivalent cases at this bound. As shown in Table 5, SQLution significantly reduces the formula size, the number of AST nodes, and the number of operators in all three benchmarks. For example, the median reductions in formula size, the number of AST nodes, and the number of operators are 76.8%, 91.5%, and 90.4% on the Spark SQL benchmark, respectively. The reduction ratio is larger for the Cubes benchmark because test cases of the Cubes benchmark are more complex. For the Spider and Spark SQL benchmarks, the reduction ratio decreases when the bound increases from 2 to 3 because the test cases at different bounds are different. Thus, SQLution’s simpler formulas explain its efficiency advantage.

9

and compares the resulting syntactic structures, but equivalent expressions do not always have structurally similar normal forms. WeTune [55] instead translates equivalence into a FOL formula checked by SMT solvers, using manually crafted approximations that handle only specific forms of unbounded summation. SQLSolver [27] handles arbitrary forms of unbounded summation without predefined rules. Because all these approaches target soundness, SQLution requires different algorithms to ensure completeness. Reasoning about ordered bag semantics. Some existing verifiers [20, 54, 55, 61, 62] only support bag semantics. Recently, some works [27, 30, 60] have proposed methods to support queries with ordered bag semantics. Existing methods are incomplete or inefficient; SQLution is complete and faster.

10

LIMITATIONS

SQLution has the following two limitations. First, SQLution does not support some SQL features, such as window functions, OVER, PARTITION BY, ROLLUP, CUBE, lateral scalar sub-query, and recursive CTEs, because these features are not supported by Uexpressions. They are also unsupported by the evaluated complete verifiers VeriEQL and Polygon [30, 60]. Second, if a query sorts tuples by non-unique attributes, its result will be nondeterministic because the order of tuples with identical values for the sorting attributes is ambiguous. Existing SQL equivalence verifiers [27, 30, 60] do not define query equivalence in such cases. Thus, SQLution also does not handle such ambiguous queries. How to encode more SQL features into U-expressions and handle nondeterministic SQL queries is an interesting direction for future work.

RELATED WORK 11

Complete verification for SQL equivalence. Recent works [21, 30, 53, 60] have made significant progress in developing complete verifiers for SQL query equivalence. VeriEQL [30] supports SQL features by representing the input and output of each SQL operator as symbolic lists related by FOL formulas. This list-based encoding produces complex formulas, as discussed in Section 2. Polygon [60] accelerates verification by constructing under-approximations of VeriEQL’s formulas to search a smaller space, but retains the complexity of list-based encoding. In contrast, SQLution uses Uexpressions to generate much simpler formulas while supporting more SQL features. Reasoning about U-expressions. U-expressions are an algebra capable of encoding a wide range of SQL features. Prior works [20, 27, 54, 55] propose several algorithms for reasoning about their equivalence. UDP [20] uses predefined rules to normalize U-expressions

CONCLUSION

This paper presents SQLution, a complete verifier for SQL query equivalence. We propose a new encoding method for SQL query equivalence based on U-expressions that produces much simpler formulas than prior work. We design a complete decision procedure to reason about U-expressions, which can handle unbounded summations with unbounded summation expansion. The evaluation shows that SQLution can verify queries dramatically faster than the state-of-the-art Polygon while supporting more SQL features.

REFERENCES [1] 2021. MySQL Bug #104918: Derived condition pushdown rewrite ignores user variables. https://bugs.mysql.com/bug.php?id=104918. [2] 2024. DuckDB Issue #11294: UNION DISTINCT and EXCEPT DISTINCT is ignored when subquery returns no rows. https://github.com/duckdb/duckdb/ issues/11294.

[3] 2026. Apache Spark Issue SPARK-58383. https://issues.apache.org/jira/browse/ SPARK-58383. [4] Serge Abiteboul, Richard Hull, and Victor Vianu. 1995. Foundations of databases. Vol. 8. Addison-Wesley Reading. [5] Rajeev Alur, Rastislav Bodik, Garvit Juniwal, Milo M. K. Martin, Mukund Raghothaman, Sanjit A. Seshia, Rishabh Singh, Armando Solar-Lezama, Emina Torlak, and Abhishek Udupa. 2013. Syntax-guided synthesis. In 2013 Formal Methods in Computer-Aided Design. 1–8. https://doi.org/10.1109/FMCAD.2013.6679385 [6] Authors. 2026. Supplementary Material. https://anonymous.4open.science/r/ sqlution-vldb2027-supplementary-material-D826. [7] Qiushi Bai, Sadeem Alsudais, and Chen Li. 2023. QueryBooster: Improving SQL Performance Using Middleware Services for Human-Centered Query Rewriting. Proc. VLDB Endow. 16, 11 (July 2023), 2911–2924. https://doi.org/10.14778/36114 79.3611497 [8] Haniel Barbosa, Clark W. Barrett, Martin Brain, Gereon Kremer, Hanna Lachnitt, Makai Mann, Abdalrhman Mohamed, Mudathir Mohamed, Aina Niemetz, Andres Nötzli, Alex Ozdemir, Mathias Preiner, Andrew Reynolds, Ying Sheng, Cesare Tinelli, and Yoni Zohar. 2022. cvc5: A Versatile and Industrial-Strength SMT Solver. In Tools and Algorithms for the Construction and Analysis of Systems 28th International Conference, TACAS 2022, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2022, Munich, Germany, April 2-7, 2022, Proceedings, Part I (Lecture Notes in Computer Science), Dana Fisman and Grigore Rosu (Eds.), Vol. 13243. Springer, 415–442. https://doi.org/ 10.1007/978-3-030-99524-9_24 [9] Clark W. Barrett, Christopher L. Conway, Morgan Deters, Liana Hadarean, Dejan Jovanovic, Tim King, Andrew Reynolds, and Cesare Tinelli. 2011. CVC4. In Computer Aided Verification - 23rd International Conference, CAV 2011, Snowbird, UT, USA, July 14-20, 2011. Proceedings (Lecture Notes in Computer Science), Ganesh Gopalakrishnan and Shaz Qadeer (Eds.), Vol. 6806. Springer, 171–177. https: //doi.org/10.1007/978-3-642-22110-1_14 [10] Pascal Baumann, Rupak Majumdar, Ramanathan S. Thinniyam, and Georg Zetzsche. 2021. Context-bounded verification of liveness properties for multithreaded shared-memory programs. Proc. ACM Program. Lang. 5, POPL, Article 44 (Jan. 2021), 31 pages. https://doi.org/10.1145/3434325 [11] Edmon Begoli, Jesús Camacho-Rodríguez, Julian Hyde, Michael J. Mior, and Daniel Lemire. 2018. Apache Calcite: A Foundational Framework for Optimized Query Processing Over Heterogeneous Data Sources. In Proceedings of the 2018 International Conference on Management of Data (Houston, TX, USA) (SIGMOD ’18). Association for Computing Machinery, New York, NY, USA, 221–230. https: //doi.org/10.1145/3183713.3190662 [12] Armin Biere, Alessandro Cimatti, Edmund M. Clarke, and Yunshan Zhu. 1999. Symbolic Model Checking without BDDs. In Proceedings of the 5th International Conference on Tools and Algorithms for Construction and Analysis of Systems (TACAS ’99). Springer-Verlag, Berlin, Heidelberg, 193–207. [13] Ricardo Brancas, Miguel Terra-Neves, Miguel Ventura, Vasco Manquinho, and Ruben Martins. 2024. Towards Reliable SQL Synthesis: Fuzzing-Based Evaluation and Disambiguation. In Fundamental Approaches to Software Engineering: 27th International Conference, FASE 2024, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2024, Luxembourg City, Luxembourg, April 6–11, 2024, Proceedings (Luxembourg City, Luxembourg). Springer-Verlag, Berlin, Heidelberg, 232–254. https://doi.org/10.1007/978-3-031-57259-3_11 [14] Ricardo Brancas, Miguel Terra-Neves, Miguel Ventura, Vasco Manquinho, and Ruben Martins. 2025. CUBES: A Parallel Synthesizer for SQL Using Examples. Form. Asp. Comput. (Sept. 2025). https://doi.org/10.1145/3768578 Just Accepted. [15] Apache Calcite. 2025. Apache Calcite Project. http://calcite.apache.org. [16] Jeroen Castelein, Maurício Aniche, Mozhan Soltani, Annibale Panichella, and Arie van Deursen. 2018. Search-based test data generation for SQL queries. In Proceedings of the 40th International Conference on Software Engineering (Gothenburg, Sweden) (ICSE ’18). Association for Computing Machinery, New York, NY, USA, 1220–1230. https://doi.org/10.1145/3180155.3180202 [17] Ashok K. Chandra and Philip M. Merlin. 1977. Optimal Implementation of Conjunctive Queries in Relational Data Bases. In Proceedings of the Ninth Annual ACM Symposium on Theory of Computing (Boulder, Colorado, USA) (STOC ’77). Association for Computing Machinery, New York, NY, USA, 77–90. https: //doi.org/10.1145/800105.803397 [18] Bikash Chandra, Ananyo Banerjee, Udbhas Hazra, Mathew Joseph, and S. Sudarshan. 2019. Automated Grading of SQL Queries. In 2019 IEEE 35th International Conference on Data Engineering (ICDE). 1630–1633. https://doi.org/10.1109/ICDE. 2019.00159 [19] Bikash Chandra, Bhupesh Chawda, Biplab Kar, KV Maheshwara Reddy, Shetal Shah, and S Sudarshan. 2015. Data generation for testing and grading SQL queries. The VLDB Journal 24, 6 (2015), 731–755. [20] Shumo Chu, Brendan Murphy, Jared Roesch, Alvin Cheung, and Dan Suciu. 2018. Axiomatic Foundations and Algorithms for Deciding Semantic Equivalences of SQL Queries. Proc. VLDB Endow. 11, 11 (jul 2018), 1482–1495. https://doi.org/10 .14778/3236187.3236200

[21] Shumo Chu, Chenglong Wang, Konstantin Weitz, and Alvin Cheung. 2017. Cosette: An Automated Prover for SQL.. In Proceedings of the 8th Biennial Conference on Innovative Data Systems Research (Chaminade, California, USA) (CIDR ’17). [22] Shumo Chu, Konstantin Weitz, Alvin Cheung, and Dan Suciu. 2017. HoTTSQL: Proving Query Rewrites with Univalent SQL Semantics. SIGPLAN Not. 52, 6 (June 2017), 510–524. https://doi.org/10.1145/3140587.3062348 [23] Fabien Coelho. 2013. DataFiller: Generate Random Data from Database Schema. https://github.com/memsql/datafiller. [24] SQLGlot Contributors. 2025. SQLGlot: Python SQL Parser and Transpiler. https: //github.com/tobymao/sqlglot. [25] Z3 contributors. 2025. z3-4.15.4. https://github.com/Z3Prover/z3. [26] Leonardo De Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In Proceedings of the Theory and Practice of Software, 14th International Conference on Tools and Algorithms for the Construction and Analysis of Systems (Budapest, Hungary) (TACAS ’08/ETAPS’08). Springer-Verlag, Berlin, Heidelberg, 337–340. [27] Haoran Ding, Zhaoguo Wang, Yicun Yang, Dexin Zhang, Zhenglin Xu, Haibo Chen, Ruzica Piskac, and Jinyang Li. 2023. Proving Query Equivalence Using Linear Integer Arithmetic. Proc. ACM Manag. Data 1, 4, Article 227 (Dec. 2023), 26 pages. [28] Rui Dong, Jie Liu, Yuxuan Zhu, Cong Yan, Barzan Mozafari, and Xinyu Wang. 2023. SlabCity: Whole-Query Optimization Using Program Synthesis. Proc. VLDB Endow. 16, 11 (July 2023), 3151–3164. https://doi.org/10.14778/3611479.3611515 [29] Dawei Gao, Haibin Wang, Yaliang Li, Xiuyu Sun, Yichen Qian, Bolin Ding, and Jingren Zhou. 2024. Text-to-SQL Empowered by Large Language Models: A Benchmark Evaluation. Proc. VLDB Endow. 17, 5 (Jan. 2024), 1132–1145. [30] Yang He, Pinhan Zhao, Xinyu Wang, and Yuepeng Wang. 2024. VeriEQL: Bounded Equivalence Verification for Complex SQL Queries with Integrity Constraints. Proc. ACM Program. Lang. 8, OOPSLA1, Article 132 (April 2024), 29 pages. [31] The SMT-LIB Initiative. 2025. SMT-LIB: The Satisfiability Modulo Theories Libraries. https://smt-lib.org. [32] Omar Inverso, Ermenegildo Tomasco, Bernd Fischer, Salvatore La Torre, and Gennaro Parlato. 2021. Bounded Verification of Multi-threaded Programs via Lazy Sequentialization. ACM Trans. Program. Lang. Syst. 44, 1, Article 1 (Dec. 2021), 50 pages. https://doi.org/10.1145/3478536 [33] Zhe Jiang, Zhaoguo Wang, Haoning Lan, Chuzhe Tang, Haoran Ding, Lefeng Wang, Songyun Zou, Zhuoran Wei, Yongcun Liu, Xiang Yu, Yang Ren, Guoliang Li, and Haibo Chen. 2025. GRewriter: Practical Query Rewriting with Automatic Rule Set Expansion in GaussDB. Proc. VLDB Endow. 18, 12 (Aug. 2025), 4991–5003. https://doi.org/10.14778/3750601.3750622 [34] Michalis Kokologiannakis, Ori Lahav, Konstantinos Sagonas, and Viktor Vafeiadis. 2017. Effective stateless model checking for C/C++ concurrency. Proc. ACM Program. Lang. 2, POPL, Article 17 (Dec. 2017), 32 pages. https://doi.org/10.114 5/3158105 [35] Michalis Kokologiannakis, Azalea Raad, and Viktor Vafeiadis. 2019. Effective lock handling in stateless model checking. Proc. ACM Program. Lang. 3, OOPSLA, Article 173 (Oct. 2019), 26 pages. https://doi.org/10.1145/3360599 [36] Michalis Kokologiannakis, Azalea Raad, and Viktor Vafeiadis. 2019. Model checking for weakly consistent libraries. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation (Phoenix, AZ, USA) (PLDI 2019). Association for Computing Machinery, New York, NY, USA, 96–110. https://doi.org/10.1145/3314221.3314609 [37] Michalis Kokologiannakis and Viktor Vafeiadis. 2020. HMC: Model Checking for Hardware Memory Models. In Proceedings of the Twenty-Fifth International Conference on Architectural Support for Programming Languages and Operating Systems (Lausanne, Switzerland) (ASPLOS ’20). Association for Computing Machinery, New York, NY, USA, 1157–1171. https://doi.org/10.1145/3373376.3378480 [38] Michalis Kokologiannakis and Viktor Vafeiadis. 2021. GenMC: A Model Checker for Weak Memory Models. In Computer Aided Verification: 33rd International Conference, CAV 2021, Virtual Event, July 20–23, 2021, Proceedings, Part I. SpringerVerlag, Berlin, Heidelberg, 427–440. https://doi.org/10.1007/978-3-030-816858_20 [39] Maxwell Levatich, Nikolaj Bjørner, Ruzica Piskac, and Sharon Shoham. 2020. Solving LIA* Using Approximations. In International Conference on Verification, Model Checking, and Abstract Interpretation. Springer, 360–378. [40] Boyan Li, Yuyu Luo, Chengliang Chai, Guoliang Li, and Nan Tang. 2024. The Dawn of Natural Language to SQL: Are We Fully Ready? Proc. VLDB Endow. 17, 11 (July 2024), 3318–3331. https://doi.org/10.14778/3681954.3682003 [41] Haoyang Li, Jing Zhang, Cuiping Li, and Hong Chen. 2023. RESDSQL: decoupling schema linking and skeleton parsing for text-to-SQL. In Proceedings of the ThirtySeventh AAAI Conference on Artificial Intelligence and Thirty-Fifth Conference on Innovative Applications of Artificial Intelligence and Thirteenth Symposium on Educational Advances in Artificial Intelligence (AAAI’23/IAAI’23/EAAI’23). AAAI Press, Article 1466, 9 pages. https://doi.org/10.1609/aaai.v37i11.26535 [42] Jie Liu and Barzan Mozafari. 2024. Query Rewriting via Large Language Models. arXiv:arXiv: [43] Jie Liu and Barzan Mozafari. 2026. GenRewrite: Query Rewriting via Large Language Models. Proc. ACM Manag. Data 4, 1, Article 70 (April 2026), 26 pages.

https://doi.org/10.1145/3786684 [44] Qiuyang Mang, Runyuan He, Suyang Zhong, Xiaoxuan Liu, Huanchen Zhang, and Alvin Cheung. 2025. Automated Discovery of Test Oracles for Database Management Systems Using LLMs. arXiv:arXiv: [45] MySQL. 2024. Sorting Rows. https://dev.mysql.com/doc/refman/9.5/en/sortingrows.html. [46] Kartik Nagar, Prasita Mukherjee, and Suresh Jagannathan. 2020. Semantics, Specification, and Bounded Verification of Concurrent Libraries in Replicated Systems. In Computer Aided Verification: 32nd International Conference, CAV 2020, Los Angeles, CA, USA, July 21–24, 2020, Proceedings, Part I (Los Angeles, CA, USA). Springer-Verlag, Berlin, Heidelberg, 251–274. https://doi.org/10.1007/9783-030-53288-8_13 [47] Jonas Oberhauser, Rafael Lourenco de Lima Chehab, Diogo Behrens, Ming Fu, Antonio Paolillo, Lilith Oberhauser, Koustubha Bhat, Yuzhong Wen, Haibo Chen, Jaeho Kim, and Viktor Vafeiadis. 2021. VSync: push-button verification and optimization for synchronization primitives on weak memory models. In Proceedings of the 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems (Virtual, USA) (ASPLOS ’21). Association for Computing Machinery, New York, NY, USA, 530–545. https://doi.org/10.1145/3445814.3446748 [48] Mohammadreza Pourreza and Davood Rafiei. 2023. DIN-SQL: decomposed incontext learning of text-to-SQL with self-correction. In Proceedings of the 37th International Conference on Neural Information Processing Systems (New Orleans, LA, USA) (NIPS ’23). Curran Associates Inc., Red Hook, NY, USA, Article 1577, 10 pages. [49] Tobias Schuele and Klaus Schneider. 2007. Bounded model checking of infinite state systems. Form. Methods Syst. Des. 30, 1 (Feb. 2007), 51–81. https://doi.org/ 10.1007/s10703-006-0019-9 [50] Snowflake. 2026. Snowflake. https://docs.snowflake.com/en/sql-reference/ constructs/order-by. [51] Chenglong Wang, Alvin Cheung, and Rastislav Bodik. 2017. Interactive Query Synthesis from Input-Output Examples. In Proceedings of the 2017 ACM International Conference on Management of Data (Chicago, Illinois, USA) (SIGMOD ’17). Association for Computing Machinery, New York, NY, USA, 1631–1634. https://doi.org/10.1145/3035918.3058738 [52] Chenglong Wang, Alvin Cheung, and Rastislav Bodik. 2017. Synthesizing highly expressive SQL queries from input-output examples. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation (Barcelona, Spain) (PLDI 2017). Association for Computing Machinery, New York, NY, USA, 452–466. https://doi.org/10.1145/3062341.3062365 [53] Chenglong Wang, Alvin Cheung, and Rastislav Bodik. 2018. Speeding up symbolic reasoning for relational queries. Proc. ACM Program. Lang. 2, OOPSLA, Article 157 (Oct. 2018), 25 pages. https://doi.org/10.1145/3276527 [54] Shuxian Wang, Sicheng Pan, and Alvin Cheung. 2024. QED: A powerful query equivalence decider for SQL. Proceedings of the VLDB Endowment 17, 11 (2024), 3602–3614. [55] Zhaoguo Wang, Zhou Zhou, Yicun Yang, Haoran Ding, Gansen Hu, Ding Ding, Chuzhe Tang, Haibo Chen, and Jinyang Li. 2022. WeTune: Automatic Discovery and Verification of Query Rewrite Rules. In Proceedings of the 2022 International Conference on Management of Data (Philadelphia, PA, USA) (SIGMOD ’22). Association for Computing Machinery, New York, NY, USA, 94–107. https://doi.org/10.1145/3514221.3526125 [56] Yale-LILY. 2018. Spider: Yale Semantic Parsing and Text-to-SQL Challenge. https://yale-lily.github.io/spider. [57] Yicun Yang, Zhaoguo Wang, Yu Xia, Zhuoran Wei, Haoran Ding, Ruzica Piskac, Haibo Chen, and Jinyang Li. 2025. Automated Validating and Fixing of Textto-SQL Translation with Execution Consistency. Proc. ACM Manag. Data 3, 3, Article 134 (June 2025), 28 pages. https://doi.org/10.1145/3725271 [58] Tao Yu, Rui Zhang, Kai Yang, Michihiro Yasunaga, Dongxu Wang, Zifan Li, James Ma, Irene Li, Qingning Yao, Shanelle Roman, Zilin Zhang, and Dragomir Radev. 2018. Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, Ellen Riloff, David Chiang, Julia Hockenmaier, and Jun’ichi Tsujii (Eds.). Association for Computational Linguistics, Brussels, Belgium, 3911–3921. https://doi.org/10.186 53/v1/D18-1425 [59] Guoqiang Zhang, Yuanchao Xu, Xipeng Shen, and Işıl Dillig. 2021. UDF to SQL translation through compositional lazy inductive synthesis. Proc. ACM Program. Lang. 5, OOPSLA, Article 112 (Oct. 2021), 26 pages. https://doi.org/10.1145/3485 489 [60] Pinhan Zhao, Yuepeng Wang, and Xinyu Wang. 2025. Polygon: Symbolic Reasoning for SQL using Conflict-Driven Under-Approximation Search. Proc. ACM Program. Lang. 9, PLDI, Article 200 (June 2025), 26 pages. [61] Qi Zhou, Joy Arulraj, Shamkant Navathe, William Harris, and Dong Xu. 2019. Automated Verification of Query Equivalence Using Satisfiability modulo Theories. Proc. VLDB Endow. 12, 11 (jul 2019), 1276–1288. https://doi.org/10.14778/3 342263.3342267

[62] Qi Zhou, Joy Arulraj, Shamkant B. Navathe, William Harris, and Jinpeng Wu. 2022. SPES: A Symbolic Approach to Proving Query Equivalence Under Bag Semantics. In 2022 IEEE 38th International Conference on Data Engineering (ICDE). 2735–2748. https://doi.org/10.1109/ICDE53745.2022.00250 [63] Yi Zhou, Jay Bosamiya, Yoshiki Takashima, Jessica Li, Marijn Heule, and Bryan Parno. 2023. Mariposa: Measuring SMT Instability in Automated Program Verification. In 2023 Formal Methods in Computer-Aided Design (FMCAD). 178–188. https://doi.org/10.34727/2023/isbn.978-3-85448-060-0_26

Related documents

Record · ID 1767926 · SHA-256 45a6796f0c8d7f8b
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
Bring this data into your agent: Connect via MCP or API · 20 free credits to start · no card required
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive