AI/TLDR

Rohan Bansal · 2026-09-16 · notable

Qorl — a 4B model plans Postgres queries 1.81x faster

Qorl trains a 4B distilled Qwen3.8 model with LoRA and agentic reinforcement learning to hint the PostgreSQL planner. On the 113-query Join Order Benchmark it reaches a 1.81x geometric-mean speedup with no regressions, for $1,200.

Title card for the Qorl write-up on training a 4B model to optimize Postgres query plans

Qorl gets a 4B model to out-plan the PostgreSQL optimizer on join-heavy queries for about $1,200 of compute.

Key specs

Geomean speedup1.81x on JOB
Training cost$1,200

What is it?

Qorl is a small agent that steers PostgreSQL toward faster physical query plans instead of replacing the planner. Rohan Bansal published the write-up and the training code on 16 September 2026. The policy is a distilled 4B Qwen3.8 model — empero-ai/Qwen3.8-4B-Distill — adapted with LoRA adapters holding only 21.2 million trainable parameters, about 42.5 MB.

How does it work?

Training ran in two stages. First came off-policy distillation: the small model imitated 420 trajectories in which GPT-6 Astra drove PostgreSQL through a six-tool harness called qo-agent, with calls such as inspect_relation, get_column_stats, get_plan and evaluate_candidate. Then came agentic reinforcement learning, using a GRPO variant with anchored relative advantages that scores each emitted planner hint by how much real execution time it saves against PostgreSQL's default plan.

Why does it matter?

The result argues that a narrow, cheap model beats a frontier model on a well-shaped systems task. Across the 113 queries of the Join Order Benchmark, best-of-3 rollouts cut latency 44.7%, improved 68 queries by more than 5% and regressed none, for a total bill of roughly $1,200 — about $800 of H100 rental over 95 hours plus $400 of API fees for the distillation trajectories.

Who is it for?

database and ML systems engineers

Try it

git clone https://github.com/polyphilz/qorl && uv sync --frozen

Sources · 3 outlets

Tags

  • postgres
  • databases
  • query-optimization
  • reinforcement-learning
  • grpo
  • lora
  • distillation
  • small-models
  • agents
  • open-source

← All releases · Learn AI