sql-explainer

A guide for explaining SQL queries and database execution plans in plain English. SQL is the language used to read and change data in databases, while an execution plan shows how a database will run a query.

In plain words
What is it for?
Use it to break down queries step by step, inspect EXPLAIN ANALYZE results, find missing indexes or inefficient scans, and suggest safer or faster rewrites.
Why use it?
It helps reveal what a query returns, how joins and filters work, where edge cases occur, and which operations may make it slow.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/anentrypoint/freddie/sql-explainer
Any agent
npx skills add AnEntrypoint/freddie --skill sql-explainer
Clone the repo
git clone --depth 1 https://github.com/AnEntrypoint/freddie

Made for: Claude Code, Codex.

Per session 21 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 475 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00021 $0.00475
Opus 5 $0.00010 $0.00237
Sonnet 5 $0.00004 $0.00095
Haiku 4.5 $0.00002 $0.00047

Measured yesterday against content hash 659a96e24176, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

sql-explainer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/data/sql-explainer/SKILL.md · 61 lines

What it actually says

SQL Explainer

Explain SQL queries, analyse execution plans, identify performance bottlenecks, and suggest rewrites.

Explanation format

For any query:

WHAT IT DOES (one sentence)

STEP BY STEP:
1. FROM / JOIN — which tables, join type and implications
2. WHERE — filters, sargability (can indexes be used?)
3. GROUP BY / HAVING — aggregation logic
4. SELECT — columns, computed expressions
5. ORDER BY / LIMIT — sort and pagination

EDGE CASES:
- NULLs: which columns and how they affect results
- Empty sets: what happens if a subquery returns no rows
- Duplicates: expected or a bug?

PERFORMANCE NOTES:
- Estimated scan type
- Columns that should have indexes
- Estimated row count at each stage

EXPLAIN ANALYZE reading

  • Highest actual time node = bottleneck.
  • rows estimated vs actual divergence → stale statistics (ANALYZE needed).
  • Seq Scan on large table with filter → missing index.
  • Hash Join with large hash → may spill to disk; check work_mem.
  • Nested Loop on large outer, inner Seq Scan → N+1; index the join key.

Common rewrites

Anti-pattern Fix
SELECT * in subquery Select only the join key
NOT IN (subquery with NULLs) Use NOT EXISTS
Correlated subquery in SELECT LEFT JOIN + COALESCE
DISTINCT hiding a bad join Fix the join
ORDER BY on un-indexed column with small LIMIT Index the sort column

Rules

  • Always state the SQL dialect assumed (PostgreSQL, MySQL, SQLite, BigQuery, etc.).
  • Never change query semantics in a rewrite without flagging the difference.
  • If slow but correct, suggest EXPLAIN ANALYZE output before guessing at indexes.

Paste the query (and optionally DDL + EXPLAIN output) and I will explain immediately.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 61 lines · 21 tokens per session scan A 659a96e24176

Subscribe to this mod's changes

sql-explainer is a skill published in the GitHub repository AnEntrypoint/freddie (5 stars, last pushed 2d ago), licensed MIT. It adds 21 tokens to every session and 475 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories