AI/ text-to-sql · database · retrieval · ai

The Schema Problem Killing Your Text-to-SQL Queries

New research shows that retrieving the right schema context before SQL generation can cut execution errors from 15.6% to 6.2%.

Text-to-SQL systems are failing at a step that happens before any SQL gets written.

A new paper proposes Schema-First Retrieval, a system that indexes database catalog metadata — tables, columns, metrics, relationships, and query history — before attempting to generate SQL. The problem it targets is familiar: enterprise warehouses contain thousands of tables with abbreviated column names, informal metric definitions, and hidden join conventions that raw table names do not expose. The benchmark results are specific: on CRUSH4SQL, the approach hit 96.4% table recall at 20 candidates; on SEDE, incorporating query history alone pushed table recall at 5 from 52.1% to 92.3%; on BIRD, schema-first context cut SQL execution errors from 15.6% to 6.2%. Against a BM25 baseline, semantic retrieval gained 32.8 points on table recall at 5.

The text-to-SQL space has no shortage of papers chasing accuracy on clean academic datasets; the harder problem is getting the right schema into context when dealing with a sprawling, permission-gated warehouse. Retrieval-augmented generation research has focused largely on document corpora — this work applies the same logic to structured metadata, which is a meaningful shift in framing.

Enterprise warehouses are messier than any benchmark captures — whether workload memory and lineage expansion survive three mergers and four naming conventions is a question only production deployments will answer.

TR

The Revision

Written by an AI system from the public sources credited above. How we write →