Abstract
Translating users' natural language queries (NL) into SQL queries (i.e., NL2SQL) can significantly reduce barriers to accessing relational databases. The performance of NL2SQL has been greatly enhanced with the emergence of Large Language Models (LLMs). This survey provides a comprehensive review of NL2SQL techniques powered by LLMs, covering its entire lifecycle: (1) Model translation techniques; (2) Data collection and synthesis; (3) Multi-angle evaluation; and (4) Error analysis. We discuss research challenges and open problems in the LLM era.
Introduction: The Challenge of Democratizing Data
Relational databases are the backbone of modern information systems, yet accessing them remains gated behind the technical requirement of SQL proficiency. Text-to-SQL (NL2SQL) aims to democratize data access by allowing users to query databases using natural language. However, this task faces significant hurdles: natural language ambiguity, extreme schema complexity in real-world databases, and the "mapping gap" between free-form intent and formal SQL constraints.
The Evolution of Text-to-SQL Solutions
The field has transitioned through several distinct eras, moving from rigid rule-based systems to the flexible, emergent capabilities of Large Language Models.
As shown in the evolution timeline, the complexity of challenges has scaled from simple single-table queries to real-world databases requiring multi-turn dialogues and domain-specific knowledge. While early statistical and neural models required expert intervention, the LLM era has opened the door for novice users, albeit with new requirements for advanced SQL feature support and efficient generation.
The NL2SQL Lifecycle: A Modular Framework
Modern NL2SQL research is best understood through a modular lifecycle that spans from model development to rigorous error analysis.
1. Modeling and Pipeline
The translation process typically follows a three-stage pipeline:
- Pre-Processing: Focuses on schema linking and database content retrieval. In the LLM era, Schema Pruning is critical to fit complex database structures into limited context windows.
- Translation: The core engine. This involves either In-Context Learning (prompt engineering with models like GPT-4) or Fine-tuning specialized models (e.g., CodeS). Advanced decoding strategies like PICARD help enforce SQL grammar during generation.
- Post-Processing: Refines output through execution-guided correction and self-consistency checks.
2. Data and Benchmarks
Benchmarks have evolved from simple sets like WikiSQL to complex, cross-domain standards like Spider. Newer datasets like BIRD emphasize execution efficiency, while AmbiQT targets the resolution of natural language ambiguity.
3. Evaluation and Error Analysis
Evaluation has moved beyond simple execution accuracy to include metrics like the Valid Efficiency Score (VES). Detailed error analysis reveals that the majority of failures occur in SELECT (25.5%) and GROUP BY (16.6%) clauses, often stemming from a failure in "Database Grounding"—understanding the specific quirks of an unfamiliar schema.
Key Insights and Results
- The Bottleneck Shift: LLMs excel at language understanding but struggle with grounding queries in specific, massive database schemas.
- Efficiency Trade-offs: LLM-based methods (e.g., DIN-SQL) can be significantly more accurate but suffer from 5x higher latency and 10x higher token consumption compared to optimized Pre-trained Language Models (PLMs).
- Performance Gap: While accuracy on standard benchmarks is high (~80%), it drops precipitously to ~50% for "Extra Hard" cases involving nested queries and complex joins.
Future Directions
The survey identifies several frontiers:
- Open-Domain NL2SQL: Querying across multiple, heterogeneous data sources.
- Cost-Effective Routing: Using small models for simple queries and escalating to LLMs only when necessary.
- Trustworthiness: Developing explainable AI tools that allow non-technical users to verify the logic behind a generated SQL query.
- Adaptive Synthesis: Automatically generating training data to target specific model weaknesses.
Summary updated