sql-optimization-patterns

Analyze SQL execution plans and apply indexing and query rewriting techniques.

6|2|Updated Oct 19, 2025
One-click install
npx skills add https://github.com/amurata/cc-tools --skill sql-optimization-patterns-amurata
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/amurata/cc-tools/tree/main/plugins/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/amurata/cc-tools --skill sql-optimization-patterns-amurata

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill helps you diagnose and fix slow database queries, optimize database schemas, and improve overall application performance by applying advanced SQL optimization techniques.

Core Features & Use Cases

  • Query Plan Analysis: Understand EXPLAIN output to identify bottlenecks.
  • Indexing Strategies: Learn to create effective B-Tree, Hash, GIN, GiST, BRIN, and composite indexes.
  • Query Optimization Patterns: Master techniques to avoid N+1 queries, optimize pagination, aggregate efficiently, and refactor subqueries.
  • Batch Operations: Improve performance with batch INSERTs and UPDATEs.
  • Advanced Techniques: Utilize materialized views, partitioning, and query hints.
  • Use Case: You have a critical report that takes minutes to run. Use this Skill to analyze its EXPLAIN plan, identify missing indexes, and rewrite the query for sub-second execution.

Quick Start

Use the sql-optimization-patterns skill to analyze the explain plan for the query 'SELECT * FROM orders WHERE created_at > NOW() - INTERVAL '30 days';'.

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 an EXPLAIN plan to fix slow SQL queries?

Analyzing an EXPLAIN plan identifies SQL execution bottlenecks like sequential scans or inefficient joins. This Skill helps you interpret the output to pinpoint missing indexes and rewrite queries for sub-second execution.

What is the best way to optimize SQL pagination and avoid N+1 query issues?

Optimizing SQL pagination and resolving N+1 queries requires specific patterns like deferred joins or eager loading. This Skill provides query rewriting techniques to aggregate efficiently and refactor subqueries for faster data retrieval.

When do I need to use composite indexes or partitioning for database performance tuning?

Composite indexes and partitioning are needed when single-column indexing fails to handle large-scale data retrieval. This Skill guides you in creating B-Tree, Hash, or BRIN indexes and implementing partitioning to reduce database load.

Can I improve batch INSERT and UPDATE performance in relational databases?

Batch INSERT and UPDATE performance can be improved by grouping operations to minimize transaction overhead. This Skill implements batch processing best practices to enhance database efficiency during bulk data modifications.

How do materialized views and query hints help with SQL query analysis?

Materialized views cache complex query results and query hints guide the SQL execution planner, both reducing query times. This Skill utilizes these advanced techniques alongside strategic indexing to address scalability issues.