$ recombobulate _
home / tips / paste-a-slow-querys-explain-output-and-let-claude-optimize-it
85

Paste a Slow Query's EXPLAIN Output and Let Claude Optimize It

recombobulate @recombobulate · Mar 29, 2026 · Debugging
paste-a-slow-querys-explain-output-and-let-claude-optimize-it

You know a query is slow, but EXPLAIN output is hard to read. Paste it into Claude and get a clear diagnosis with specific fixes.

"This query takes 4 seconds. Here's the EXPLAIN output:
[paste EXPLAIN ANALYZE results]
Fix it."

Claude reads the execution plan, identifies the bottlenecks, and gives you actionable fixes — not generic advice, but specific changes for this query:

  • "The orders table is doing a full table scan because there's no index on customer_id — add one"
  • "The subquery runs once per row. Rewrite it as a JOIN to eliminate 10,000 subquery executions"
  • "The filesort on created_at is killing performance. Add a composite index on (status, created_at)"

You can provide just the query, just the EXPLAIN, or both:

# Just the slow query
"This query is slow in production. Read the schema and explain why, then fix it:
SELECT * FROM orders WHERE..."

# Query + EXPLAIN plan
"Here's a slow query and its EXPLAIN output. What's wrong and how do I fix it?
Query: SELECT...
EXPLAIN: [paste output]"

# From your ORM
"This Eloquent query is slow. Read the model and suggest how to optimize it:
Order::with('items.product')->where('status', 'pending')->get()"

Claude can also help you get the data you need:

# Generate the EXPLAIN for you
"Run EXPLAIN ANALYZE on the query that lists pending orders and tell me what's slow"

# Compare before and after
"I added the index you suggested. Run EXPLAIN again and tell me if it's better"

For ORM users, Claude translates between the ORM code and the generated SQL — showing you which Eloquent call produces the problematic query and how to rewrite it:

"This eager load is creating an N+1. Show me the queries it generates and fix it."

EXPLAIN tells you what the database is doing. Claude tells you why it's slow and how to fix it.

via Claude Code

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
161
Ask Claude to Find and Fix the Performance Bottleneck in a Slow Endpoint

When a page takes five seconds to load or an API endpoint times out under load, tell Claude which route is slow and it traces the entire code path — controller, services, queries, loops — identifying N+1 queries, redundant computations, missing indexes, and cacheable operations, then fixes each bottleneck.

recombobulate @recombobulate · 1 day ago
149
Ask Claude to Diagnose and Fix Flaky Tests That Pass Sometimes and Fail Randomly

Flaky tests are maddening — they pass locally, fail in CI, pass again when you retry. Tell Claude to read the test, identify the source of non-determinism — timing issues, shared state, date dependencies, or order-dependent setup — and fix the root cause so the test is reliably green or reliably red.

recombobulate @recombobulate · 1 day ago
148
Paste an Error Message or Stack Trace and Let Claude Trace It to the Root Cause

When your app throws an error, don't just Google the message — paste the full stack trace into Claude Code. It reads the trace, opens the referenced files in your codebase, follows the call chain, and pinpoints the actual root cause instead of just explaining the symptom.

recombobulate @recombobulate · 1 day ago