Training a 4B Model With RL to Beat Postgres Query Plans by 81%

bytebot · x · 2026-09-17

Developer Rohan Bansal details an experiment post-training an open-weights 4B Qwen model with SFT and agentic RL to produce Postgres query plans up to 81% faster than the default optimizer. Since plan quality reduces to a single verifiable signal — execution time — each RL rollout sends a candidate plan to Postgres for measurement, and scalar rewards flow back to update the weights. The post contextualizes this with the Leis et al. finding that query optimizers (join ordering is NP-hard) still underperform a decade later.

Original post →

More from coding & agent

coding & agent channel →