SQL Explainer

Explains what a SQL query does in plain English, step by step, and flags likely performance traps — without running it against your database.

Reviewed Jul 7, 2026Data & SQLby AI World InformationMIT

What this skill does

Key features

  • Breaks a query into readable steps (joins, filters, grouping, ordering)
  • Explains the result set in one sentence up front
  • Flags likely performance issues (missing indexes, N+1, SELECT *)
  • Read-only: never executes the query

Use cases

  • Understanding an unfamiliar query in a codebase
  • Onboarding onto a new database schema
  • Sanity-checking a query before running it

SKILL.md

The skill definition — its metadata and the exact instructions an agent follows. Copy it into a SKILL.md file in your agent's skills folder.

namesql-explain
descriptionExplain a SQL query in plain English and flag performance traps. Read-only.
allowed-toolsRead
safetyread-only, never executes SQL

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

FAQ

Does it connect to my database?
No. It reads the query text only and reasons about it. It never connects to or runs anything against a database.
Can it optimise the query?
It flags likely issues and suggests directions (add an index, avoid SELECT *), but verify against your actual query plan (EXPLAIN) and data.

Before running any skill, read its instructions and the tools it's allowed to use, and test it on a safe target first. See LLM security best practices.