Back to Devoured - September 17, 2026
DEVOURED
Training a 4B model to produce 81% faster query plans than Postgres

Training a 4B model to produce 81% faster query plans than Postgres

Tech Rohanbansal.com
A 4B parameter model fine-tuned with reinforcement learning can generate PostgreSQL query plans that are 44.7% faster than the database's native optimizer.
What: Rohan Bansal demonstrated that a small, open-weights model, trained via supervised fine-tuning and agentic reinforcement learning, consistently outperforms PostgreSQL's default optimizer on join-heavy queries.
Why it matters: This reveals that query optimization is a prime candidate for machine learning augmentation because the output—query execution time—is easily verifiable, turning a traditionally NP-hard search problem into an reinforcement learning task.
Takeaway: If you are struggling with complex join performance, consider that external AI agents can now generate statistically faster execution plans than native database heuristics.
Deep dive
  • The author demonstrated that 4B parameter models can outperform PostgreSQL’s native cost-based query optimizer.
  • Training utilized supervised fine-tuning (SFT) followed by agentic reinforcement learning (RL) to optimize for execution time.
  • Key results included a 44.7% latency reduction across 113 join-heavy queries on the IMDb dataset.
  • The system handles the massive combinatorial space of join trees, orientations, and scan types (Hash, Merge, Nested Loop).
  • Infrastructure setup involved a 2x H100 node for RL training and a local machine running PostgreSQL containers to measure execution time.
  • The approach used GRPO (Group Relative Policy Optimization) to account for noise in database performance measurements.
Decoder
  • Join ordering: The sequence in which database tables are combined to produce a result, which drastically affects performance due to intermediate table sizes.
  • NP-hard: A class of computational problems where no algorithm is known to provide the optimal solution in polynomial time, making exact solutions expensive for large inputs.
  • GRPO: A variant of Proximal Policy Optimization (PPO) that evaluates multiple outputs to determine a baseline score, useful for noisy reward signals.
Original article

Full article content is not available for inline reading.

Read the original article →

Explore all 60 articles in today's digest

Fresh dev news, AI-digested daily. Never miss a trend at devoured.fyi