sql-optimization-patterns

Analyze EXPLAIN output and implement indexing strategies for SQL query optimization.

Updated Dec 16, 2025
One-click install
npx skills add https://github.com/EanLee/article-write --skill sql-optimization-patterns-eanlee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/EanLee/article-write/tree/main/.github/skills/sql-optimization-patterns
Command: npx skills add https://github.com/EanLee/article-write --skill sql-optimization-patterns-eanlee

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill addresses slow-running database queries and inefficient database performance by providing systematic strategies for optimization, indexing, and query plan analysis.

Core Features & Use Cases

  • Query Plan Analysis: Understand EXPLAIN output to identify bottlenecks.
  • Indexing Strategies: Implement B-Tree, Hash, GIN, GiST, BRIN, and composite indexes effectively.
  • Query Optimization Patterns: Learn to avoid N+1 queries, optimize pagination, aggregate efficiently, and refactor subqueries.
  • Use Case: A web application is experiencing slow load times due to database queries. This Skill can be used to analyze the problematic queries, identify missing indexes, and refactor them for significant performance gains.

Quick Start

Analyze the EXPLAIN output for the following PostgreSQL query to identify performance bottlenecks.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I optimize slow SQL queries causing web application performance issues?

Optimize slow SQL queries by analyzing EXPLAIN plan output to identify bottlenecks, implementing B-Tree or composite indexes, and refactoring subqueries to avoid N+1 query patterns for significant load time reductions.

What is the best way to analyze EXPLAIN plans for PostgreSQL query tuning?

Analyze EXPLAIN plans for PostgreSQL query tuning by reading the execution plan output to identify sequential scans, missing indexes, and inefficient joins, then applying targeted indexing strategies to resolve the identified bottlenecks.

When do I need composite indexes versus B-Tree or Hash indexes for database optimization?

You need composite indexes for multi-column query conditions, B-Tree indexes for standard range and equality searches, and Hash indexes for simple equality lookups, with GIN, GiST, and BRIN serving specialized data types within database optimization.

How can I fix N+1 queries and inefficient pagination in my database schema?

Fix N+1 queries and inefficient pagination by refactoring subqueries into joins, applying efficient aggregation patterns, and implementing index-backed pagination strategies to slash overall query execution times.

Do I need prior knowledge of SQL execution plans to use query optimization patterns?

Yes, effective implementation of query optimization patterns requires an existing understanding of SQL execution plans and indexing techniques to properly interpret EXPLAIN output and design efficient database schemas.

Why does my database query still run slow after adding a standard B-Tree index?

A database query still runs slow after adding a B-Tree index when the EXPLAIN plan reveals function-based filters, inefficient pagination, or N+1 query patterns requiring composite indexes, GIN, GiST, or BRIN index strategies instead.