sql-optimization-patterns

Analyze EXPLAIN query plans and apply indexing patterns to optimize SQL performance.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/TrollHeap/dotfiles --skill sql-optimization-patterns-trollheap
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/TrollHeap/dotfiles/tree/main/ai-config/.claude/templates/php-native/.claude/skills/sql-optimization-patterns
Command: npx skills add https://github.com/TrollHeap/dotfiles --skill sql-optimization-patterns-trollheap

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Transform slow database queries into high-performance operations by applying structured optimization patterns, effective indexing, and thoughtful query plans.

Core Features & Use Cases

  • Understand and analyze query plans (EXPLAIN) to identify bottlenecks and guide optimizations.
  • Implement robust indexing strategies (B-Tree, Hash, GIN/ GiST, partial and expression indexes) to improve lookups and joins.
  • Apply common optimization patterns (eliminate N+1 queries, optimize pagination, optimize aggregates, and write efficient joins) to real-world workloads.
  • Use safe, repeatable techniques to reduce latency, lower resource usage, and scale with data growth.

Quick Start

Start by running an EXPLAIN plan on a slow query and applying a targeted index to demonstrate immediate performance gains.

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 query plans to identify SQL performance bottlenecks?

Analyze EXPLAIN query plans by examining execution steps to identify bottlenecks like sequential scans or inefficient joins, guiding targeted indexing and SQL optimization patterns to reduce latency and improve performance.

What's the best way to optimize slow SQL pagination and eliminate N+1 queries?

The best way to optimize slow SQL pagination and eliminate N+1 queries is by applying proven optimization patterns that restructure aggregates and joins, significantly reducing latency and lowering resource usage across workloads.

Does this SQL optimization approach work with PostgreSQL and MySQL/MariaDB?

Yes, this SQL optimization approach works with PostgreSQL and MySQL/MariaDB, providing safe, repeatable techniques to scale with data growth and optimize application performance across general SQL workloads.

How do I implement robust indexing strategies using B-Tree, Hash, or GIN indexes?

Implement robust indexing strategies by crafting B-Tree, Hash, GIN, GiST, partial, or expression indexes to improve lookups and joins, directly addressing slow query performance identified during query plan analysis.

When should I use expression or partial indexes for database tuning?

Use expression or partial indexes for database tuning when query plan analysis reveals bottlenecks in specific lookups or joins, allowing you to apply safe, scalable optimization patterns that reduce resource usage as data grows.