sql-optimization-patterns

Analyze SQL query plans and apply indexing and rewriting patterns.

Updated Feb 16, 2026
One-click install
npx skills add https://github.com/hwatkins/my-skills --skill sql-optimization-patterns-hwatkins
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/hwatkins/my-skills/tree/main/skills/sql-optimization-patterns
Command: npx skills add https://github.com/hwatkins/my-skills --skill sql-optimization-patterns-hwatkins

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

SQL queries can degrade as data grows, causing high latency and resource usage. This Skill provides a structured set of optimization patterns to identify and fix bottlenecks in query design and execution.

Core Features & Use Cases

  • Query plan analysis with EXPLAIN and EXPLAIN ANALYZE to identify bottlenecks.
  • Indexing strategies (B-Tree, partial indexes, covering indexes) to accelerate lookups.
  • Query rewriting and patterns for avoiding unnecessary data transfer, efficient joins, and optimized aggregations.
  • Use Case: When performance regresses after schema changes or data growth, apply optimization patterns to improve response times in production workloads.

Quick Start

Analyze a batch of representative queries and apply the recommended indexing and rewriting patterns to achieve measurable improvements.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I use EXPLAIN ANALYZE to fix slow PostgreSQL queries?

Use EXPLAIN ANALYZE to identify query execution bottlenecks. This Skill analyzes query plans to find slow operations, then applies indexing and query rewriting patterns to fix SQL performance issues in production workloads.

What are the best SQL optimization patterns for OLTP and OLAP workloads?

SQL optimization patterns for both OLTP and OLAP scenarios include applying B-Tree, partial, and covering indexes, rewriting inefficient joins, and optimizing aggregations to reduce unnecessary data transfer and lower latency.

How do I design indexing strategies to speed up SQL queries after data growth?

Design indexing strategies using B-Tree, partial indexes, and covering indexes to accelerate lookups. As data grows, applying these indexing patterns prevents performance regression and significantly improves query response times.

Can I optimize SQL query patterns for both OLTP and OLAP scenarios?

Yes, this Skill applies query optimization patterns across both OLTP and OLAP scenarios. It analyzes representative query batches to recommend indexing and query rewriting patterns that achieve measurable performance improvements.

Why does query performance regress after schema changes and how do I fix it?

Query performance regresses after schema changes or data growth due to misaligned execution plans. Fix slow SQL by analyzing query plans and applying targeted optimization patterns like index design and query rewriting.

What is the best way to rewrite SQL queries to avoid unnecessary data transfer?

Rewrite SQL queries using optimization patterns that streamline joins and aggregations. This avoids unnecessary data transfer and improves execution efficiency, resulting in measurable latency reductions for production applications.