Skip to main content
QUICK REVIEW

[Paper Review] Testing Database Engines via Pivoted Query Synthesis

Manuel Rigger, Zhendong Su|arXiv (Cornell University)|Jan 13, 2020
Software Testing and Debugging TechniquesComputer Science25 references28 citations
TL;DR

This paper proposes a novel, general approach called SQLancer that detects logic bugs in database management systems (DBMS) by synthesizing queries designed to retrieve a specific, randomly selected 'pivot row'. By ensuring the query must include this row in its result set, the method acts as a containment oracle; if the DBMS fails to return the pivot row, a logic bug is triggered. The approach discovered 123 bugs across SQLite, MySQL, and PostgreSQL, 99 of which were fixed or verified, demonstrating high effectiveness and broad applicability.

ABSTRACT

Relational databases are used ubiquitously. They are managed by database management systems (DBMS), which allow inserting, modifying, and querying data using a domain-specific language called Structured Query Language (SQL). Popular DBMS have been extensively tested by fuzzers, which have been successful in finding crash bugs. However, approaches to finding logic bugs, such as when a DBMS computes an incorrect result set, have remained mostly untackled. Differential testing is an effective technique to test systems that support a common language by comparing the outputs of these systems. However, this technique is ineffective for DBMS, because each DBMS typically supports its own SQL dialect. To this end, we devised a novel and general approach that we have termed Pivoted Query Synthesis. The core idea of this approach is to automatically generate queries for which we ensure that they fetch a specific, randomly selected row, called the pivot row. If the DBMS fails to fetch the pivot row, the likely cause is a bug in the DBMS. We tested our approach on three widely-used and mature DBMS, namely SQLite, MySQL, and PostgreSQL. In total, we reported 123 bugs in these DBMS, 99 of which have been fixed or verified, demonstrating that the approach is highly effective and general. We expect that the wide applicability and simplicity of our approach will enable the improvement of robustness of many DBMS.

Motivation & Objective

  • To address the challenge of detecting logic bugs in DBMS that do not cause crashes but return incorrect results.
  • To overcome the limitations of differential testing, which fails when DBMS support different SQL dialects and semantics.
  • To design a lightweight, general-purpose testing oracle that ensures a specific row is included in query results.
  • To enable automated, scalable detection of previously undetected logic bugs in mature, widely-used DBMS.
  • To provide a practical and extensible framework for improving DBMS robustness through targeted query synthesis.

Proposed method

  • The method generates SQL queries that are guaranteed to include a randomly selected 'pivot row' by constructing WHERE and JOIN clauses that evaluate to TRUE when applied to the pivot row.
  • It uses a constraint-based synthesis technique to dynamically modify expressions so that they evaluate to TRUE for the pivot row, ensuring the row must be in the result set.
  • The approach employs a containment oracle: if the DBMS fails to return the pivot row, a logic bug is detected.
  • The method is implemented in a tool called SQLancer, which supports multiple DBMS by adapting to their specific SQL dialects and features.
  • It leverages random query generation enhanced with semantic constraints to ensure correctness of the oracle without requiring shared semantics across systems.
  • The approach is complemented by techniques to trigger internal errors (e.g., corruption, crashes) and detect them via side effects.

Experimental results

Research questions

  • RQ1Can a general-purpose, lightweight oracle be designed to detect logic bugs in DBMS without relying on differential testing?
  • RQ2Can pivot-row query synthesis effectively uncover logic bugs that are undetected by existing fuzzing and random query generation techniques?
  • RQ3To what extent can this approach scale across diverse, mature DBMS with divergent SQL dialects and features?
  • RQ4How effective is the containment oracle in detecting previously unknown logic bugs in production-grade DBMS?
  • RQ5Can the approach be extended to detect bugs in complex SQL constructs such as aggregates and set operations?

Key findings

  • The approach discovered 123 bugs in three widely used DBMS: 65 in SQLite, 25 in MySQL, and 9 in PostgreSQL.
  • Of these, 99 bugs were confirmed or fixed by developers, including 61 detected via the containment oracle and 34 via internal errors such as database corruption.
  • One MySQL crash was classified as a security vulnerability (CVE-2019-2879).
  • The method successfully detected a critical logic bug in SQLite that had existed since 2013 and was previously undetected by existing tools.
  • The approach is effective even for DBMS-specific features, such as SQLite’s dynamic typing and partial indexes, which are not supported by other DBMS.
  • The simplicity and generality of the approach enable broad applicability across DBMS without requiring shared semantics or complex oracles.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.