Table of Contents
Fetching ...

SchemaGraphSQL: Efficient Schema Linking with Pathfinding Graph Algorithms for Text-to-SQL on Large-Scale Databases

AmirHossein Safdarian, Milad Mohammadi, Ehsan Jahanbakhsh, Mona Shahamat Naderi, Heshaam Faili

TL;DR

SchemaGraphSQL presents a zero-shot, training-free schema linking framework for Text-to-SQL on large databases by modeling schemas as undirected graphs over foreign-key relations and applying classical path-finding to generate a compact, join-grounded sub-schema. The approach relies on a single LLM call to identify coarse source/destination tables, enumerates all shortest paths between them, and uses a downstream generator to produce SQL from the selected sub-schema, achieving state-of-the-art recall on the BIRD benchmark while preserving low latency and cost. Ablations show that union of all shortest paths improves recall and end-to-end accuracy, whereas forcing longer paths degrades performance, highlighting the importance of comprehensive yet concise schema grounding. The method requires no training data, scales to real-world schemas, and offers a transparent, interpretable mechanism for schema filtering, with limitations in deeply nested queries and very dense schemas to be addressed in future work.

Abstract

Text-to-SQL systems translate natural language questions into executable SQL queries, and recent progress with large language models (LLMs) has driven substantial improvements in this task. Schema linking remains a critical component in Text-to-SQL systems, reducing prompt size for models with narrow context windows and sharpening model focus even when the entire schema fits. We present a zero-shot, training-free schema linking approach that first constructs a schema graph based on foreign key relations, then uses a single prompt to Gemini 2.5 Flash to extract source and destination tables from the user query, followed by applying classical path-finding algorithms and post-processing to identify the optimal sequence of tables and columns that should be joined, enabling the LLM to generate more accurate SQL queries. Despite being simple, cost-effective, and highly scalable, our method achieves state-of-the-art results on the BIRD benchmark, outperforming previous specialized, fine-tuned, and complex multi-step LLM-based approaches. We conduct detailed ablation studies to examine the precision-recall trade-off in our framework. Additionally, we evaluate the execution accuracy of our schema filtering method compared to other approaches across various model sizes.

SchemaGraphSQL: Efficient Schema Linking with Pathfinding Graph Algorithms for Text-to-SQL on Large-Scale Databases

TL;DR

SchemaGraphSQL presents a zero-shot, training-free schema linking framework for Text-to-SQL on large databases by modeling schemas as undirected graphs over foreign-key relations and applying classical path-finding to generate a compact, join-grounded sub-schema. The approach relies on a single LLM call to identify coarse source/destination tables, enumerates all shortest paths between them, and uses a downstream generator to produce SQL from the selected sub-schema, achieving state-of-the-art recall on the BIRD benchmark while preserving low latency and cost. Ablations show that union of all shortest paths improves recall and end-to-end accuracy, whereas forcing longer paths degrades performance, highlighting the importance of comprehensive yet concise schema grounding. The method requires no training data, scales to real-world schemas, and offers a transparent, interpretable mechanism for schema filtering, with limitations in deeply nested queries and very dense schemas to be addressed in future work.

Abstract

Text-to-SQL systems translate natural language questions into executable SQL queries, and recent progress with large language models (LLMs) has driven substantial improvements in this task. Schema linking remains a critical component in Text-to-SQL systems, reducing prompt size for models with narrow context windows and sharpening model focus even when the entire schema fits. We present a zero-shot, training-free schema linking approach that first constructs a schema graph based on foreign key relations, then uses a single prompt to Gemini 2.5 Flash to extract source and destination tables from the user query, followed by applying classical path-finding algorithms and post-processing to identify the optimal sequence of tables and columns that should be joined, enabling the LLM to generate more accurate SQL queries. Despite being simple, cost-effective, and highly scalable, our method achieves state-of-the-art results on the BIRD benchmark, outperforming previous specialized, fine-tuned, and complex multi-step LLM-based approaches. We conduct detailed ablation studies to examine the precision-recall trade-off in our framework. Additionally, we evaluate the execution accuracy of our schema filtering method compared to other approaches across various model sizes.

Paper Structure

This paper contains 34 sections, 2 equations, 1 figure, 6 tables, 1 algorithm.

Figures (1)

  • Figure 1: Overview of our graph-based schema linking pipeline.

Theorems & Definitions (2)

  • Definition 3.1: Text-to-SQL
  • Definition 3.2: Schema Linking