doc-condenser
**DEPRECATED** — Modern Claude models condense and summarize technical documentation natively with comparable quality. The output…
Analyzes SQL queries for missing indexes, N+1 patterns, suboptimal joins, and full table scans. Interprets EXPLAIN, detects anti-patterns, rewrites queries. Triggers on: "optimize this query", "slow query", "add indexes", "explain plan", "N+1 query", "why is this query slow".
Claude Code
$ npx -y skills add Mathews-Tom/armory --skill sql-optimizer --agent claude-code
Codex
$ npx skills add Mathews-Tom/armory --skill sql-optimizer -a codex -y
Cursor
$ npx skills add Mathews-Tom/armory --skill sql-optimizer -a cursor -y
Gemini CLI
$ npx skills add Mathews-Tom/armory --skill sql-optimizer -a gemini-cli -y
GitHub Copilot
$ npx skills add Mathews-Tom/armory --skill sql-optimizer -a github-copilot -y
OpenCode
$ npx skills add Mathews-Tom/armory --skill sql-optimizer -a opencode -y
Windsurf
$ npx skills add Mathews-Tom/armory --skill sql-optimizer -a windsurf -y
name: sql-optimizer description: 'Analyzes SQL queries for missing indexes, N+1 patterns, suboptimal joins, and full table scans. Interprets EXPLAIN, detects anti-patterns, rewrites queries. Triggers on: "optimize this query", "slow query", "add indexes", "explain plan", "N+1 query", "why is this query slow".' metadata: version: 1.1.1 category: data tags: [sql, performance, database, optimization] difficulty: intermediate phase: build
Systematic SQL performance analysis: parse query structure, interpret EXPLAIN plans, detect anti-patterns (N+1, full scans, cartesian joins), recommend indexes, and rewrite queries — with explanations of WHY each change improves performance, not just WHAT changed.
| File | Contents | Load When | | --------------------------------- | ------------------------------------------------------------------------- | ---------------------------------- | | `references/anti-patterns.md` | Common SQL anti-patterns with detection rules and fixes | Always | | `references/index-strategies.md` | Index type selection, composite index ordering, covering indexes | Index recommendations needed | | `references/explain-guide.md` | Reading EXPLAIN output for PostgreSQL, MySQL, SQLite | EXPLAIN plan provided | | `references/join-optimization.md` | Join type selection, join order optimization, subquery-to-join conversion | Query contains joins or subqueries |
Parse the SQL to understand its structure:
1. **Identify operations** — SELECT columns, FROM tables, JOIN conditions, WHERE filters, GROUP BY, ORDER BY, HAVING, subqueries. 2. **Map table relationships** — Which tables are joined? On what keys? Are there implicit cartesian products? 3. **Detect immediate red flags**:
If an EXPLAIN plan is provided:
1. **Scan types** — Sequential Scan (bad for large tables), Index Scan (good), Index Only Scan (best), Bitmap Index Scan (acceptable). 2. **Join methods** — Nested Loop (good for small tables), Hash Join (good for equi-joins), Merge Join (good for sorted data). 3. **Row estimates** — Compare estimated rows with actual rows. Large discrepancies indicate stale statistics (`ANALYZE`). 4. **Cost hotspots** — Highest-cost node is the bottleneck. Optimize there first. 5. **Sort operations** — External sorts (disk) are expensive. Consider indexes that match ORDER BY.
Check for known performance anti-patterns (see `references/anti-patterns.md`):
| Pattern | Detection | Impact | | --------------------------- | ------------------------------ | -------------------------- | | SELECT \* | Star in select list | Transfers unnecessary data | | N+1 queries | Loop with query inside | N additional roundtrips | | Function on indexed column | `WHERE UPPER(name) = 'X'` | Index bypass | | Implicit type cast | String compared to integer | Index bypass | | Missing join condition | Cartesian product | Exponential rows | | LIKE '%prefix' | Leading wildcard | Full scan | | OR with different columns | `WHERE a=1 OR b=2` | Index bypass | | SELECT DISTINCT as band-aid | Hides duplicate-producing join | Fix the join instead |
1. **Index recommendations** — Based on WHERE, JOIN, ORDER BY, GROUP BY columns. Consider composite indexes for multi-column conditions. 2. **Query rewrite** — Convert correlated subqueries to JOINs, replace `IN (SELECT...)` with EXISTS, use CTEs for readability without performance cost (PostgreSQL 12+ may inline CTEs). 3. **Schema suggestions** — Denormalization, materialized views, partitioning (mention only when query-level optimization is insufficient).
Present the original query, detected issues, recommended indexes, rewritten query, and explanation of each change.
## SQL Optimization Analysis
### Original Query
```sql
{original SQL}| # | Issue | Severity | Location | Impact | | --- | ------- | ----------------- | ------------------- | ---------------- | | 1 | {issue} | {High/Medium/Low} | {WHERE/JOIN/SELECT} | {what it causes} |
{If EXPLAIN provided}
-- {Reason for this index}
CREATE INDEX {name} ON {table}({columns});{rewritten query}1. **{Change}** — {Why this improves performance. Include estimated impact.}
## Configuring Scope | Mode | Input | Depth | When to Use
Curated, production-grade skills, agents, hooks, rules, commands, utilities, and presets for AI coding agents. No magic, no demos — battle-tested workflows built for developers who use AI seriously.
**DEPRECATED** — Modern Claude models condense and summarize technical documentation natively with comparable quality. The output…
DEPRECATED: The Opus 4.7 migration scanner is retired from the active skill catalog. Retained for archival reference only; not…
**DEPRECATED** — Modern Claude models produce accurate, well-explained regex patterns with edge-case test suites natively,…
**DEPRECATED** — Opus 4.7 uses adaptive thinking (optional at each step) and Sonnet 4.6 handles structured chain-of-thought…
Generates Architecture Decision Records capturing context, rationale, alternatives, and consequences in numbered status-tracked…
Build AI agents and automate Claude Code programmatically via the Claude Agent SDK and headless CLI mode. Covers Python SDK,…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.