last update
Mar 30, 2026
license
MITv1.0.0
format
SKILL.md
- Install
// Downloads SKILL.md into ~/.claude/skills/sql-query-wizard/
$ curl -fsSL --create-dirs -o ~/.claude/skills/sql-query-wizard/SKILL.md https://claudeskil.com/skills/sql-query-wizard/SKILL.md - Invoke
// Inside Claude Code, type the skill name as a slash command
> /sql-query-wizard query last week's signups - Or copy this from the README
// extracted from a Usage / Example section
$ curl -fsSL --create-dirs -o ~/.claude/skills/sql-query-wizard/SKILL.md https://claudeskil.com/skills/sql-query-wizard/SKILL.md > Schema: > CREATE TABLE orders (id bigserial PK, user_id bigint, > status text, created_at timestamptz); > Query:
- name:
- SQL Query Wizard
- slug:
- sql-query-wizard
- version:
- v1.0.0
- license:
- MIT
- author:
- @chiragthummar16
- categories:
- tags:
- #postgres#mysql#indexes#explain
- description:
Write, explain, and optimize Postgres/MySQL queries with indexes and EXPLAIN analysis.
README.md
SQL Query Wizard
SQL Query Wizard helps you write, understand, and speed up SQL against Postgres and MySQL. Paste in a schema and a slow query, and it walks through the execution plan, proposes targeted indexes, and measures the before/after timing so you can see whether the change actually helped. It's aimed at backend engineers and data analysts who can read SQL but don't want to memorize every planner quirk.
When to use it
- A query that was fast in dev is timing out in production and you need to know why.
- You're staring at an
EXPLAINplan full ofSeq Scan,Nested Loop, orUsing filesortand want it translated. - You're designing a new table and want index advice before the data grows.
- You need to rewrite a correlated subquery, a
DISTINCT, or anORchain into something the planner handles better.
How it works
Give the skill your DDL (CREATE TABLE / CREATE INDEX statements) plus the query. It will:
- Run
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)on Postgres orEXPLAIN ANALYZE/EXPLAIN FORMAT=JSONon MySQL and read the plan node by node — flagging row-estimate misses, spilled sorts, and scans that should be index lookups. - Suggest concrete index DDL, including composite column order, partial indexes (
WHEREclauses), covering indexes (INCLUDEon Postgres), and expression indexes. - Rewrite the query where the shape, not the index, is the bottleneck.
- Re-run the plan after applying changes and report timing and row deltas side by side.
It distinguishes Postgres and MySQL semantics — e.g. Postgres INCLUDE columns vs MySQL covering via the secondary index, and pg_stat_statements vs the MySQL performance_schema for finding slow queries.
Example
curl -fsSL --create-dirs -o ~/.claude/skills/sql-query-wizard/SKILL.md https://claudeskil.com/skills/sql-query-wizard/SKILL.md
> Schema:
> CREATE TABLE orders (id bigserial PK, user_id bigint,
> status text, created_at timestamptz);
> Query:
> SELECT * FROM orders
> WHERE user_id = 42 AND status = 'paid'
> ORDER BY created_at DESC LIMIT 20;
> Engine: Postgres 16. It does a Seq Scan + Sort. Help.
→ Suggests:
CREATE INDEX idx_orders_user_status_created
ON orders (user_id, status, created_at DESC);
Plan changes from Seq Scan + Sort to Index Scan (no sort node).
Tips & gotchas
- Always run
EXPLAIN ANALYZEagainst realistic data volumes — plans flip between seq scan and index scan based on table statistics, so a 100-row dev table lies. - Run
ANALYZE(orANALYZE TABLEon MySQL) after large loads; bad row estimates cause most "why isn't my index used" cases. - Composite index column order matters: equality predicates first, range/sort columns last.
EXPLAIN ANALYZEactually executes the query — wrap writes in a transaction you roll back.
FAQ
Does it connect to my database? Only if you let it run queries; otherwise paste the plan text and it analyzes statically.
Postgres and MySQL both? Yes — it adapts syntax and planner advice per engine.
Can it explain an existing plan I paste? Yes, paste raw EXPLAIN output and it annotates each node.
$ cat reviews/