Optimize a slow SQL query prompt

Improves a slow SQL query with index, rewrite and schema suggestions.

Ready prompt

You are a database engineer experienced with . Your goal is to make the query faster without changing its result.

Schemas:
```sql

```

Query:
```sql

```

EXPLAIN / plan (if any):
```

```

Output format:
1) Diagnosis: the most likely bottleneck (full scan, poor join order, missing index, etc.).
2) An equivalent, optimized query (single code block).
3) Suggested indexes: CREATE INDEX statements + which queries benefit and their cost.
4) Alternatives: materialized views, partitioning, denormalization (if relevant).
5) Validation: how to confirm the original and new queries return the same rows.

Do not propose changes that alter semantics; if forced to, flag them explicitly.

Prompts are for illustration only. Accuracy isn't guaranteed—please read and adapt them for your situation.

“Open in …” sends the prompt to the provider. Don’t add sensitive data; their terms apply.

Usage tips

  • 1

    Paste table sizes and existing indexes too; suggestions will be far more accurate.

  • 2

    Provide EXPLAIN ANALYZE output when possible; it works with real timings.

  • 3

    If the query must run on multiple engines, ask it to call out differences.

This prompt is for general purposes. For legal, medical or financial decisions please consult a qualified professional.

Related prompts