Prefix-to-SQL: Text-to-SQL Generation from Incomplete User Questions

Naihao Deng, Shuaichen Chang, Peng Shi, Tao Yu, Rui ZhangarXiv 2021

Abstract

This paper introduces Prefix-to-SQL, a novel task aimed at predicting executable SQL queries from incomplete natural language question fragments. To support this research, the authors present PAGSAS, a large-scale benchmark containing 124,000 examples derived from five popular Text-to-SQL datasets. The study evaluates various generative and retrieval-based models, identifying that task difficulty is primarily driven by the number of omitted tokens rather than SQL complexity. Experimental results demonstrate that while the task is significantly harder than standard Text-to-SQL, performance can be boosted by up to 9% using curriculum learning. However, generalizing to unseen SQL structures remains a significant challenge for current architectures.

Introduction

Standard Text-to-SQL systems are designed to translate complete natural language sentences into executable SQL queries. However, in real-world scenarios, users often struggle to formulate precise, complex questions for databases. They may start typing and get stuck or desire a more interactive experience similar to search engine auto-suggestions.

Overview of the Prefix-to-SQL task workflow, showing the transition from a question prefix to suggested SQL queries and their natural language equivalents.

The authors identify a critical gap in current Natural Language Interfaces to Databases (NLIDB): they do not assist the user during the formulation process. By treating Text-to-SQL as a prefix-completion task, developers can build systems that suggest possible SQL queries and their natural language equivalents as the user types, effectively providing "IntelliSense" for database querying.

Methodology

The researchers framed Prefix-to-SQL as both a generation and a retrieval problem, evaluating several architectures:

  • Generative Models: The study utilized T5 (a pre-trained Transformer) and various Seq2Seq models employing Bi-LSTMs with attention and copy mechanisms.
  • Retrieval Models: RoBERTa was used to create embeddings for question prefixes and historical SQL queries, ranking the most likely matches.
  • Two-Stage Models (QAC-S2S): This approach first uses GPT-2 to predict the completion of the question, which is then passed to a standard Text-to-SQL model.

A key methodological innovation is the application of Curriculum Learning. The authors observed that task difficulty is directly tied to the number of "omitted tokens." They trained the T5 model by starting with "easy" examples (prefixes missing only a few words) and gradually introducing "harder" ones (shorter prefixes missing many words).

The PAGSAS Benchmark

The authors introduced PAGSAS, a benchmark constructed by generating prefixes for every question in five well-known datasets: Advising, GeoQuery, Scholar, ATIS, and Spider. Models were evaluated on two types of data splits:

  1. Question Split: Randomly splitting questions, where the model might see a known SQL template with a new prefix.
  2. SQL Query Split: Splitting by SQL template, requiring the model to generalize to entirely unseen SQL structures.

Results and Analysis

The study revealed several key insights into the nature of prefix-to-SQL generation:

  • Omission as a Hardness Factor: Unlike standard Text-to-SQL, where query length determines difficulty, Prefix-to-SQL difficulty is defined by the number of omitted tokens. As shown in performance metrics, recall improves significantly as the user provides more tokens in the prefix.
  • Retrieval vs. Generation: Retrieval models are effective when the user's intent matches seen patterns (Question Split), sometimes outperforming T5. However, they fail when the intent requires a new SQL structure.
  • Curriculum Learning Boost: Adding curriculum learning (T5+CL) significantly improved performance. On the GeoQuery sub-task, it improved RECALL by 9% and the SAVE score (a metric for typing effort saved) by 3.9%.
Recall@5 performance across different datasets as a function of the number of tokens provided in the question prefix.

Conclusion and Future Work

While Prefix-to-SQL offers a promising path toward more interactive database interfaces, the "SQL Query Split" remains incredibly difficult. Most models saw their scores drop to near zero when forced to predict unseen SQL templates, highlighting that zero-shot prefix completion is still an open challenge.

Future work may involve using more sophisticated SQL-to-Text models to make suggestions feel more natural and improving the model's ability to imagine complex, novel logic from minimal input. There remains significant room for improvement before these systems can perfectly anticipate user intent from the earliest stages of typing.

Summary updated

BibTeX
@misc{deng2021prefix,
  author = {Naihao Deng and Shuaichen Chang and Peng Shi and Tao Yu and Rui Zhang},
  title = {{Prefix-to-SQL: Text-to-SQL Generation from Incomplete User Questions}},
  year = {2021},
  eprint = {2109.13066},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.13066},
}
Figure