arXiv:2608.30385cs.DBAug 2026

Manuscript Offprint

arXiv:2608.30385

Detecting DBMS Bugs by Constructing Equivalent Representations of Intermediate Query Results

Xiaoxu Niu, Gong Chen, Jinfu Chen, Xiaoyuan Xie

Xiaoxu Niu ∗^{*}

Wuhan University

School of Computer Science

Wuhan, China

xiaoxuniu@whu.edu.cn

Jinfu Chen

Wuhan University

School of Computer Science

Wuhan, China

jinfuchen@whu.edu.cn

Gong Chen ∗^{*}

Wuhan University

School of Computer Science

Wuhan, China

chengongcg@whu.edu.cn

Abstract

Database Management Systems (DBMSs) support multiple SQL mechanisms for representing intermediate query results, including VIEWs, Common Table Expressions (CTEs), and Temporary Tables (TEMPTs). When these mechanisms are used to represent the same intermediate query result, the corresponding queries are expected to produce consistent results. However, we observe that such queries can return inconsistent results, indicating potential DBMS logic bugs. Existing approaches for detecting DBMS logic bugs have never explored result consistency across such equivalent representations.

In this paper, we propose ERIQ, a novel testing approach for detecting DBMS logic bugs from the perspective of checking result consistency across Equivalent Representations of Intermediate Query Results. ERIQ constructs SQL variants using a VIEW, a CTE, or a TEMPT to represent the same intermediate query result, executes these variants, and compares their returned results. We evaluated ERIQ on four widely used open-source DBMSs: MySQL, MariaDB, Percona, and OceanBase. In total, ERIQ detected 64 bugs, 63 of which were confirmed by developers, and two have been fixed. Among the confirmed bugs, 54 were unique and previously unknown logic bugs, and one was a documentation issue.

Xiaoyuan Xie †^{\dagger}

Wuhan University

School of Computer Science

Wuhan, China

xxie@whu.edu.cn

1 Introduction

Database Management Systems (DBMSs) provide various SQL mechanisms for representing intermediate query results, including VIEWs, Common Table Expressions (CTEs), and Temporary Tables (TEMPTs) [9, 19, 20, 25]. These mechanisms are widely used in database applications to simplify the construction of complex queries and improve query readability: VIEWs define reusable named queries, CTEs provide temporary result sets that can be referenced within a single statement, and TEMPTs store query results in temporary tables that can be reused by subsequent statements [19, 20, 25]. When different mechanisms are used to represent the same intermediate query result, the corresponding queries are expected to produce consistent results. However, we observe that such queries can return inconsistent results, as illustrated in Section 2.2. Such inconsistencies can indicate potential DBMS bugs, which may be exposed when the corresponding queries are processed through different paths within the DBMS.

Many approaches have been proposed for detecting DBMS logic bugs. However, to the best of our knowledge, they have never explored the perspective of detecting such bugs by checking result consistency across equivalent representations of intermediate query results. For example, NoREC [29] compares the results of optimized and unoptimized queries; TLP [30] partitions queries based on ternary logic; PQS [31] checks whether a selected pivot row appears in the result of a generated query; Pinolo [8] checks result containment between synthesized queries and a seed query; EET [11] and CODDTest [42] apply equivalent transformations at the expression level; Radar [34] compares query results across databases with the same data but different metadata; and EDC [4] checks query consistency using precomputed results of data operation expressions.

In this paper, we propose ERIQ, a novel testing approach for detecting DBMS logic bugs from the perspective of checking result consistency across Equivalent Representations of Intermediate Query Results. ERIQ constructs corresponding SQL variants that use a VIEW, a CTE, or a TEMPT to represent the same intermediate query result, executes these variants, and compares their returned results. If the results are inconsistent, ERIQ reports the inconsistency as a bug.

We implemented ERIQ and evaluated it on four widely used open-source DBMSs: MySQL, MariaDB, Percona, and OceanBase. In total, ERIQ detected 64 bugs, including 29 in MySQL, 18 in MariaDB, 13 in Percona, and 4 in OceanBase. Developers confirmed 63 of them, including 54 unique and previously unknown logic bugs, 8 duplicates of other bugs reported by ERIQ, and one documentation issue. Among the 54 unique logic bugs, two have been fixed. We further compared ERIQ with four state-of-the-art DBMS logic bug detection approaches: EDC [4], Radar [34], EET [11], and TLP [30]. Among these 54 unique logic bugs, the best-performing existing approach could detect only 9 of them, showing that ERIQ detects many bugs missed by each existing approach and thus provides complementary bug detection capability. Under the 24-hour testing

∗^{*}These authors have contributed equally to this work.

†^{\dagger}Corresponding author.

budget on each supported DBMS, ERIQ detected 54 logic bugs, compared with 16 detected by the best-performing existing approach, demonstrating its stronger bug detection capability.

This paper makes the following contributions:

  • We introduce a new perspective for detecting DBMS logic bugs by checking result consistency across equivalent representations of intermediate query results, which has never been explored by existing methods.

  • Based on this new perspective, we propose and implement ERIQ, a novel testing approach that constructs SQL variants using a VIEW, a CTE, or a TEMPT to represent the same intermediate query result and detects DBMS logic bugs by checking result consistency across these variants.

  • We conduct a comprehensive experimental study of ERIQ on four widely used open-source DBMSs, detecting 54 unique and previously unknown logic bugs and demonstrating that ERIQ complements existing approaches.

The rest of this paper is organized as follows. Section 2 introduces the background and motivation. Section 3 describes the proposed approach. Section 4 presents the experimental evaluation. Section 5 discusses false positive mitigation, a documentation issue, and limitations. Section 6 reviews related work. Finally, Section 7 concludes the paper.

References (16)