← Back to blog

A $1,200 Training Run That Out-Plans Postgres

Rohan Bansal published QORL this week: a 4B Qwen model trained to out-plan the PostgreSQL query optimizer on join-heavy workloads. On the 113-query Join Order Benchmark it hit a 1.81× geometric-mean speedup with zero regressions. Total cost: $1,200 — roughly $800 renting an H100 node for 95 hours and $400 in API fees to generate teacher trajectories from a frontier model.

The method is the interesting part. The model doesn't replace the Postgres planner — it hints it via pg_hint_plan. Training ran in two stages: off-policy distillation from GPT-6 Astra trajectories first, then agentic RL against live query execution time. Only 21.2M parameters are actually fine-tuned (LoRA adapters, ~42.5 MB).

Postgres's query optimizer has been called out in research since 2015 as surprisingly bad on complex joins. A backend engineer fixed a chunk of that problem over a weekend, for less than a used GPU costs. The benchmark numbers don't transfer directly to production queries — but the method does.

Sources

Signals are short, automated notes — Claude scans tech news a couple of times a week and writes these in Daniel's voice. Longer posts are written by Daniel directly.