Read an EXPLAIN Plan and Fix a Slow Query

8 Views
0 Uses

Prompt

ChatGPT
Claude
Grok
OpenRouter
You are a database performance specialist. Diagnose this slow query from its execution plan and propose the smallest effective fix.

Database and version: {{DIALECT}}
The query: {{QUERY}}
EXPLAIN (ANALYZE if possible) output: {{EXPLAIN_OUTPUT}}
Table sizes, existing indexes, and how often the query runs: {{TABLE_FACTS}}

Do this:
1. Walk the plan from the most expensive node outward. For each costly node, explain in plain English what the database is doing and why: sequential scan, nested loop over many rows, sort spilling to disk, misestimated row counts.
2. Point out mismatches between estimated and actual rows, and what they suggest (stale statistics, correlated columns, functions on columns).
3. Propose fixes in order of least invasive first: rewrite the query, add or change an index (give the exact CREATE INDEX statement and its column order reasoning), update statistics, then schema changes.
4. For each index, state the cost: slower writes, disk space, and lock behavior while it's being created on a live table (and the concurrent-build option if my database has one).
5. Tell me what the new plan should look like if the fix works, so I can confirm it.

Only reference indexes and columns that exist in what I pasted, unless you're proposing a new one.

Customize this prompt

Fill in the variables below to personalize this prompt:

ChatGPT
Claude
Grok
OpenRouter

Model Settings

Recommended Models

ChatGPT Claude Gemini

Temperature

0.7

Max Tokens

2000

Additional Notes

Best for: Fixing a query that got slow as the data grew

About this prompt

“Read an EXPLAIN Plan and Fix a Slow Query” is a free prompt for ChatGPT in the Coding & Software category, 205 words long, added to The Prompt Index on October 28, 2026 by The Prompt Index. Copy it with the button above, paste it into ChatGPT or any other AI chat assistant, and send it.

It has 4 placeholders to fill in first: {{DIALECT}}, {{QUERY}}, {{EXPLAIN_OUTPUT}}, {{TABLE_FACTS}}. Use the “Customize this prompt” fields to personalise it before you copy.

Recommended models: ChatGPT, Claude, Gemini.

0 upvotes, sent to an AI tool 0 times, viewed 8 times.

Browse all Coding & Software prompts, the AI prompt database or use the AI prompt finder to search every prompt.