Query and Conquer: Execution-Guided SQL Generation
Łukasz Borchmann, Marek Wydmuch
TL;DR
The paper tackles the gap between pass@k and pass@1 in text-to-SQL by introducing execution-guided self-consistency, which uses execution results to compare candidate queries within a Minimum Bayes Risk (MBR) framework. It differentiates exact execution similarity, based on matching outputs, from approximate similarity via execution plans, and extends the approach to partially executable SQL with PipeSQL and a patience mechanism to refine intermediate steps. Empirically, the method yields significant accuracy gains across a spectrum of models, with small 3B–7B models approaching the performance of heavier reasoning systems at markedly reduced inference cost (up to 30x cheaper). The approach generalizes beyond SQL to broader code-generation tasks, offering a scalable, exchangeable pathway to robust, cost-efficient program synthesis.
Abstract
We propose a novel approach for generating complex outputs that significantly improves accuracy in text-to-SQL tasks. Our method leverages execution results to select the most semantically consistent query from multiple candidates, enabling smaller, cost-effective models to surpass computationally intensive reasoning methods such as o1, o3-mini, and DeepSeek R1 while reducing inference cost by as much as 30 times. It integrates effortlessly with existing models, offering a practical and scalable pathway to state-of-the-art SQL generation.
