Qingzhi Ma

Author directory

2026

SQL query rewriting reformulates queries into more efficient forms while preserving equivalence. Most existing methods rely on predefined rules that struggle to generalize beyond fixed query patterns and cannot express complex rewriting strategies. Large language models (LLMs) can reason over complex structures and generalize to diverse patterns, but their limited execution awareness and semantic grounding often result in non-equivalent or inefficient rewrites. To this end, we propose E3-Rewrite, an LLM-based framework that generates executable, equivalent, and efficient SQL rewrites. It features two key designs: (1) an execution-aware context construction that integrates query plans and retrieved examples to expose structural bottlenecks; and (2) a reinforcement learning optimization with executability, equivalence, and efficiency rewards, trained under a correctness-to-efficiency curriculum for stable convergence. Experiments on multiple benchmarks show that E3-Rewrite-Rewrite reduces execution time by up to 25.6% over leading baselines and delivers 7.3% more equivalent rewrites, extending SQL rewriting to query patterns previously beyond rule-based methods.
While Large Language Models have significantly advanced Text2SQL generation, a critical semantic gap persists: syntactically valid queries can still misinterpret user intent. To mitigate this challenge, we propose GBV-SQL, a multi-agent framework that introduces Guided Generation with SQL2Text Back-translation Validation. In particular, a dedicated validator translates generated SQL back into natural language and checks whether its logic is aligned with the original question. Beyond the method itself, we also conduct a systematic audit of benchmark quality and introduce a typology of “Gold Errors” in Text2SQL datasets. Our analysis shows that benchmark issues can coexist with strong execution accuracy and can substantially affect evaluation outcomes. On the challenging BIRD benchmark, GBV-SQL achieves 63.23% execution accuracy, a 5.8% absolute improvement over the Deepseek-v3-based MAC-SQL setting. Under manually audited benchmark corrections, GBV-SQL reaches 96.5% (dev) and 97.6% (test) on Spider, and 90.42% on repaired BIRD dev, providing a diagnostic view of model behavior under improved gold quality. Our work contributes both a practical framework for semantic validation and an empirical analysis of benchmark integrity in Text2SQL evaluation.