sql-optimization-patterns

Analyze EXPLAIN output and apply indexing strategies to optimize slow SQL queries.

1|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/AngelP17/factoryops-console --skill sql-optimization-patterns-angelp17
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/AngelP17/factoryops-console/tree/main/factoryops-console/.agent/skills/sql-optimization-patterns
Command: npx skills add https://github.com/AngelP17/factoryops-console --skill sql-optimization-patterns-angelp17

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

SQL performance issues across applications due to slow queries, missing indexes, and inefficient plans.

Core Features & Use Cases

  • Analyze query plans with EXPLAIN to identify bottlenecks and suggest index strategies.
  • Design and apply indexing schemes (B-Tree, partial, expression, and covering) to accelerate common queries.
  • Optimize joins, subqueries, and pagination to reduce latency and resource usage.

Quick Start

Run an EXPLAIN ANALYZE on a slow query to observe cost and timing, then iteratively apply indexing and query rewrites to achieve measurable improvements.

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 why my SQL queries are running slowly?

Use EXPLAIN ANALYZE to view query execution plans, which reveal cost estimates, actual runtime, and bottlenecks like sequential scans or inefficient joins. This output shows where optimization efforts will have the most impact.

What indexing strategies speed up slow database queries?

Apply B-Tree, partial, expression, and covering indexes to accelerate common query patterns. Choose index type based on EXPLAIN output to target sequential scans, full table scans, or specific WHERE and JOIN conditions.

How do I optimize joins and subqueries to reduce query latency?

Restructure joins to match index availability, eliminate unnecessary subqueries, and use materialized views where appropriate. Test each change with EXPLAIN ANALYZE to measure latency reduction and confirm index usage.

Can I apply query optimization to both PostgreSQL and MySQL?

Yes. Both databases use EXPLAIN plans and support B-Tree, partial, and covering indexes, though syntax and plan output differ slightly. Core optimization patterns apply across both platforms.

What should I know before redesigning a schema for performance?

Establish a baseline with EXPLAIN ANALYZE on current queries, identify the highest-impact bottlenecks, and test schema changes in isolation. Validate that index additions and query rewrites reduce application latency without breaking functionality.