Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Database Query Optimization

  • 525 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

database-query-optimization is a Claude Code skill that diagnoses and accelerates slow SQL queries using EXPLAIN ANALYZE, indexing strategies, and execution plan review for developers who need to cut database latency and

About

database-query-optimization is a structured performance skill from aj-geddes/useful-ai-prompts that walks developers through systematic SQL diagnosis and remediation. The skill covers EXPLAIN ANALYZE interpretation, indexing strategies, efficient query rewrites, and execution plan review to reduce response times and database CPU usage. Reference guides and best-practice sections address slow endpoints, performance regressions, and high-load scenarios common in API-backed applications. Developers reach for database-query-optimization when profiling shows database-bound latency, when new features introduce expensive joins or scans, or when production monitoring flags rising query times. The workflow emphasizes measurable before-and-after plans rather than ad-hoc query tweaks.

  • Analyzes EXPLAIN ANALYZE output to distinguish Seq Scan vs Index Scan performance
  • Identifies high-variance row estimates, nested loops, and expensive sorts
  • Recommends indexing, query rewrites, and caching patterns for production workloads
  • Applies to new feature deployments, performance regressions, and scheduled maintenance
  • Reduces response times and database CPU usage across Postgres, MySQL and compatible engines

Database Query Optimization by the numbers

  • 525 all-time installs (skills.sh)
  • Ranked #120 of 911 Databases skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill database-query-optimization

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs525
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you optimize slow SQL queries with EXPLAIN?

Systematically diagnose and accelerate slow SQL queries using EXPLAIN ANALYZE, indexing strategies, and execution plan review.

Who is it for?

Backend developers maintaining PostgreSQL, MySQL, or similar relational databases with measurable slow-query bottlenecks.

Skip if: Developers needing NoSQL schema design, full database migration planning, or ORM framework selection without SQL-level tuning.

When should I use this skill?

A developer reports slow API responses, high database CPU, or asks to analyze, index, or rewrite specific SQL queries.

What you get

Execution plans, index recommendations, rewritten queries, and documented performance improvements.

  • Optimized SQL statements
  • Index recommendations
  • Execution plan analysis notes

Files

SKILL.mdMarkdownGitHub ↗

Database Query Optimization

Table of Contents

Overview

Slow database queries are a common performance bottleneck. Optimization through indexing, efficient queries, and caching dramatically improves application performance.

When to Use

  • Slow response times
  • High database CPU usage
  • Performance regression
  • New feature deployment
  • Regular maintenance

Quick Start

Minimal working example:

-- Analyze query performance

EXPLAIN ANALYZE
SELECT users.id, users.name, COUNT(orders.id) as order_count
FROM users
LEFT JOIN orders ON users.id = orders.user_id
WHERE users.created_at > '2024-01-01'
GROUP BY users.id, users.name
ORDER BY order_count DESC;

-- Results show:
-- - Seq Scan (slow) vs Index Scan (fast)
-- - Rows: actual vs planned (high variance = bad)
-- - Execution time (milliseconds)

-- Key metrics:
-- - Sequential Scan: Full table read (slow)
-- - Index Scan: Uses index (fast)
-- - Nested Loop: Joins with loops
-- - Sort: In-memory or disk sort

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Query AnalysisQuery Analysis
Indexing StrategyIndexing Strategy
Query Optimization TechniquesQuery Optimization Techniques
Optimization ChecklistOptimization Checklist

Best Practices

✅ DO

  • Follow established patterns and conventions
  • Write clean, maintainable code
  • Add appropriate documentation
  • Test thoroughly before deploying

❌ DON'T

  • Skip testing or validation
  • Ignore error handling
  • Hard-code configuration values

Related skills

How it compares

Pick database-query-optimization for hands-on SQL plan and index work rather than general application profiling or ORM configuration guides.

FAQ

What does database-query-optimization analyze first?

database-query-optimization starts with EXPLAIN ANALYZE and execution plan review to locate sequential scans, missing indexes, and expensive joins before proposing index or rewrite changes.

When should developers use database-query-optimization?

database-query-optimization fits slow API endpoints, rising database CPU, and post-release performance regressions where SQL—not application logic—is the suspected bottleneck.

Databasesbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.