wshobson avatar

Sql Optimization Patterns

This walks you through the core SQL optimization techniques that actually move the needle on query performance. It covers reading EXPLAIN plans, building the right indexes (including partial and covering indexes), eliminating N+1 queries, and fixing slow pagination with cursor-based approaches. The examples show real before/after query patterns for common problems like correlated subqueries and inefficient JOINs. What I like is that it focuses on systematic debugging rather than random performance tweaks. Use this when you're staring at slow queries in production or designing schemas that need to scale.

install copies · 90 days. Times the install command was copied on this site in the last 90 days, bots filtered.
13
skills.sh installs
20.4K
GitHub stars
42.4K
last updated
Aug 21, 2026

Install

$ npx -y skills add wshobson/agents --skill sql-optimization-patterns --agent claude-code

Installs into .claude/skills of the current project.

Files

SQL Optimization Patterns

Transform slow database queries into lightning-fast operations through systematic optimization, proper indexing, and query plan analysis.

When to Use This Skill

  • Debugging slow-running queries
  • Designing performant database schemas
  • Optimizing application response times
  • Reducing database load and costs
  • Improving scalability for growing datasets
  • Analyzing EXPLAIN query plans
  • Implementing efficient indexes
  • Resolving N+1 query problems

Core Concepts

1. Query Execution Plans (EXPLAIN)

Understanding EXPLAIN output is fundamental to optimization.

PostgreSQL EXPLAIN:

-- Basic explain
EXPLAIN SELECT * FROM users WHERE email = 'user@example.com';

-- With actual execution stats
EXPLAIN ANALYZE
SELECT * FROM users WHERE email = 'user@example.com';

-- Verbose output with more details
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT u.*, o.order_total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.created_at > NOW() - INTERVAL '30 days';

Key Metrics to Watch:

Sponsors

Details

Repository
github.com/wshobson/agents
Categories
Backend & APIs, Documentation, Debugging, Databases

More from wshobson/agents

All 174
1pilioai avatargpt-image-2pilioai/skillsCreate or edit images with Pilio GPT Image 2 through the unified Pilio developer API. Use when the user wants text-to-image generation, prompt-based image editi20.4Kskills.sh installs
2yuan1z0825 avatarnature-figureyuan1z0825/nature-skillsCreate, revise, audit, and export submission-grade scientific figures for Nature-family and other high-impact venues in Python (matplotlib/seaborn) or R (ggplot19.9Kskills.sh installs
3mintlify avatarmintlifymintlify/docsComprehensive reference for building Mintlify documentation sites. Use when creating pages, configuring docs.json, adding components, setting up navigation, or 19.7Kskills.sh installs
4gmgnai avatargmgn-marketgmgnai/gmgn-skillsGet crypto and meme token price charts (K-line, candlestick, OHLCV), trending meme coin rankings by volume, newly launched tokens on launchpads (pump.fun, fourm19.4Kskills.sh installs
5gmgnai avatargmgn-tokengmgnai/gmgn-skillsResearch any crypto or meme token by address — real-time price, market cap, liquidity, holder list, trader list, top Smart Money and KOL positions, security aud19.4Kskills.sh installs
6warpdotdev avatarwrite-feature-docswarpdotdev/common-skillsDraft a complete documentation page for a new Warp feature from its PRODUCT.md and/or TECH.md spec. Use when an engineer has written a spec and needs to produce19.3Kskills.sh installs