sql-optimization-patterns

Analyze EXPLAIN plans and apply indexing patterns to optimize SQL queries.

1|Updated Dec 16, 2025
One-click install
npx skills add https://github.com/pythoninthegrasses/lunchjs --skill sql-optimization-patterns-pythoninthegrasses
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/pythoninthegrasses/lunchjs/tree/main/.claude/skills/sql-optimization-patterns
Command: npx skills add https://github.com/pythoninthegrasses/lunchjs --skill sql-optimization-patterns-pythoninthegrasses

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Helps teams reduce slow SQL queries by providing structured optimization guidance, including EXPLAIN analysis, indexing strategies, and query patterns to apply across common workloads.

Core Features & Use Cases

  • EXPLAIN-driven optimization: Interpret query plans to identify bottlenecks and choose effective indexing and join strategies.
  • Indexing playbook: Build and tune B-tree, partial, composite, and specialized indexes to accelerate critical queries.
  • Pattern library: Apply proven patterns for common issues like N+1 queries, pagination, aggregates, and subqueries to improve throughput.
  • Use Case: When facing slow warehouse or transactional queries, apply the patterns to reduce latency and resource usage.

Quick Start

Run a first-pass analysis of a slow query and apply the recommended indexing and rewriting patterns to your schema and queries.

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 plans to fix slow PostgreSQL queries?

Use this Skill to interpret execution plans and identify bottlenecks like sequential scans or inefficient joins. It guides you through indexing strategies and query rewriting patterns to reduce slow query latency.

What's the best way to design scalable indexes for relational databases?

The best way is to apply an indexing playbook that builds and tunes B-tree, partial, and composite indexes. This Skill helps you select the right index types to accelerate critical queries and improve database throughput.

How can I resolve N+1 query problems and optimize SQL aggregates?

Resolve N+1 query problems and optimize SQL aggregates by applying proven query rewriting patterns from a pattern library. This Skill targets N+1 queries, pagination, and subqueries to improve database throughput.

Does this SQL optimization approach work with MySQL and PostgreSQL?

Yes, this approach works with MySQL and PostgreSQL. It optimizes SQL queries across relational databases to debug slow queries, design scalable schemas, and improve runtime performance.

When should I use partial or composite indexes for database performance?

Use partial or composite indexes when facing slow transactional or warehouse queries that require targeted data access. This Skill helps you build and tune specialized indexes to accelerate critical queries and reduce resource usage.

What do I need to provide to debug slow SQL queries and improve runtime performance?

To debug slow SQL queries, you need to provide EXPLAIN plans, available indexing options, and schema details. This Skill requires these inputs to reason about query plans and apply effective optimization patterns.