sql-optimization-patterns

Optimize slow PostgreSQL and MySQL queries using EXPLAIN analysis and indexing strategies.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill helps database teams quickly identify and fix slow SQL queries by applying a structured set of optimization patterns, indexing strategies, and EXPLAIN-driven analysis.

Core Features & Use Cases

  • EXPLAIN-driven analysis: interpret query plans to spot bottlenecks and choose fixes.
  • Indexing strategies: design and implement effective indexes, including composite and partial indexes.
  • Query rewrite patterns: apply best-practice rewrites to eliminate N+1 queries, optimize joins, and improve pagination.
  • Use Case: When facing slow analytical reports or high-latency transactional queries, run the skill to optimize queries in PostgreSQL or MySQL.

Quick Start

Get a slow query sample, run through the optimization patterns, and apply recommended changes to a test database.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I optimize slow SQL queries using EXPLAIN analysis?

To optimize slow SQL queries, you apply proven optimization patterns by interpreting EXPLAIN outputs to spot bottlenecks, designing effective indexes, and rewriting queries to eliminate inefficiencies in PostgreSQL or MySQL workloads.

What's the best way to fix N+1 queries and improve database pagination?

The best way to fix N+1 queries and improve pagination is by applying best-practice query rewrite patterns, which restructure joins and pagination logic to reduce database round trips and latency.

Does this SQL query optimization approach work with both PostgreSQL and MySQL?

Yes, this SQL query optimization approach works with PostgreSQL, MySQL, or compatible engines, requiring access to EXPLAIN outputs, indexing capabilities, and non-destructive query rewrites across analytics and transactional applications.

When do I need to use composite and partial indexes for database tuning?

You need composite and partial indexes for database tuning when EXPLAIN-driven analysis reveals query bottlenecks that single-column indexes cannot resolve, particularly in high-latency transactional queries or slow analytical reports.

Can I use non-destructive query rewrites to speed up slow analytical reports?

Yes, you can use non-destructive query rewrites to speed up slow analytical reports by applying structured optimization patterns that improve join efficiency and eliminate N+1 queries without altering underlying database schema.