NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SQLformer: Deep Auto-Regressive Query Graph Generation for Text-to-SQL Translation

Adrián Bazaga, Pietro Liò, Gos MicklemarXiv 2023 · DOI

Introduction

Text-to-SQL translation aims to democratize data access by allowing non-technical users to query databases using natural language. Despite significant progress, two primary challenges persist: domain generalization across unseen database schemas and the structural complexity of SQL itself. Traditional sequence-to-sequence models often fail to capture the rigid grammar of SQL, while previous tree-based decoders relying on LSTMs suffer from slow training and limited long-range dependency modeling.

SQLformer addresses these issues by treating Text-to-SQL as an autoregressive graph generation task. By incorporating structural inductive biases—such as syntactic dependencies and database schema relationships—directly into a Transformer-based architecture, SQLformer achieves state-of-the-art performance while maintaining high efficiency.

Methodology

SQLformer departs from standard text-to-text modeling by leveraging the inherent graph structures of both natural language and relational databases.

Schema-Aware Encoding

The model represents natural language questions as graphs using syntactic dependencies and part-of-speech tags. Simultaneously, the database schema is modeled as a graph of tables, columns, and foreign key relationships. A key innovation is the introduction of learnable "table" and "column" tokens within the Transformer encoder. These tokens facilitate a selection mechanism that identifies the most relevant schema elements for a given query, significantly improving domain generalization.

The SQLformer architecture, featuring a schema-aware encoder and an autoregressive AST decoder.

Autoregressive AST Decoding

Instead of generating raw SQL text, SQLformer predicts an Abstract Syntax Tree (AST) in a canonical Breadth-First Search (BFS) order. This approach ensures the generated output adheres to SQL grammar. The decoder integrates three structural attributes for each node:

  1. Node Type: (e.g., SelectTable).
  2. Node Adjacency: How the node connects to its parent and siblings.
  3. Previous Action: The embedding of the preceding generation step.

These attributes are injected as bias terms in the multi-head attention layers, forcing the model to respect the structural constraints of the target language.

Experimental Evaluation

The researchers evaluated SQLformer on a comprehensive suite of benchmarks, primarily the Spider dataset, which is the standard for cross-domain Text-to-SQL. To test robustness, they also utilized variants like Spider-DK (Domain Knowledge), Spider-SYN (Synonyms), and Spider-Realistic.

Key Results

SQLformer established new state-of-the-art records across all major metrics. On the Spider test set, it achieved 75.6% Exact Match (EM) and 81.9% Execution (EX) accuracy, outperforming significantly larger models such as T5-3B.

Performance comparison on the Spider benchmark, showing SQLformer achieving state-of-the-art results.

Beyond raw accuracy, the model demonstrated exceptional performance on "Extra Hard" queries, showing an 8.3% improvement over the RAT-SQL baseline. Its robustness was further validated on the Spider-DK set, where it achieved 55.1% EM, a substantial jump over previous methods.

Discussion and Insights

The success of SQLformer highlights several critical insights:

  • Inductive Bias is King: The table and column selection mechanism was the most impactful component; removing it led to a ~6% performance drop.
  • Transformers Beat LSTMs for Trees: By replacing LSTMs with Transformers for tree decoding, the model trains approximately 4x faster and is 1.2x faster during inference.
  • BFS Linearization: Using BFS traversal to linearize the AST provides a stable and predictable sequence for autoregressive learning, which is more effective than depth-first approaches for complex graphs.

Conclusion

SQLformer represents a significant step forward in Text-to-SQL translation by successfully merging Transformer architectures with graph-based structural biases. While currently focused on English, future work aims to integrate multilingual pre-trained models and further optimize the schema selection process to handle even larger, more complex databases.

Summary updated

BibTeX
@misc{bazaga2023sqlformer,
  author = {Adrián Bazaga and Pietro Liò and Gos Micklem},
  title = {{SQLformer: Deep Auto-Regressive Query Graph Generation for Text-to-SQL Translation}},
  year = {2023},
  eprint = {2310.18376},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.18376},
}
Figure