milad-ahmd/agent-skills/sql-optimizer
Claude Code and agent skill by milad-ahmd/agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Explains slow SQL queries in plain English, reads EXPLAIN plans, and suggests concrete rewrites and indexes for PostgreSQL, MySQL, and SQLite, including ORM-generated N+1 problems. Use when the user shares a slow query, an EXPLAIN output, asks why a query is slow, or wants index recommendations.
Install
npx vskill@latest install milad-ahmd/agent-skills/sql-optimizerSKILL.md
The same SKILL.md was published earlier as milad-ahmd/agent-skills/sql-optimizer.
SQL Optimizer
Turn "this query takes 8 seconds" into a measured fix.
1. Understand
- Identify the engine and version, then explain in plain English what the query returns.
- Gather the schema: the tables, the indexes (
\d tablein Postgres,SHOW INDEX FROM tin MySQL) and rough row counts. - Get the real plan. Ask before running anything against production:
- Postgres:
EXPLAIN (ANALYZE, BUFFERS) <query>. Note that ANALYZE executes the query, so wrap writes inBEGIN; ... ROLLBACK;. - MySQL:
EXPLAIN ANALYZE <query>(8.0.18+) orEXPLAIN FORMAT=JSON. - SQLite:
EXPLAIN QUERY PLAN <query>.
2. Diagnose. Common culprits:
- Seq scan or full table scan on a large table with a selective filter → missing index.
- Functions or casts on indexed columns (
WHERE lower(email) = ...,WHERE created_at::date = ...) → not sargable. - Leading wildcard
LIKE '%x',ORacross different columns, orNOT INwith NULLs. - Large estimate-vs-actual row mismatches → stale statistics (
ANALYZE). SELECT *on wide tables, unnecessaryDISTINCT, orORDER BYwith no supporting index plusLIMIT.- Deep
OFFSETpagination → use keyset pagination. - Correlated subqueries → use JOIN or
EXISTS; also look for an N+1 pattern in ORM code (loops that issue queries).
3. Recommend
For each fix give: the change, why it helps, the expected plan change and the trade-offs.
- Prefer query rewrites before adding indexes. Every index slows down writes and uses storage.
- Consider partial indexes (
WHERE deleted_at IS NULL), covering indexes (INCLUDE) and expression indexes. - For ORMs, show the fix in the ORM's own syntax: eager loading (
include,select_related,preload) and selecting only the needed columns. - Use
CONCURRENTLY(Postgres) or online DDL for production tables, and ship index changes as a migration in the project's migration tool.
4. Verify
Compare the plan and timing before and after the change. Never claim a speedup you didn't measure; label unmeasured numbers as estimates.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/sql-optimizer/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/milad-ahmd/agent-skills/sql-optimizer)