option

Optimizes SQL queries, designs database schemas, and troubleshoots performance issues. Use when a user asks why their query is slow, needs help writing complex joins or aggregations, mentions database performance issues, or wants to design or migrate a schema. Invoke for complex queries, window functions, CTEs, indexing strategies, query plan analysis, covering index creation, recursive queries, EXPLAIN/ANALYZE interpretation, before/after query benchmarking, or migrating queries between databas

...Expand all
57
Updated time June 29, 2026

About sql-pro

SQL Pro is a specialized AI skill designed to enhance database query efficiency, optimize schema design, and troubleshoot performance issues. It addresses common challenges in relational databases where queries run slowly or are difficult to maintain, especially when dealing with complex joins, aggregations, or large datasets. By analyzing SQL queries, execution plans, and indexing strategies, this skill helps users identify bottlenecks and implement best practices to achieve faster and more predictable database performance.

The skill offers a structured workflow that starts with schema analysis, evaluating database structures, indexes, and query patterns to pinpoint performance constraints. It then assists in designing queries using advanced techniques such as Common Table Expressions (CTEs), window functions, and appropriate join strategies. Optimization features include execution plan analysis, creation of covering indexes, elimination of full table scans, and iterative refinement to meet performance targets. SQL Pro also emphasizes verification through `EXPLAIN ANALYZE` outputs, ensuring queries run efficiently and indexes are effectively utilized. Comprehensive documentation of queries, index rationale, and performance metrics is provided to support maintainability and knowledge transfer.

SQL Pro is intended for database administrators, developers, and data engineers who work with PostgreSQL, MySQL, SQL Server, or Oracle databases and require expertise in query tuning, schema migration, or performance optimization. Typical use cases include speeding up slow queries, designing normalized schemas, converting queries between database dialects, analyzing execution plans, and implementing complex analytics without sacrificing efficiency. Its guidance is particularly valuable in scenarios requiring advanced SQL features like recursive queries, window functions, and performance benchmarking, making it a key tool for teams aiming to maintain high-performance, scalable database applications.

FAQ

How do I use SQL Pro to optimize a slow query?

Provide the query and relevant schema information. SQL Pro will analyze execution plans, suggest index improvements, and rewrite queries using efficient patterns such as CTEs or aggregation joins.

Which database systems are supported by SQL Pro?

SQL Pro supports PostgreSQL, MySQL, SQL Server, and Oracle, and includes guidance for differences between these dialects.

Can SQL Pro handle complex analytics queries with window functions?

Yes. It offers guidance for using window functions like ROW_NUMBER, RANK, SUM, and LAG/LEAD efficiently within partitions without unnecessary self-joins.

What should I check when using EXPLAIN ANALYZE with SQL Pro?

Key checks include detecting sequential scans on large tables, comparing actual versus estimated row counts, and reviewing buffer hits and reads to identify missing indexes or stale statistics.

Are there any limitations or prerequisites for using SQL Pro?

Users should have access to database schemas and sufficient privileges to run queries and analyze execution plans. Performance improvements depend on proper indexing, query structure, and database statistics.

View on GitHub

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 readabilityWITH 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_amountFROM ranked_ordersWHERE rn = 1;                           -- latest completed order per customer

Window Function Pattern

-- Running total and rank within partition — no self-join requiredSELECT    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_rankFROM employees;

EXPLAIN ANALYZE Interpretation

-- PostgreSQL: always use ANALYZE to see actual row counts vs. estimatesEXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)SELECT *FROM orders oJOIN customers c ON c.id = o.customer_idWHERE 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_countFROM orders o;-- AFTER: single aggregation join (fast)SELECT o.order_id, COALESCE(agg.item_count, 0) AS item_countFROM orders oLEFT 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

Install sql-pro

Download and extract the skill files to your .claude/skills/ directory.

Download ZIP

Clone the repository and copy the skill files to your project.

git clone https://github.com/Jeffallan/claude-skills/blob/main/skills/sql-pro/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

Copy Copy
Quick Setup: Copy the skill folder to .claude/skills/Claude will automatically detect and use the skill

Related Skills

microservices-patterns
Updated time June 29, 2026
fabric-lakehouse
Updated time June 30, 2026
jpa-patterns
Updated time June 30, 2026
prisma-expert
Updated time June 29, 2026
OR