Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
jeffallan avatar

Sql Pro

  • 4.9k installs
  • 10.8k repo stars
  • Updated May 20, 2026
  • jeffallan/claude-skills

sql-pro is a specialist Claude skill that optimizes SQL queries, designs database schemas, and troubleshoots performance using execution plans, indexes, CTEs, and window functions across major SQL dialects.

About

The sql-pro skill guides agents through schema analysis, set-based query design, execution plan review, and verified optimization for PostgreSQL, MySQL, SQL Server, and Oracle workloads. It loads targeted references for JOIN and CTE patterns, window functions, EXPLAIN interpretation, database design, and dialect differences when context demands. The core workflow reviews structure and indexes, designs queries with early filtering and window functions, analyzes plans to eliminate sequential scans on large tables, implements covering indexes, and verifies with EXPLAIN ANALYZE against a sub-100 millisecond target before documenting rationale and metrics. Mandatory practices include set-based operations over cursors, EXISTS over COUNT for existence checks, explicit NULL handling, production-scale testing, and dialect-specific tuning. Output templates deliver optimized SQL with inline comments, index recommendations, plan analysis, before-and-after benchmarks, and platform notes. Quick-reference examples cover ranked-order CTEs, running totals via window functions, correlated subquery rewrites, and covering index creation for aggregation joins.

  • Five-step workflow: schema analysis, design, optimize, verify with EXPLAIN ANALYZE, document
  • Context-loaded references for query patterns, window functions, optimization, design, and dialects
  • Covering indexes and early filtering to eliminate sequential scans on large tables
  • Rewrites correlated subqueries into single aggregation joins with supporting indexes
  • Output bundle: optimized SQL, index rationale, plan analysis, and before/after metrics

Sql Pro by the numbers

  • 4,872 all-time installs (skills.sh)
  • +121 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #22 of 923 Databases skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

sql-pro capabilities & compatibility

Capabilities
schema analysis with index and bottleneck review · set based query design using ctes and window fun · explain analyze interpretation and covering inde · correlated subquery rewrites and dialect specifi · before/after benchmarking with documented perfor
Use cases
database · debugging · api development
From the docs

What sql-pro says it does

Analyze execution plans before recommending optimizations
SKILL.md
Use set-based operations over row-by-row processing
SKILL.md
Run `EXPLAIN ANALYZE` and confirm no sequential scans on large tables
SKILL.md
npx skills add https://github.com/jeffallan/claude-skills --skill sql-pro

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs4.9k
repo stars10.8k
Security audit3 / 3 scanners passed
Last updatedMay 20, 2026
Repositoryjeffallan/claude-skills

Why is my query slow, how do I write complex joins or aggregations, and what indexes or rewrites will meet production latency targets?

Optimize slow SQL, design schemas, and troubleshoot database performance across PostgreSQL, MySQL, SQL Server, and Oracle with execution-plan driven rewrites.

Who is it for?

Backend developers and agents tuning slow queries, designing schemas, migrating SQL between PostgreSQL, MySQL, SQL Server, or Oracle, or interpreting EXPLAIN plans.

Skip if: Skip when the task is ORM-only scaffolding without SQL, NoSQL databases, or greenfield apps with no schema or performance symptoms yet.

When should I use this skill?

User asks why a query is slow, needs complex joins, window functions, CTEs, indexing strategies, EXPLAIN/ANALYZE help, recursive queries, or dialect migration.

What you get

Optimized queries with inline comments, covering index DDL, EXPLAIN ANALYZE interpretation, before/after benchmarks, and dialect-specific notes validated against production-scale data.

  • CREATE TABLE DDL scripts
  • Junction and constraint definitions

By the numbers

  • Covers normalization levels 1NF through 3NF with SQL examples

Files

SKILL.mdMarkdownGitHub ↗

SQL Pro

Core Workflow

1. Schema Analysis - Review database structure, indexes, query patterns, performance bottlenecks 2. Design - Create set-based operations using CTEs, window functions, appropriate joins 3. Optimize - Analyze execution plans, implement covering indexes, eliminate table scans 4. Verify - Run EXPLAIN ANALYZE and confirm no sequential scans on large tables; if query does not meet sub-100ms target, iterate on index selection or query rewrite before proceeding 5. Document - Provide query explanations, index rationale, performance metrics

