Abstract
It is challenging to convert natural language (NL) questions into executable structured query language (SQL) queries for text-to-SQL tasks due to the vast number of database schemas with redundancy, which interferes with semantic learning, and the domain shift between NL and SQL. Existing works for schema linking focus on the table level and perform it once, ignoring the multi-granularity semantics and chainable cyclicity of schemas. In this paper, we propose a progressive schema linking with multi-granularity semantics (PSM-SQL) framework to reduce the redundant database schemas for text-to-SQL. Using the multi-granularity schema linking (MSL) module, PSM-SQL learns the schema semantics at the column, table, and database levels. More specifically, a triplet loss is used at the column level to learn embeddings, while fine-tuning LLMs is employed at the database level for schema reasoning. MSL employs classifier and similarity scores to model schema interactions for schema linking at the table level. In particular, PSM-SQL adopts a chain loop strategy to reduce the task difficulty of schema linking by continuously reducing the number of redundant schemas. Experiments conducted on text-to-SQL datasets show that the proposed PSM-SQL is 1-3 percentage points higher than the existing methods.
Introduction
The core challenge in Text-to-SQL is "schema linking"—the precise identification of relevant database components from a natural language question. Real-world databases often contain hundreds of tables and columns with redundant or ambiguous names, creating significant noise. Most existing methods attempt schema linking in a single pass or focus on a single level of granularity (e.g., just tables). This often leaves excessive irrelevant schemas in the prompt, interfering with a Large Language Model's (LLM) reasoning capabilities and exacerbating the "domain shift" between human speech and rigid database structures.
PSM-SQL addresses these issues by iteratively filtering out irrelevant database components before query generation. By combining multi-level semantic analysis with a cyclic refinement loop, it significantly reduces noise and boosts accuracy on complex benchmarks.
The PSM-SQL Framework
The framework is built upon two primary innovations: Multi-granularity Schema Linking (MSL) and a Progressive Chain Loop Strategy.
Multi-granularity Schema Linking (MSL)
Instead of treating the database as a monolith, MSL analyzes it at three distinct levels to capture comprehensive semantic signals:
- Column Level: Employs a triplet loss to fine-tune embedding models, training the system to pull relevant columns closer to the question's vector space while pushing irrelevant ones away.
- Table Level: Uses a cross-encoder (based on RoBERTa and LSTMs) and a Disentangled Network (DN). The DN filters out linguistic noise (e.g., stop words) to focus on semantic links between the question and table names.
- Database Level: Fine-tunes an LLM (such as Llama3-8B) using Low-Rank Adaptation (LoRA) to perform high-level reasoning over the entire schema, identifying the necessary components for the final query.
Chain Loop Strategy
This "progressive" component runs the MSL module in cycles. Each iteration discards redundant schemas, progressively shrinking the search space. This iterative pruning makes the final generation task significantly easier for the LLM by providing a cleaner, more relevant context.
Experimental Evaluation
PSM-SQL was evaluated on two major benchmarks: Spider (cross-domain) and Bird (large-scale, complex databases requiring external knowledge).
Performance on Bird
On the challenging Bird development set, PSM-SQL paired with Llama3-70B achieved state-of-the-art results, reaching an Execution Accuracy (EX) of 65.06% and a Valid Efficiency Score (VES) of 67.87%. These results outperform other competitive models like CHESS and MAC-SQL.
Performance on Spider
On the Spider dataset, the framework achieved an EX of 88.6% and an Exact Match (EM) score of 82.2%, demonstrating its robustness across different database scales and domains.
Key Insights and Limitations
- Iterative Refinement: Ablation studies confirm that moving from "Cycle 1" to "Cycle 2" significantly reduces the Redundancy (RE) metric (often from ~72% down to ~25%) without sacrificing the inclusion of correct schemas.
- Semantic Disentanglement: The Disentangled Network is crucial for overcoming domain shift by separating SQL-relevant tokens from general natural language.
- Granularity Synergy: Column-level embeddings provide fine-grained matching, while database-level reasoning captures the "big picture" logic, creating a complementary effect.
Limitations: The primary risk of the progressive approach is the "Upper Limit" problem: if a correct table is discarded in an early cycle, the model cannot recover it. Additionally, the multi-cycle process increases computational latency compared to single-pass methods.
Summary updated