sql-optimization-patterns

Identify and optimize slow SQL queries using EXPLAIN plans and indexing strategies.

6|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/linhlinhlin/LMS_hohulili --skill sql-optimization-patterns-linhlinhlin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/linhlinhlin/LMS_hohulili/tree/main/.claude/skills/sql-optimization-patterns
Command: npx skills add https://github.com/linhlinhlin/LMS_hohulili --skill sql-optimization-patterns-linhlinhlin

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Transform slow database queries into fast, scalable operations by using systematic optimization, indexing, and plan analysis.

Core Features & Use Cases

  • Pattern-based optimization: eliminate N+1 queries, rewrite subqueries, and optimize joins for better performance.
  • Indexing and plan analysis: design indexes guided by EXPLAIN ANALYZE outputs to reduce scan costs.
  • Production-ready guidance: scalable techniques for large datasets, evolving schemas, and latency reduction.

Quick Start

Run a targeted optimization pass on a slow query by analyzing its EXPLAIN plan and applying index and rewrite strategies.

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

Optimize slow SQL queries by analyzing EXPLAIN ANALYZE outputs to identify high scan costs, then applying targeted index designs and query rewrites to reduce latency and improve database performance.

What is the best way to eliminate N+1 queries and optimize database joins?

Eliminate N+1 queries and optimize database joins by applying pattern-based query rewrites that consolidate repeated fetches into efficient single-query operations for better performance on large datasets.

Can I use these SQL indexing strategies with both PostgreSQL and MySQL?

Yes, these SQL indexing strategies apply to PostgreSQL, MySQL, and other relational databases, supporting pattern-based optimizations and safe, testable changes across evolving schemas and production workloads.

How do I design indexes to reduce scan costs for large production databases?

Design indexes to reduce scan costs by interpreting EXPLAIN plans to target filtering predicates and join columns, ensuring scalable performance for large production database workloads and latency reduction.

When should I rewrite subqueries instead of adding indexes for database performance?

Rewrite subqueries instead of adding indexes when EXPLAIN ANALYZE reveals inefficient execution plans or nested loop bottlenecks, allowing pattern-based query restructuring to achieve better database performance than indexing alone.