Training a 4B model to produce 81% faster query plans than Postgres(rohanbansal.com)
689 points by polyphilz 27 days ago | 143 comments
tl;dr: A developer post-trained a 4B parameter model (Qwen3.8-4B-Distill) using supervised fine-tuning on GPT-6 Astra trajectories plus custom GRPO reinforcement learning to generate Postgres query hints via the pg_hint_plan extension. The resulting agent achieved a 44.7% latency reduction across 113 join-heavy JOB benchmark queries, up from a baseline where the untrained model couldn't even produce valid plans for 99 of them. Key engineering work included building a low-noise Postgres measurement rig (tuning shared_buffers was critical) and designing reward signals robust to execution-time variance.
HN Discussion:
  • ↓Benchmark conditions are unrealistic and results likely don't generalize to real workloads
  • ↓LLMs are the wrong tool; query planning needs math/algorithms or specialized neural heuristics
  • ↓The speedup is likely explained by fixing misconfigured Postgres defaults rather than genuine LLM optimization
  • ↓Using hints papers over the real problem of missing indices and bad statistics
  • ↑Appreciation for the clear writing and accessible explanation of advanced ML concepts