LASER: A Data-Centric Method for Low-Cost and Efficient SQL Rewriting based on SQL-GRPO

Jiahui Li, Tongwang Wu, Yuren Mao, Rong Kang, Tieying Zhang, Yunjun GaoarXiv 2026

TL;DR

LASER is a data-centric framework that empowers compact Small Language Models (SLMs) to excel at SQL query rewriting, matching or exceeding the performance of massive LLMs at a fraction of the cost. By combining a novel Monte Carlo Tree Search-driven slow query generator with an execution-anchored reinforcement learning strategy (SQL-GRPO), LASER achieves state-of-the-art database optimization while remaining fully deployable locally and privately.

What Problem Does This Paper Address?

Modern Database Management Systems (DBMS) rely heavily on SQL query rewriting to transform user queries into semantically equivalent, more efficient variants. Traditional approaches generally fall into two categories: rigid rule-based heuristics, which lack the flexibility to handle complex, nested real-world queries, and Large Language Model (LLM) approaches, which suffer from high inference latency, prohibitive API costs, and severe data privacy risks.

Small Language Models (SLMs) offer a compelling alternative for local, low-latency deployment. However, training them effectively is bottlenecked by a lack of high-quality, domain-specific data. Existing synthetic datasets are often too simple, lacking the structural complexity and "optimization headroom" required to teach a compact model how to resolve severe performance regressions.

Methods

LASER introduces a two-stage framework that synergizes automated data synthesis with targeted policy optimization:

  1. Slow Query Generator (SQL-MCTS): To create a challenging training corpus, LASER uses a Monte Carlo Tree Search (MCTS) framework to deliberately evolve complex "seed" queries into structurally intricate, execution-verified slow variants. It employs a hybrid expansion strategy that combines rule-guided anti-patterns (effectively acting as a reverse query optimizer) with free-form LLM mutations.
  2. GRPO-Enhanced Query Rewriter (SQL-GRPO): The base model (Qwen3-8B/14B) is first warmed up via Supervised Fine-Tuning (SFT) on reasoning trajectories distilled from DeepSeek-R1. It is then aligned using a specialized variant of Group Relative Policy Optimization (GRPO) featuring two core innovations:
  3. Anchored Group Advantage: Standard GRPO scores outputs relative to a group mean. In SQL generation, a mediocre query can receive an inflated positive reward simply by being valid among a batch of syntax errors. LASER fixes this by grounding relative rewards against absolute execution baselines.
  4. Complexity-Adaptive Dynamic Rollout: Instead of allocating a fixed sampling budget to every prompt, this mechanism dynamically shifts exploration resources toward highly complex queries where the model exhibits high uncertainty.

Additionally, a Verification-Driven Self-Correction loop utilizes the database's EXPLAIN command at inference time as a zero-cost syntax filter, allowing the model to iteratively repair its own parsing failures based on DBMS diagnostic feedback.

Figure 1: An overview of LASER framework.

Datasets

  • SQL-MCTS: A newly introduced dataset containing 11,675 high-quality, structurally complex slow queries evolved from 3,000 initial seeds on the TPC-DS benchmark schema.
  • Evaluation Benchmarks: The framework was evaluated across diverse standard database benchmarks, including TPC-DS, TPC-H, DSB (Decision Support Benchmark), and Calcite.

Key Insights and Ideas

  • Inverting the Optimizer: To teach a model how to optimize, you must first teach it how to make things slow. Inverting traditional optimization rules (e.g., turning clean joins into correlated subqueries) provides the exact structural degradation needed to create meaningful optimization headroom.
  • The Danger of Purely Relative Rewards: In reinforcement learning for code generation, relative ranking fails when the entire sample group performs poorly. Fusing absolute performance anchors prevents the model from being rewarded for simply generating a valid but slow query.
  • Dynamic Budgets for Heterogeneous Workloads: Uniform sampling budgets waste massive amounts of compute on simple queries that saturate early. Dynamically shifting the rollout budget to hard instances allows compact models to successfully navigate sparse solution spaces.
Figure 2: The workflow of MCTS-Driven Slow Query Generation

Key Results

  • Query Latency Reductions: On the challenging DSB benchmark, LASER-14B optimized the average query execution time from 44.88 seconds down to 10.33 seconds, achieving a 83% semantic equivalence rate and outperforming both DeepSeek-R1 and GPT-4o.
  • Robust Zero-Shot Transferability: Despite being trained exclusively on the TPC-DS schema, LASER demonstrated exceptional generalization to entirely unseen database schemas, achieving a mean query execution time of 9.98 seconds on the Calcite benchmark.
  • Low Cost and Local Deployment: LASER models achieve these results locally with minimal VRAM requirements (32GB for the 8B model, 40GB for the 14B model), drastically reducing inference costs compared to commercial LLM APIs.
  • Real-World Impact: When deployed within ByteDance's production environment across real-world datasets (E-commerce, Finance, Video Streaming), LASER-14B successfully optimized queries to yield an average latency reduction of 23.1%.

Limitations and Future Work

  • Data Generation Overhead: The initial construction of the SQL-MCTS dataset is computationally heavy, spanning approximately 6.3 days due to the necessity of executing queries on a physical database to get ground-truth latency feedback.
  • Future Directions: The authors suggest exploring lighter-weight database simulators or cost models to replace physical execution loops during the dataset generation phase, which could significantly speed up the training pipeline for new database engines.

Summary updated

BibTeX
@misc{li2026laser,
  author = {Jiahui Li and Tongwang Wu and Yuren Mao and Rong Kang and Tieying Zhang and Yunjun Gao},
  title = {{LASER: A Data-Centric Method for Low-Cost and Efficient SQL Rewriting based on SQL-GRPO}},
  year = {2026},
  eprint = {2604.06804},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.06804},
}
Figure