Training a 4B model to produce 81% faster query plans than Postgres
Points and comments are a snapshot, not live.
A 4B model trained via RL produces Postgres query plans 81% faster.
The author post-trains a 4B open-weights model using supervised fine-tuning and agentic reinforcement learning (a custom GRPO variant) to generate pg_hint_plan hints that steer Postgres toward faster query plans. On 113 join-heavy queries, the model achieves a 44.7% latency reduction (1.81x geometric mean speedup). The system splits RL across a rented 2x H100 node (vLLM and trainer) and four local Postgres containers. Distillation uses trajectories from GPT-6 Astra. The approach targets repeated analytic workloads, not one-off queries.
What commenters are saying
Commenters question practical deployment cost and validity. Some note the 95-hour training cost and that hints become stale when statistics or workload change, suggesting this suits ad-hoc testing rather than production. Others debate whether LLMs add value over deterministic heuristics, with comparisons to compilers. A subthread discusses whether neural networks can play chess legally. One commenter clarifies that Postgres does not assume uniform distributions-it stores histograms and most-common-value lists-so the article's framing may overstate the problem.