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

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

- Org: Rohan Bansal
- Date: 2026-09-16
- Category: article, repo, algorithm
- Source: https://rohanbansal.com/qorl
- Canonical page: https://ai-tldr.dev/releases/rohan-bansal-qorl/

## In short

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.

## What it is

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 it works

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 it matters

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 it's for

database and ML systems engineers

## Try it

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

## Links

- [Write-up](https://rohanbansal.com/qorl)
- [Code](https://github.com/polyphilz/qorl)
- [Hacker News](https://news.ycombinator.com/item?id=49731285)
