sql-optimization-patterns

Analyze EXPLAIN output and refactor SQL queries with indexing strategies.

1|Updated Jan 20, 2026
One-click install
npx skills add https://github.com/fakhriaditiarahman/Your-Skill-Agent --skill sql-optimization-patterns-fakhriaditiarahman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/fakhriaditiarahman/Your-Skill-Agent/tree/main/.agent/skills/sql-optimization-patterns
Command: npx skills add https://github.com/fakhriaditiarahman/Your-Skill-Agent --skill sql-optimization-patterns-fakhriaditiarahman

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill addresses slow database queries and inefficient database schemas by providing systematic optimization techniques, indexing strategies, and analysis of query execution plans.

Core Features & Use Cases

  • Query Plan Analysis: Understand EXPLAIN output to identify bottlenecks.
  • Indexing Strategies: Learn to create and use various index types (B-Tree, GIN, GiST, etc.) effectively.
  • Query Optimization Patterns: Implement best practices for WHERE clauses, JOINs, pagination, and aggregation.
  • Use Case: When a critical report takes minutes to run, use this Skill to analyze its EXPLAIN plan, identify missing indexes, and refactor the query for sub-second performance.

Quick Start

Use the sql-optimization-patterns skill to analyze the EXPLAIN output for the query 'SELECT * FROM orders WHERE created_at > NOW() - INTERVAL '30 days';'.

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 plan output to identify slow SQL query bottlenecks?

To analyze query execution plans, you must read the EXPLAIN output to identify bottlenecks like sequential scans or inefficient joins. This skill helps pinpoint missing indexes and refactor slow database operations for sub-second performance.

What is the best way to fix N+1 query anti-patterns and offset-based pagination?

The best way to fix N+1 queries and offset-based pagination is through pattern-based refactoring. This skill provides systematic optimization techniques to replace anti-patterns with efficient JOINs and pagination strategies that reduce resource utilization.

When do I need to use GIN or GiST indexes instead of standard B-Tree indexing?

You need GIN or GiST indexes instead of B-Tree indexing when dealing with specific data types or complex query patterns. This skill guides the creation and effective use of various index types to match your schema design and query tuning needs.

How do I optimize SQL queries for high resource utilization and inefficient schema design?

You optimize SQL queries by applying advanced indexing and pattern-based refactoring to address high resource utilization and inefficient schema design. This skill systematically targets slow database operations through query plan analysis and best practice implementation.

Can I use this approach to tune a critical report that currently takes minutes to run?

Yes, you can use this approach to tune critical reports by analyzing their EXPLAIN plan, identifying missing indexes, and refactoring the query. This skill specifically targets transforming slow database operations into sub-second performance.