sql-optimization-patterns

Optimize SQL query performance with indexing strategies and EXPLAIN analysis.

Updated Jan 20, 2026
One-click install
npx skills add https://github.com/ollieb89/ugro --skill sql-optimization-patterns-ollieb89
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/ollieb89/ugro/tree/main/.windsurf/skills/sql-optimization-patterns
Command: npx skills add https://github.com/ollieb89/ugro --skill sql-optimization-patterns-ollieb89

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This skill helps teams dramatically improve database performance by providing structured SQL optimization patterns, indexing guidance, and explain-plan analysis.

Core Features & Use Cases

  • Explain-driven optimization: Interpret EXPLAIN plans to locate bottlenecks and propose concrete improvements.
  • Indexing strategies: Apply B-tree, partial, composite, and covering indexes to reduce scan cost.
  • Query-patterns and refactoring: Replace bad patterns (SELECT * , Cartesian joins) with targeted queries and efficient joins.
  • Performance validation: Use query plans and lightweight benchmarks to verify gains.

Quick Start

Use the included analysis scripts against your database to identify slow queries and apply index recommendations by executing scripts/analyze-slow-queries.sql and scripts/index-recommendations.sql.

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 in PostgreSQL or MySQL?

SQL query optimization uses EXPLAIN plans to identify bottlenecks, then applies indexing strategies and refactors inefficient patterns. Interpret EXPLAIN output to locate sequential scans or expensive joins, then create B-tree, partial, or composite indexes and replace bad patterns like SELECT * with targeted queries to reduce execution time.

What indexing strategies reduce SQL query execution time?

Indexing strategies include B-tree indexes for range queries, partial indexes for filtered subsets, composite indexes for multi-column lookups, and covering indexes to satisfy queries without table access. Apply these based on EXPLAIN analysis to eliminate full table scans and lower query cost.

How do I read and interpret SQL EXPLAIN plans?

EXPLAIN plans show query execution steps, scan types, row estimates, and cost metrics. Sequential scans indicate missing indexes; nested loops suggest join optimization; high actual-vs-estimated rows signal stale statistics. Use these insights to propose index creation or query refactoring.

Can I use these SQL optimization patterns for database performance debugging?

Yes. This approach applies to debugging slow queries by running EXPLAIN analysis, identifying inefficient scans or joins, recommending indexes, and validating improvements through query plans and lightweight benchmarks across PostgreSQL and MySQL.

What SQL query patterns should I avoid for better performance?

Avoid SELECT * on large tables, Cartesian joins from missing join conditions, and unindexed WHERE clauses on high-cardinality columns. Replace these with targeted column selection, explicit join conditions, and strategic indexing to reduce scan cost and improve latency.