Reference Guide

Load detailed guidance based on context:

TopicReferenceLoad When
Query Patternsreferences/query-patterns.mdJOINs, CTEs, subqueries, recursive queries
Window Functionsreferences/window-functions.mdROW_NUMBER, RANK, LAG/LEAD, analytics
Optimizationreferences/optimization.mdEXPLAIN plans, indexes, statistics, tuning
Database Designreferences/database-design.mdNormalization, keys, constraints, schemas
Dialect Differencesreferences/dialect-differences.mdPostgreSQL vs MySQL vs SQL Server specifics

Quick-Reference Examples

CTE Pattern

-- Isolate expensive subquery logic for reuse and readability
WITH ranked_orders AS (
    SELECT
        customer_id,
        order_id,
        total_amount,
        ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) AS rn
    FROM orders
    WHERE status = 'completed'          -- filter early, before the join
)
SELECT customer_id, order_id, total_amount
FROM ranked_orders
WHERE rn = 1;                           -- latest completed order per customer

Window Function Pattern

-- Running total and rank within partition — no self-join required
SELECT
    department_id,
    employee_id,
    salary,
    SUM(salary)  OVER (PARTITION BY department_id ORDER BY hire_date) AS running_payroll,
    RANK()       OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank
FROM employees;

EXPLAIN ANALYZE Interpretation

-- PostgreSQL: always use ANALYZE to see actual row counts vs. estimates
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT *
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.created_at > NOW() - INTERVAL '30 days';

Key things to check in the output:

  • Seq Scan on large table → add or fix an index
  • actual rows ≫ estimated rows → run ANALYZE <table> to refresh statistics
  • Buffers: shared hit vs read → high read count signals missing cache / index

Before / After Optimization Example

-- BEFORE: correlated subquery, one execution per row (slow)
SELECT order_id,
       (SELECT SUM(quantity) FROM order_items oi WHERE oi.order_id = o.id) AS item_count
FROM orders o;

-- AFTER: single aggregation join (fast)
SELECT o.order_id, COALESCE(agg.item_count, 0) AS item_count
FROM orders o
LEFT JOIN (
    SELECT order_id, SUM(quantity) AS item_count
    FROM order_items
    GROUP BY order_id
) agg ON agg.order_id = o.id;

-- Supporting covering index (includes all columns touched by the query)
CREATE INDEX idx_order_items_order_qty
    ON order_items (order_id)
    INCLUDE (quantity);

Constraints

MUST DO

  • Analyze execution plans before recommending optimizations
  • Use set-based operations over row-by-row processing
  • Apply filtering early in query execution (before joins where possible)
  • Use EXISTS over COUNT for existence checks
  • Handle NULLs explicitly in comparisons and aggregations
  • Create covering indexes for frequent queries
  • Test with production-scale data volumes

MUST NOT DO

  • Use SELECT * in production queries
  • Use cursors when set-based operations work
  • Ignore platform-specific optimizations when targeting a specific dialect
  • Implement solutions without considering data volume and cardinality

Output Templates

When implementing SQL solutions, provide: 1. Optimized query with inline comments 2. Required indexes with rationale 3. Execution plan analysis 4. Performance metrics (before/after) 5. Platform-specific notes if applicable

Documentation

Related skills

How it compares

Pick sql-pro for hand-written relational DDL and normalization review rather than ORM-only scaffolding.

FAQ

When should I load the optimization reference?

Load references/optimization.md when reviewing EXPLAIN plans, indexes, statistics, or tuning bottlenecks before recommending changes.

What verification gate does sql-pro require before finishing?

Run EXPLAIN ANALYZE and confirm no sequential scans on large tables; if latency exceeds the sub-100ms target, iterate on indexes or rewrites first.

How does sql-pro handle correlated subqueries?

Replace row-by-row correlated subqueries with set-based aggregation joins and add covering indexes that include all columns the query touches.

Is Sql Pro safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Databasesdatabases

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.