sql-optimization-patterns

Analyze SQL execution plans and apply indexing and query rewrites.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

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

Core Features & Use Cases

  • Understand and interpret EXPLAIN plans to identify bottlenecks
  • Design and apply effective indexing strategies (B-tree, partial, composite)
  • Rewrite queries to minimize scans, leverage joins, and improve performance
  • Optimize for common patterns such as N+1 queries, paging, aggregations, and large data sets
  • Use materialized views, partitioning, and index-only scans to accelerate workloads

Quick Start

Provide a slow SQL query and I will analyze the execution plan and propose indexing and rewriting steps to optimize it.

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 execution plans?

To optimize slow SQL queries, you analyze EXPLAIN plans to identify bottlenecks, then apply indexing strategies and rewrite queries to minimize scans and improve performance across PostgreSQL, MySQL, or similar relational databases.

What is the best way to fix N+1 query problems in a relational database?

Fixing N+1 query problems involves rewriting queries to leverage joins and minimize sequential scans, then applying composite indexes to accelerate the joined workloads and reduce application throughput bottlenecks.

How do I use indexing strategies to speed up database performance?

Speed up database performance by designing and applying effective indexing strategies like B-tree, partial, and composite indexes, which support index-only scans and accelerate data retrieval for large datasets.

Can I use materialized views and partitioning to optimize large data sets in PostgreSQL?

Yes, you can optimize large data sets in PostgreSQL by using materialized views, partitioning, and index-only scans to accelerate workloads and transform slow database operations into scalable operations.

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

Yes, this query optimization approach works across PostgreSQL, MySQL, or similar relational databases, requiring access to EXPLAIN plans and the ability to apply indexing and query rewrites to improve performance.

When should I rewrite a query instead of adding an index to improve SQL performance?

You should rewrite a query instead of adding an index when EXPLAIN plans reveal inefficient patterns like N+1 queries or unnecessary aggregations, where rewriting to leverage joins and minimize scans yields better throughput than indexing alone.