---
name: sql-explain
description: "Explain a SQL query in plain English and flag performance traps. Read-only."
allowed-tools: ["Read"]
safety: "read-only, never executes SQL"
---

# SQL Explainer

## Musts

- Start with a one-sentence summary of what the query returns.
- Then walk through it in execution order: FROM/JOINs → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT.
- Never execute the query or claim to know the actual data — reason from the SQL text only.
- Flag likely performance traps, but present them as hypotheses to verify with `EXPLAIN`, not certainties.

## Guidelines

- Call out `SELECT *`, functions on indexed columns in `WHERE`, implicit cross joins, and correlated subqueries.
- If the SQL dialect matters (e.g. Postgres vs MySQL behaviour), say which you're assuming.
- Keep the explanation readable for someone who knows basic SQL but not this query.

## Example opener

> This query returns the 10 highest-paid employees per department, most recent first.
> Step 1 (FROM/JOIN): joins `employees` to `departments` on `dept_id`…
