Startup fine-tunes 4B open-weights model to beat Postgres's own query planner
An independent researcher used supervised fine-tuning and agentic reinforcement learning to train a small 4B-parameter open-weights language model to generate PostgreSQL execution plans. On a set of 113 join-heavy queries, the tuned model cut latency by 44.7% on average compared to Postgres's default planner, even though the base model initially failed to produce valid plans for 99 of those queries. The project also involved building a custom measurement rig to reduce caching noise and a modified GRPO reinforcement learning method for scoring plans in a noisy environment.
GoKawiil's interpretation of the reporting above, not reported fact.
Query optimization, especially join ordering, is an NP-hard problem that traditional database planners still struggle with despite decades of research. This experiment suggests that machine learning models trained with reinforcement learning on verifiable execution-time signals could eventually augment or replace hand-tuned heuristics in production databases, potentially yielding significant performance gains without rewriting the database engine itself.
- A fine-tuned 4B model reduced query latency by 44.7% versus Postgres's default optimizer on 113 join-heavy queries.
- The approach combined supervised fine-tuning with a custom reinforcement learning method (a GRPO variant) to handle noisy execution-time rewards.
- The setup split training across a rented 2x H100 GPU node and local Postgres containers to measure plan performance reliably.
Source: rohanbansal.com, 2026-09-16
Published there as: “Training a 4B model to produce 81% faster query plans than Postgres”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.