sql-optimization-patterns

Analyze EXPLAIN output and apply indexing strategies to optimize SQL query performance.

38.6k|4.1k|Updated Jul 24, 2025
One-click install
npx skills add https://github.com/wshobson/agents --skill sql-optimization-patterns-wshobson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/wshobson/agents/tree/main/plugins/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/wshobson/agents --skill sql-optimization-patterns-wshobson

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses slow database queries and inefficient data retrieval by providing strategies for optimization, indexing, and performance analysis.

Core Features & Use Cases

  • Query Plan Analysis: Understand EXPLAIN output to identify bottlenecks.
  • Indexing Strategies: Learn to create effective B-Tree, Hash, GIN, GiST, and BRIN indexes.
  • Query Optimization Patterns: Apply techniques to avoid N+1 queries, optimize pagination, and improve aggregation.
  • Use Case: When a critical report is taking too long to load, use this Skill to analyze the SQL query, identify missing indexes, and refactor the query for significant performance gains.

Quick Start

Analyze the EXPLAIN plan for the following SQL query: SELECT * FROM orders WHERE order_date > '2023-01-01';

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I analyze EXPLAIN output to identify SQL query bottlenecks?

Analyze EXPLAIN output to identify SQL query bottlenecks by reviewing execution plan operations, scanning for sequential scans on large tables, and evaluating join methods. This Skill helps interpret query plans to pinpoint slow database operations and missing indexes.

What's the best way to optimize slow PostgreSQL queries with indexing strategies?

The best way to optimize slow PostgreSQL queries is applying advanced indexing strategies like composite indexes, partial indexes, and specialized types such as GIN, GiST, and BRIN. This Skill guides creating effective indexes to slash query times and improve data retrieval.

How do I fix N+1 queries and inefficient pagination in SQL databases?

Fix N+1 queries and inefficient pagination in SQL databases by applying pattern-based refactoring techniques. This Skill provides query optimization patterns to restructure data retrieval, eliminate redundant queries, and improve aggregation performance.

When do I need to use composite indexes versus partial indexes for SQL optimization?

Use composite indexes for multi-column filtering and partial indexes for specific query subsets to achieve SQL optimization. This Skill helps determine the appropriate indexing strategy by analyzing query plans and schema design for improved application responsiveness.

Can I use these SQL query tuning patterns for databases other than PostgreSQL?

Yes, you can use these SQL query tuning patterns for databases other than PostgreSQL. While the Skill focuses on PostgreSQL features like GIN and BRIN indexes, the core query plan analysis, indexing strategies, and pattern-based refactoring apply to other SQL databases.