sql-optimization-patterns

Analyze EXPLAIN ANALYZE outputs and implement efficient indexes for slow SQL queries.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/yusoofsh/dotfiles --skill sql-optimization-patterns-yusoofsh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/yusoofsh/dotfiles/tree/main/home/dot_claude/private_plugins/private_marketplaces/claude-code-workflows/plugins/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/yusoofsh/dotfiles --skill sql-optimization-patterns-yusoofsh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill provides systematic methods to identify and eliminate slow SQL queries, dramatically improving database performance, reducing application response times, and enhancing scalability.

Core Features & Use Cases

  • EXPLAIN Analysis: Master interpreting query execution plans to pinpoint performance bottlenecks.
  • Indexing Strategies: Implement B-Tree, composite, partial, and covering indexes for optimal read performance.
  • Query Rewriting: Optimize JOINs, subqueries, and aggregations, and eliminate N+1 query problems.
  • Advanced Techniques: Utilize materialized views and partitioning for extreme performance gains.
  • Use Case: Debug a slow-loading dashboard by analyzing its underlying SQL queries with EXPLAIN ANALYZE, then applying appropriate indexes and query rewrites to achieve sub-second load times.

Quick Start

Use the sql-optimization-patterns skill to generate a PostgreSQL EXPLAIN ANALYZE query for selecting users by email.

Frequently Asked Questions about sql-optimization-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I identify why my SQL queries are running slowly?

Use EXPLAIN ANALYZE to examine query execution plans and pinpoint performance bottlenecks. This shows how the database executes your query, revealing sequential scans, missing indexes, and inefficient JOINs that slow execution.

What indexes should I create to speed up database queries?

Choose B-Tree indexes for standard lookups, composite indexes for multi-column filters, partial indexes for subset queries, and covering indexes to eliminate table lookups. Match index type to your query patterns for optimal read performance.

How do I fix N+1 query problems in my application?

N+1 occurs when one query fetches parent records and subsequent queries fetch related data per row. Resolve it by rewriting queries with efficient JOINs, using batch loading, or implementing cursor-based pagination to fetch related data in fewer round trips.

Can I optimize large datasets without redesigning my schema?

Yes. Apply query rewriting for JOINs and aggregations, add strategic indexes, use materialized views for complex aggregations, and implement partitioning for extremely large tables to maintain performance as data grows.

What's the best way to structure queries to avoid common performance pitfalls?

Avoid SELECT *, design efficient JOINs with proper filtering, use indexed columns in WHERE clauses, optimize aggregation patterns, and implement pagination for result sets. These practices reduce database load and improve application response times.