PostgreSQL · rohanbansal.com
Tuning a 4B model to produce 81% faster query gears up than Postgres
Compiled by KHAO Editorial — aggregated from 1 source. See llms.txt for citation guidance.
◌ Single Source
Leis et al. asked this exact question in 2015.
Key facts
- Running this query outputs 10 Japanese companies with the number of titles they were associated with between 2000 and 2009, sorted from highest to lowest
- They used Qwen 3.8’s 2.4T model as a teacher model to distill learnings into Qwen 3.5 4B, producing empero-ai/Qwen3.8-4B-Distill
- The first join ordering filters the 2m movie_companies entries down to the 5% slice of companies that are Japanese
- The second join ordering filters the 2m movie_companies entries down to the 20% slice of titles that were made in the 2000s
Summary
Despite an enormous body of research spanning a decade since their original exploration, they found that query optimizers continue to leave much to be desired. So query optimizers are hard. What’s not as hard is verifying whether a query plan an optimizer picks is good or not. What follows is a breakdown of an experiment the reporter ran to explore the question: can a small, open-weights model be post-trained via supervised fine-tuning (SFT) and agentic reinforcement learning (RL) to produce Postgres query plans that beat Postgres’s default plans? Attaining a 44.7% latency reduction across 113 join-heavy queries from a 4B model initially unable to produce a query plan for 99 of them.