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.
Log in to leave a comment.
Hand Claude your heap snapshots or server code and ask it to trace memory leaks — it spots missing event listener cleanup, unbounded caches, and stream lifecycle bugs that are easy to miss in code review.
Ask Claude to audit your UI components for WCAG accessibility issues — it catches semantic problems, missing ARIA attributes, and keyboard navigation gaps that automated tools miss.
The --debug flag enables verbose logging for Claude Code, and an optional category filter like "api,mcp" lets you narrow output to exactly the subsystem you need to investigate.