A 4B model beats Postgres query plans by 44.7%
Training a 4B model to produce 81% faster query plans than Postgres

A 4B open-weights model was post-trained with supervised fine-tuning and agentic reinforcement learning to produce Postgres query plans that outperform the default planner. Across 113 join-heavy queries, latency dropped 44.7%, even though the model initially failed to produce any plan for 99 of them. The work required a custom GRPO variant for noisy environments and a measurement rig that minimized page cache contention.
A query optimizer does not aim to be exact in its cost minimization… it aims to be good enough across many types of queries.