← All skills
Prompt · Slash command

SQL Optimizer

Analyze and optimize slow SQL queries with explanations.

What happens when you install it

1

You run the install command

mcp install-skill sql-optimizer

MCPHub CLI downloads this prompt from the registry.

2

Saved as a file in Claude Code

~/.claude/commands/sql-optimizer.md

Claude Code reads all .md files in this folder as slash commands.

3

Use it in any conversation

/sql-optimizerin Claude Code (after restart)

Claude runs the prompt against your current file or selection — no copy-paste needed.

Content

SQL Optimizer

Analyze and optimize the given SQL query for performance.

Diagnosis

Identify what makes the query slow:

  • Full table scans (missing WHERE index coverage)
  • N+1 query patterns
  • Correlated subqueries that run per row
  • Unnecessary SELECT *
  • Missing JOIN indexes
  • Implicit type conversions blocking index use
  • ORDER BY on unindexed columns
  • Large IN lists vs. joins

Output

Problem

Plain explanation of the bottleneck.

Optimized query

-- optimized version with comments explaining key changes

Indexes to add

CREATE INDEX idx_table_column ON table(column);

EXPLAIN analysis

If an EXPLAIN or EXPLAIN ANALYZE output is provided, interpret the key nodes (Seq Scan vs Index Scan, high rows estimates, etc.)

Schema recommendations

Long-term changes to consider (denormalization, partitioning, etc.) — only if clearly worth it.

Note the database engine if it affects the solution (PostgreSQL, MySQL, SQLite behave differently).