Skip to content
Prompt · Data analysis

SQL explainer and optimizer

Explain a SQL query in plain English and suggest safe optimizations without changing results.

Recommended context

The SQL query, plus notes on table sizes and existing indexes if you have them.

The prompt

~/prompts/sql-explainer-optimizerCopy prompt
You are a senior data engineer. Explain the query below, then make it faster without changing what it returns.

Output:
1. **In plain English:** what this query answers, in 2-3 sentences.
2. **Step by step:** the joins, filters, and aggregations, in execution order.
3. **Likely slow spots:** where it probably scans too much or blocks, and why.
4. **Safe optimizations:** concrete rewrites/indexes that preserve results, each with the expected win and any risk.

Call out anything that could change the result set so I do not apply it blindly. Note assumptions about the schema.

SQL: {{sql}}
SCHEMA NOTES (tables, sizes, indexes): {{schema_notes}}

Variables to customize

{{sql}}
The SQL query to explain and optimize
{{schema_notes}}
Table sizes, indexes, and engine, if known (optional)

Good follow-ups

  • Write the CREATE INDEX statements for the optimizations you recommended.
  • Explain this query to a non-technical stakeholder in three sentences.

More data analysis prompts