sql-optimization-patterns

Diagnose slow SQL queries and recommend indexes and rewrites.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/Jhabbig/Habbig --skill sql-optimization-patterns-jhabbig
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/Jhabbig/Habbig/tree/main/.claude/plugins/wshobson/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/Jhabbig/Habbig --skill sql-optimization-patterns-jhabbig

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you diagnose and fix slow SQL by identifying inefficient scans, bad joins, missing indexes, and expensive query patterns before they hurt application performance.

Core Features & Use Cases

  • EXPLAIN Analysis: Read query plans to spot sequential scans, costly joins, and misestimated row counts.
  • Index Strategy: Recommend B-tree, composite, partial, expression, covering, and specialized indexes when they will actually help.
  • Query Rewrites: Improve pagination, aggregation, subqueries, and N+1 access patterns with faster alternatives.
  • Use Case: If a dashboard query is timing out on a large table, this Skill can pinpoint the bottleneck and suggest a rewrite plus the right index to make it fast.

Quick Start

Ask the sql optimization patterns skill to review your slow query and propose the best rewrite, index, and EXPLAIN-based tuning steps.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I fix slow SQL queries and improve database performance?

Fix slow SQL queries by analyzing EXPLAIN plans to spot sequential scans, bad joins, and missing indexes, then applying query rewrites and concrete index recommendations to reduce execution time.

How do I read an EXPLAIN plan to find query bottlenecks?

Read an EXPLAIN plan to identify costly joins, sequential scans, and misestimated row counts, which pinpoint the exact database performance bottlenecks slowing down your query execution.

What is the best way to eliminate N+1 queries and optimize pagination?

Eliminate N+1 queries and optimize pagination by rewriting expensive subqueries and aggregations into faster alternatives that reduce unnecessary database scans and improve access patterns.

When should I use composite or partial indexes for query tuning?

Use composite, partial, expression, or covering indexes for query tuning when they directly address expensive scan patterns identified in your EXPLAIN plan and will actually improve execution time.

Does this query optimization approach work for Postgres and other relational databases?

Yes, this query optimization approach works across relational databases including Postgres, applying schema design, index selection, and batch operations to improve query execution and maintenance.