Researchers have demonstrated that a small 4B parameter language model can significantly outperform the default PostgreSQL query optimizer by generating optimized execution plans via structured hints. Using the empero-ai/Qwen3.8-4B-Distill model, the experiment utilized an agentic framework called qo-agent to interact with a PostgreSQL instance via six specialized tools, including relation inspection and plan evaluation. The training methodology employed supervised fine-tuning (SFT) and a custom variant of Group Relative Policy Optimization (GRPO) to reinforce behaviors that produce faster execution times. To ensure training stability, the researcher implemented a sophisticated measurement rig to mitigate Linux page cache contention and noise, utilizing a "fooling rate" metric to minimize the probability of incorrect reward signals caused by execution time variance. The model was trained on the Cardinality Estimation Benchmark (CEB) and validated using the Join Order Benchmark (JOB) on the IMDb dataset, ensuring the model learned structural join-graph topologies rather than just memorizing specific queries. Results showed the 4B model achieved a 44.7% latency reduction across 113 join-heavy queries, successfully overcoming the combinatorial complexity of join ordering and the inaccuracies of traditional cardinality estimation heuristics.
Read original
hackernews