Exploring Schema Generalizability of Text-to-SQL

Jieyu Li, Lu Chen, Ruisheng Cao, Su Zhu, Hongshen Xu, Zhi Chen, Hanchong Zhang, Kai Yu

Abstract

Current state-of-the-art text-to-SQL models demonstrate high accuracy on benchmarks like Spider but often fail to generalize when the underlying database schema changes. This research identifies a "template-matching" behavior where models memorize surface patterns rather than reasoning about database structures. We introduce a novel framework that transforms database schemas—converting entities to attributes or concepts to cell values—while preserving question semantics. Evaluation on an Equivalent Test Set (ETS) reveals performance drops of up to 50%, highlighting a critical lack of structural robustness. We demonstrate that adversarial training with these transformed schemas significantly improves model generalizability.

Introduction

The primary objective of text-to-SQL systems is to translate natural language questions into executable SQL queries. While performance has improved significantly, these models often lack schema generalizability. In real-world scenarios, the same question (e.g., "How many singers are there?") may require different SQL structures depending on whether "singer" is defined as a table, a column, or a specific value within a table.

Variations in database schema for the same natural language question require different SQL structures.

As shown in the figure above, current models tend to over-fit to training templates. They often predict SQL structures based solely on the wording of the question, ignoring the provided schema. This "shortcut" leads to failure when the database topology deviates from the training distribution.

Methodology

To investigate and address this issue, we propose a framework for evaluating and improving structural robustness.

1. Proving Template-Matching

Experiments in syntax role prediction show that models can predict structural SQL components (e.g., JOIN, GROUP BY) with approximately 80% accuracy without accessing the database schema. This confirms a heavy reliance on natural language surface patterns rather than schema-aware reasoning.

2. Data-Driven Synthesis Framework

We utilize Entity-Relationship (E-R) graphs to automatically generate new (Schema, SQL) pairs. The framework performs four primary structural transformations:

  • Entity to Attribute (E2A): Merging related tables into one.
  • Concept to Attribute (C2A): Converting a table name into a categorical value in a column.
  • Named to Unnamed (N2U) and vice versa: Altering relationship representations, such as switching between join tables and foreign keys.
Overview of the structural transformations used to generate the Equivalent Test Set (ETS).

3. Synchronous AST Updating

To maintain logical consistency, the target SQL is updated synchronously with schema changes using Abstract Syntax Trees (AST). This ensures that the generated SQL correctly reflects the new database architecture while answering the original question.

Results and Discussion

The study primarily utilizes the Spider dataset and introduces the Equivalent Test Set (ETS), a synthetic version of the Spider dev set with structurally altered samples.

Performance Collapse

On the ETS, top-performing models like RATSQL and LGESQL experienced Exact Match (EM) accuracy drops of 25-40%. Generative models were even more vulnerable; T5-Picard's accuracy plummeted from 67.60% to 26.98%. The "Concept to Attribute" (C2A) transformation proved most challenging, with models initially achieving near 0% accuracy due to the lack of such patterns in training data.

Robustness via Adversarial Training

Training on "Affected" data—where both the schema and SQL structure change—yielded significant gains. For instance, RATSQL's performance on adversarial tests improved from 44.68% to 67.21%. Conversely, training on "Unaffected" data (schema changes only) provided negligible benefits, emphasizing that models must learn the mapping between schema topology and SQL structure.

Conclusion

This research demonstrates that current text-to-SQL models prioritize lexical patterns over structural reasoning. While adversarial training offers a path toward better generalizability, future work should focus on developing "schema-agnostic" architectures. Moving beyond static benchmarks toward models that truly reason about the relationship between natural language and graph-based database structures is essential for real-world deployment.

Summary updated

BibTeX
@inproceedings{li2023exploring,
  author = {Jieyu Li and Lu Chen and Ruisheng Cao and Su Zhu and Hongshen Xu and Zhi Chen and Hanchong Zhang and Kai Yu},
  title = {{Exploring Schema Generalizability of Text-to-SQL}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.87},
}
Figure