sql-optimization-patterns

Analyze EXPLAIN plans and implement indexing strategies to optimize SQL queries.

4|Updated Dec 7, 2025
One-click install
npx skills add https://github.com/icartsh/icartsh_plugin --skill sql-optimization-patterns-icartsh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/icartsh/icartsh_plugin/tree/main/icartsh-plugin/skills/sql-optimization-patterns
Command: npx skills add https://github.com/icartsh/icartsh_plugin --skill sql-optimization-patterns-icartsh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill teaches SQL optimization patterns, indexing strategies, and EXPLAIN analysis to eliminate slow queries.

Core Features & Use Cases

  • EXPLAIN analysis: interpret execution plans to identify bottlenecks
  • Index strategies: composite, functional, partial, and covering indexes
  • Query patterns: rewrite patterns to avoid N+1 and expensive sorts

Quick Start

Run EXPLAIN on slow queries, apply indexing strategies, and validate with performance tests.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I identify and fix slow SQL queries?

Use EXPLAIN to analyze query execution plans and identify bottlenecks like sequential scans or missing indexes. EXPLAIN shows where queries spend time, revealing whether to add indexes, rewrite the query, or restructure joins to reduce cost.

What indexing strategies improve database query performance?

Composite, functional, partial, and covering indexes target different query patterns. Composite indexes optimize multi-column filters; covering indexes eliminate table lookups; partial indexes reduce size for filtered datasets; functional indexes speed computed columns.

How do I avoid N+1 query problems?

N+1 occurs when one query loads a parent row, then separate queries load each child. Rewrite using joins, subqueries, or batch loading to fetch related data in one or two queries instead of one-plus-many, dramatically reducing database round trips.

What's the best way to optimize pagination in large result sets?

Use keyset pagination or LIMIT with OFFSET on indexed columns instead of scanning full tables. Keyset pagination fetches only needed rows by comparing previous result boundaries, avoiding expensive sorts and full-table scans.

Can I validate query optimization improvements with performance metrics?

Yes. Measure execution time, row counts examined, and index usage before and after changes. Re-run EXPLAIN and performance tests to confirm improvements are measurable and sustainable across varied data volumes.

When should I design indexes while building a database schema?

Design indexes during schema creation by analyzing expected query patterns, not retroactively. Identify high-frequency filters, joins, and sorts in your application queries, then create supporting indexes to prevent slow queries from deployment.