sql-optimization-patterns

Analyze PostgreSQL EXPLAIN plans and implement B-Tree, GIN, and composite indexes.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/drgaciw/academic-compliance-hub-glm --skill sql-optimization-patterns-drgaciw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/drgaciw/academic-compliance-hub-glm/tree/main/agents/plugins/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/drgaciw/academic-compliance-hub-glm --skill sql-optimization-patterns-drgaciw

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill helps you diagnose and fix slow database queries, significantly improving application performance and reducing database load.

Core Features & Use Cases

  • Query Plan Analysis: Understand EXPLAIN output to identify bottlenecks.
  • Indexing Strategies: Learn to create effective B-Tree, GIN, and composite indexes.
  • Optimization Patterns: Master techniques like eliminating N+1 queries, cursor-based pagination, and efficient aggregation.
  • Use Case: When a critical report takes minutes to load, use this Skill to analyze the EXPLAIN plan, add the correct indexes, and reduce the load time to seconds.

Quick Start

Use the sql-optimization-patterns skill to analyze the EXPLAIN plan for a slow query.

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 a slow PostgreSQL query using an EXPLAIN plan?

To fix slow query performance, this Skill analyzes PostgreSQL EXPLAIN plans to identify execution bottlenecks like sequential scans. It then recommends specific query rewriting and indexing strategies to reduce load times.

When should I use GIN versus B-Tree indexes for database optimization?

Use B-Tree indexes for standard equality and range queries, and GIN or GiST indexes for composite data types. This Skill guides you in implementing effective indexing strategies based on your specific query patterns.

What is the best way to eliminate N+1 queries in SQL?

Eliminate N+1 queries by applying proven optimization patterns like eager loading and efficient aggregation. This Skill helps you master query rewriting techniques to batch database requests and slash query times.

How do I implement cursor-based pagination to improve query performance?

Implement cursor-based pagination to replace slow OFFSET queries. This Skill teaches proven optimization patterns for efficient SQL pagination that maintains fast database response times on large datasets.

Can this Skill help with schema design for application performance tuning?

Yes, this Skill addresses database schema design and application performance tuning scenarios. It requires understanding of PostgreSQL indexing and query rewriting techniques to optimize SQL performance effectively.

Why is my PostgreSQL query slow despite having indexes?

Slow query performance despite indexes often stems from inefficient execution plans or missing composite indexes. This Skill analyzes your EXPLAIN plan to identify bottlenecks and applies proven optimization patterns to resolve them.