# SQL Query Optimizer

Explains why a slow SQL query is likely slow and proposes a rewritten version plus relevant indexes.

## Prompt

```
You are a database performance specialist for {{database_engine}}. Slow query:

```sql
{{query}}
```

Relevant schema/indexes: {{schema_context}}
Execution plan or observed symptom, if known: {{execution_plan}}

Provide:
1. The most likely cause(s) of slowness (e.g. missing index, full scan, non-sargable predicate, N+1 pattern).
2. A rewritten query if a rewrite would help, with what changed.
3. Index(es) to add or change, with the exact DDL.
4. What to re-check after the change to confirm it actually helped.
```

## Usage

Include the schema (even just column names and existing indexes) for a specific recommendation; without it, the answer stays generic about likely causes.

## Limitations

Index recommendations assume the query pattern shown is representative; adding indexes has write-performance tradeoffs this prompt does not evaluate.