Diagnose a slow SQL query using EXPLAIN output
When a query is running slow and you have an EXPLAIN or EXPLAIN ANALYZE output, it's not always obvious which node is the culprit. This prompt helps you interpret the plan and get concrete index or rewrite suggestions.
You are a database performance specialist. I have a SQL query that is running too slowly in production and I have its execution plan.
Database engine: {{DB_ENGINE}} (e.g. PostgreSQL 15, MySQL 8, SQLite)
Original query:
```sql
{{SLOW_QUERY}}
```
EXPLAIN / EXPLAIN ANALYZE output:
```
{{EXPLAIN_OUTPUT}}
```
Table sizes and relevant context: {{TABLE_CONTEXT}}
Please do the following:
1. Identify the single most expensive node in the execution plan and explain in plain English why it is expensive.
2. Check for sequential scans on large tables. For each one, state whether an index could help and what columns that index should cover.
3. Check for nested loop joins on large row sets. If present, suggest whether a hash join or merge join would be more appropriate and why.
4. List up to three concrete, prioritized changes (index additions, query rewrites, or config changes) ordered by expected impact.
5. For each suggestion, write the exact SQL or config change needed.
6. Note any suggestions that require a maintenance window or could lock the table in production.
Do not suggest changes that require upgrading the database version unless you flag them clearly as version-dependent. {{DB_ENGINE}}{{SLOW_QUERY}}{{EXPLAIN_OUTPUT}}{{TABLE_CONTEXT}}
How to use this prompt
- Copy the prompt above (Copy button on the top-right).
- Replace each
{{VAR}}with your own value. Variables:{{DB_ENGINE}}{{SLOW_QUERY}}{{EXPLAIN_OUTPUT}}{{TABLE_CONTEXT}}. - Paste it into one of the recommended tools below.
- Iterate: tighten constraints in the prompt if the output is generic.
Why this prompt is structured this way
The prompt is split into explicit steps because LLMs do better when the path is named, not implied. Each variable forces specificity at the input layer — vague inputs get vague outputs.
Pair this prompt with a tool
Perplexity
$0/mo (Pro at $20)AI search engine with citations.
Perplexity is the answer engine Google would build if it weren't protecting search ad revenue. Cited answers, follow-up questions, focused source modes.
Claude (Anthropic)
$0/mo (Pro at $20)Frontier model with long context and strong reasoning.
Claude (Opus / Sonnet / Haiku tiers) is the assistant favored by writers and engineers who care about reasoning quality and tone. 1M token context on Opus.
ChatGPT (OpenAI)
$0/mo (Plus at $20)The category-defining general-purpose AI assistant.
ChatGPT has the broadest feature surface: image gen, voice, custom GPTs, web browsing, code execution. Often the right default; sometimes beaten on specific tasks by Claude or Perplexity.
Cursor
$20/moAI-first code editor forked from VS Code.
Cursor is VS Code with first-class LLM integration. Multi-file edits, codebase Q&A, autocomplete that's actually useful. The default IDE for many shipping engineers in 2026.
The PlaybookPrompts weekly
One short email per week. The five sharpest prompts we found, one tool worth your attention, one anti-pattern to avoid. Unsubscribe in one click.
Newsletter signup is not configured. Set PUBLIC_NEWSLETTER_USERNAME in the build env.