Constructing Expressive Relational Queries with Dual-Specification Synthesis

Christopher Baik, Zhongjun Jin, Michael J. Cafarella, H. V. Jagadish

Introduction

Querying relational databases remains a significant challenge for non-expert users. Existing solutions typically fall into two categories: Natural Language Interfaces (NLIs), which are intuitive but often ambiguous, and Programming-by-Example (PBE) systems, which are precise but struggle with the vast search space of complex SQL queries. This paper introduces Duoquest, a system that addresses this "missing middle" by leveraging dual-specification synthesis. By combining natural language queries (NLQ) with lightweight "table sketches" (TSQ), Duoquest guides the search for the correct SQL statement while pruning incorrect candidates early in the process.

System Architecture

The Duoquest architecture consists of two primary components: a Synthesizer and a Verifier, working in a feedback loop to generate valid SQL queries from user specifications.

Figure 1: The Duoquest system architecture illustrates the interaction between the user, synthesizer, and verifier.

Dual-Specification Input

Users provide an NLQ (e.g., "show me movies from 1995") and an optional Table Sketch Query (TSQ). A TSQ allows users to provide partial examples of the expected output without requiring knowledge of the underlying database schema. For instance, a user might specify that "Tom Hanks" should appear in a column of type string.

Guided Partial Query Enumeration (GPQE)

The Synthesizer, based on a modified neural network architecture, translates the NLQ into Partial Queries (PQs)—SQL statements containing placeholders. The Verifier then evaluates these PQs against the TSQ. Crucially, the Verifier uses "over-approximation" rules to determine if a partial query can ever satisfy the user's examples. If a PQ is deemed impossible to fulfill the TSQ, the Verifier provides feedback to the Synthesizer to prune that entire branch of the search space immediately. This early pruning is essential for handling complex queries involving joins and aggregations.

Experimental Evaluation

Duoquest was evaluated using the Spider benchmark, a challenging cross-domain text-to-SQL dataset. The evaluation focused on Select-Project-Join-Aggregate (SPJA) queries, comprising 589 development tasks and 1,247 test tasks.

Figure 2: Performance comparison of Duoquest (DQ) against NLI-only, PBE-only, and Chain approaches in terms of top-10 accuracy and task completion time.

Key Results

As shown in Figure 2, Duoquest (DQ) significantly outperforms baseline systems:

  • Accuracy: Duoquest achieved a top-10 accuracy of 83.7% on the development set, compared to 56.7% for NLI-only and 34.0% for PBE-only systems.
  • Efficiency: By pruning the search space during synthesis rather than after (as in the "Chain" approach), Duoquest finds correct queries much faster. It completed a higher percentage of tasks within a 60-second time limit than all other methods, demonstrating the effectiveness of the GPQE technique.

Conclusion

Duoquest demonstrates that combining natural language with example-based specifications can effectively bridge the gap between user intent and complex database queries. By integrating a verifier that prunes partial queries, the system achieves high accuracy and efficiency on complex benchmarks. Future work will focus on expanding the query scope beyond SPJA and conducting user studies to evaluate the ease of constructing table sketches in real-world scenarios.

Summary updated

BibTeX
@inproceedings{baik2020constructing,
  author = {Christopher Baik and Zhongjun Jin and Michael J. Cafarella and H. V. Jagadish},
  title = {{Constructing Expressive Relational Queries with Dual-Specification Synthesis}},
  booktitle = {Cidr},
  year = {2020},
}
Figure