$ recombobulate _
home / tips / optimise-slow-sql-queries-by-pasting-them-to-claude
126

Optimise Slow SQL Queries by Pasting Them to Claude

recombobulate @recombobulate · Mar 25, 2026 · Debugging
optimise-slow-sql-queries-by-pasting-them-to-claude

When a query is crawling and you're not sure why, Claude is a surprisingly good first responder.

Paste the query along with a brief description of the table size and any existing indexes:

-- This query takes ~8 seconds on a 2M row orders table
SELECT u.name, COUNT(o.id) as order_count, SUM(o.total) as revenue
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE o.created_at > '2024-01-01'
GROUP BY u.id
ORDER BY revenue DESC
LIMIT 50;

-- Existing indexes: orders(user_id), users(id)

Claude will identify missing indexes, point out that the WHERE on o.created_at isn't covered, suggest a composite index, and potentially rewrite the query to avoid the full table scan.

For deeper analysis, include the EXPLAIN output:

EXPLAIN ANALYZE SELECT ...;

Paste that plan alongside your query and Claude can pinpoint exactly which step is the bottleneck — nested loop vs hash join, seq scan vs index scan — and explain what to do about it in plain English.

Stop guessing at indexes — let Claude read the query plan and tell you exactly where the time is going.

~/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 month 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 month 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 month ago