← Back to the feed

A 4B AI model speeds up Postgres queries by testing better plans

Rohan Bansal reports a 44.7% cut in benchmark query time after testing up to 15 candidate plans per query. The AI tunes Postgres; it does not replace the database.

A wizard with a 4B chip face checks up to fifteen query plans; a Postgres elephant races ahead in an illustrated two-panel meme.
Original illustration for Meme Daily News. Visual reference: Doctor Strange (Marvel).

The actual story.

Bansal trained a four-billion-parameter model with supervised fine-tuning and reinforcement learning to propose Postgres query-plan changes. His experiment used 113 join-heavy queries from the Join Order Benchmark.

The strongest result came from choosing among up to 15 candidates per query using measured feedback: a 1.81× total-workload speedup, equivalent to 44.7% less execution time. The model's own final choices achieved a smaller 1.24× workload speedup in the same three-rollout evaluation. These are different selection methods, not interchangeable results.

The gains included changing join order, scan methods and parallel execution. pg_hint_plan's documentation explains those controls; PostgreSQL's EXPLAIN guide explains how to inspect plans and measure execution. Postgres still runs the queries.

The headline improvement measures the selected plans, not an end-to-end saving after model inference and candidate testing. This is a reported benchmark result, not proof of the same improvement on a production workload.

THE TAKEAWAY

The practical target is a slow query you run repeatedly, not every query on demand. Extra plan-search work can pay off if the resulting saving recurs often enough. Before adopting this approach, measure search cost against repeat-run savings on your own workload; a faster winning plan alone does not establish a cheaper system.

Receipts, not rumors.

Read the original reporting: rohanbansal.com

The reporting above provides context. Illustrations are editorial interpretations, not source photographs.

Postgres query optimizationsmall language modelsreinforcement learning

What’s your take?

Comments appear after editorial approval. No links.

Sign in with email

By continuing, you agree to our Terms of Service. Read our Privacy Policy for how we use your information.

Aaron Patelzick

EDITOR-IN-CHIEF

Aaron Patelzick

Bio

Aaron Patelzick is an entrepreneur, writer, and technologist based outside Portland, Oregon. He founded Meme Daily News and serves as its editor-in-chief, covering tech, business, and science through original memes, concise reporting, and links to the sources. He and his wife, Jaylene, co-founded Sync & Thrive, a newsletter for couples who want to build healthier habits together.

Upvote to support.

Confirm your email to vote, comment and save. New readers are welcome.

This does not subscribe you to the newsletter.

Open the sign-in page instead

One account. One vote per meme.

By continuing, you agree to our Terms of Service. Read our Privacy Policy for how we use your information.

PASS IT ON

Share the story.

WhatsAppMessagesXLinkedInYouTubeInstagramFacebookThreads
Download meme

The Monday Meme Briefing

Big Stories. Small attention span. We get it.