Graph-Reward-SQL: Execution-Free Reinforcement Learning for Text-to-SQL via Graph Matching and Stepwise Reward

Han Weng, Boyi Liu, Yuanfeng Song, Dun Zeng, Yingxiang Yang, Yi Zhan, Longjie Cui, Xiaoming Yin, Yang SunarXiv 2025 · DOI

Introduction

Reinforcement Learning (RL) is a powerful tool for fine-tuning Large Language Models (LLMs) to generate SQL, but the "reward signal"—the feedback telling the model if it did a good job—is currently a major bottleneck. Existing methods typically fall into three traps: slow and complex execution-based rewards (EX), memory-heavy LLM-based reward models (BTRM), or brittle syntactic matching (AST) that fails to recognize semantically equivalent queries.

To overcome these limitations, we introduce Graph-Reward-SQL, a high-efficiency, execution-free framework. By replacing traditional reward signals with a lightweight Graph Matching Network (GMNScore) and a Stepwise Relational Operator Tree Match (StepRTM), we achieve state-of-the-art performance while drastically reducing computational costs.

Methodology

The core innovation of Graph-Reward-SQL lies in treating SQL as a logical structure rather than just text. The framework utilizes Apache Calcite to compile SQL into a canonical intermediate representation (Relational Operator Trees), stripping away surface-level differences to focus on underlying logic.

Overview of the Graph-Reward-SQL framework, showing the integration of GMNScore and StepRTM within the RL training loop.

GMNScore: Outcome Reward

Instead of running the SQL against a live database, the system converts both the generated and reference SQL into Relational Operator Trees (ROT). These trees represent the logical flow of the query (e.g., Filter -> Join -> Project). A lightweight Graph Matching Network (GMN) compares these embeddings to identify functional equivalence. This approach is semantically robust and avoids the "false positives" common in small-dataset execution.

StepRTM: Stepwise Reward

Complex SQL often utilizes Common Table Expressions (CTEs)—essentially sub-queries that act as intermediate steps. StepRTM provides intermediate supervision by rewarding the model for each individual sub-query (step) rather than just the final result. This mitigates the "credit assignment" problem, encouraging the model to break down complex problems into logical, readable steps.

Key Results

Graph-Reward-SQL demonstrates that efficiency and accuracy can go hand-in-hand. On the Spider benchmark, the framework reached 81.62% Execution Accuracy, outperforming standard execution-based RL and multi-agent systems.

Efficiency Gains

The computational advantages of GMNScore are substantial, offering a viable path for scaling RL training without massive hardware requirements.

Efficiency comparison between GMNScore and existing reward models, highlighting the significant speedup and memory reduction.
  • Latency: GMNScore is 47x faster than execution-based rewards (0.023s vs 1.088s per sample).
  • Memory Usage: It uses only 83MB of GPU memory, compared to 9304MB for the BTRM approach—a 112x reduction.
  • Reliability: The model achieved an AUC of 97.62% in distinguishing equivalent vs. non-equivalent queries, proving it is a highly reliable proxy for actual database execution.

Conclusion

Graph-Reward-SQL proves that a tiny 3.99M-parameter Graph Matching Network can provide a more stable and efficient reward signal than massive LLMs or literal database executions. By focusing on the underlying relational algebra, the framework solves the "long query problem" and sets a new standard for execution-free RL in Text-to-SQL tasks. Future work will explore adapting this graph-based logic to general-purpose programming languages like Python or Java.

Summary updated

BibTeX
@misc{weng2025graph,
  author = {Han Weng and Boyi Liu and Yuanfeng Song and Dun Zeng and Yingxiang Yang and Yi Zhan and Longjie Cui and Xiaoming Yin and Yang Sun},
  title = {{Graph-Reward-SQL: Execution-Free Reinforcement Learning for Text-to-SQL via Graph Matching and Stepwise Reward}},
  year = {2025},
  eprint = {2505.12380},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.12380},
}
Figure