Introduction
State-of-the-art Text-to-SQL models, designed to convert natural language questions into executable database queries, typically rely on including the entire database schema within the model's prompt. While this approach is effective for academic benchmarks like SPIDER—where schemas average approximately 30 columns—it fails in the context of real-world enterprise data warehouses. These production environments often contain tens of thousands of columns across thousands of tables, far exceeding the context window limits of modern Large Language Models (LLMs).
Even when context windows allow for large schemas, the presence of "distractor" columns—irrelevant metadata that happens to share keywords with the user query—significantly degrades model performance. Traditional retrieval methods, such as Dense Passage Retrieval (DPR), often struggle in this domain because they treat schema elements as independent documents. This leads to the retrieval of fragmented, unjoinable components or the selection of generic columns (like ID or Name) that appear frequently but lack specific semantic utility. CRUSH4SQL addresses this "needle in a haystack" problem by leveraging LLM hallucination as a structured retrieval mechanism.
The CRUSH4SQL Framework
CRUSH (Collective Retrieval Using Schema Hallucination) introduces a two-stage process that transforms the user's natural language intent into a cohesive subset of the actual database schema.
1. LLM-based Query Transformation (Hallucination)
Rather than searching the database using the raw user question, CRUSH first asks an LLM to "hallucinate" a hypothetical, minimal schema (tables and columns) that would be sufficient to answer the question. In this context, hallucination is treated as a feature rather than a flaw. The LLM uses its internal world knowledge to bridge semantic gaps; for example, if a user asks about "Cameroon," the LLM can hallucinate a Country column, even if that specific term does not appear in the original question. This hallucinated schema serves as a semantic "sketch" or bridge to the real database.
2. Collective Retrieval
The system uses the hallucinated elements as probes to identify candidates within the real database. Unlike standard retrieval, which simply selects the top-K matches, CRUSH solves a combinatorial optimization problem to select a subset of the real schema that maximizes three key metrics:
- Coverage: Ensuring that every component of the hallucinated schema has a corresponding representation in the retrieved set.
- Entropy-guided Similarity: Using an entropy-based scoring system (similar to TF-IDF) to dampen the influence of generic, high-frequency column names that often act as distractors.
- Connectivity: Rewarding the selection of tables and columns that are physically linked via foreign keys. This ensures that the retrieved schema subset is "joinable" and logically consistent for SQL generation.
Experimental Setup and Datasets
To evaluate retrieval at scale, the authors introduced three new benchmarks:
- SpiderUnion: A semi-synthetic dataset combining 166 schemas from the SPIDER benchmark, totaling 4,502 columns.
- BirdUnion: A combination derived from the BIRD benchmark, totaling 798 columns.
- SocialDB: A real-world benchmark sourced from a production data warehouse containing 17,844 columns across 1,046 tables, characterized by complex lexical gaps and overlapping naming conventions.
Key Results and Insights
CRUSH4SQL demonstrated significant improvements over standard retrieval baselines across all benchmarks. On the massive SocialDB dataset, CRUSH achieved a recall of 58% for gold tables at a budget of 10 elements, compared to 49% for the best OpenAI-based DPR baseline. On SpiderUnion, the use of the CRUSH-retrieved schema led to a jump in "Execution Match" accuracy from 0.53 to 0.60 (at a budget of 10 elements).
One of the most critical findings of the research is the "Distraction Sweet Spot." The authors discovered that while higher retrieval recall generally improves performance, providing too much schema information (a budget exceeding 30 elements) actually decreases final SQL generation accuracy. This suggests that LLMs are highly sensitive to metadata noise, reinforcing the need for precise, minimal retrieval methods like CRUSH.
Conclusion and Future Work
CRUSH4SQL demonstrates that LLM hallucination can be a powerful tool for structured data retrieval when properly constrained. By moving from element-based retrieval to collective, set-based retrieval, the system effectively handles the scale of enterprise data warehouses.
Future work aims to address current limitations, such as "unguided hallucination," where the LLM imagines a schema without any knowledge of the actual database structure. Providing a compressed summary of the real schema during the hallucination phase could further improve accuracy. Additionally, the researchers plan to explore learning the weights for connectivity and similarity scores from data, rather than relying on manual tuning.
Summary updated