aj-geddes avatar

Sql Query Optimization

This handles the mechanical work of SQL optimization: analyzing EXPLAIN plans, spotting missing indexes, and rewriting queries that perform poorly. You'd reach for it when a query is taking too long and you need to understand why, or when you're trying to figure out if an index is actually being used. It covers both PostgreSQL and MySQL, focuses on practical patterns like join optimization and subquery flattening, and includes the buffer analysis you need for real diagnostics. The approach is systematic rather than clever, which is exactly right for performance work. If you're comfortable reading query plans yourself, you might not need it, but it's solid for catching the common mistakes that slow down most applications.

skills.sh installs
527
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill sql-query-optimization --agent claude-code

Installs into .claude/skills of the current project.

Files

SQL Query Optimization

Table of Contents

Overview

Analyze SQL queries to identify performance bottlenecks and implement optimization techniques. Includes query analysis, indexing strategies, and rewriting patterns for improved performance.

When to Use

  • Slow query analysis and tuning
  • Query rewriting and refactoring
  • Index utilization verification
  • Join optimization
  • Subquery optimization
  • Query plan analysis (EXPLAIN)
  • Performance baseline establishment

Quick Start

PostgreSQL:

-- Analyze query plan with execution time
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
SELECT u.id, u.email, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at > NOW() - INTERVAL '1 year'
GROUP BY u.id, u.email;

-- Check table statistics
SELECT * FROM pg_stats
WHERE tablename = 'users' AND attname = 'created_at';

Reference Guides

Detailed implementations in the references/ directory:

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, AI & Agent Building, Debugging, Databases
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1sanjay3290 avatargmailsanjay3290/ai-skillsInteract with Gmail - search emails, read messages, send emails, create drafts, and manage labels. Use when user asks to: search email, read email, send email, 525skills.sh installs
2wanshuiyin avatarauto-review-loop-llmwanshuiyin/auto-claude-code-research-in-sleepAutonomous research review loop using any OpenAI-compatible LLM API. Configure via llm-chat MCP server or environment variables. Trigger with "auto review loop 525skills.sh installs
3libukai avatarvscode-httpyac-configlibukai/awesome-agent-skillsConfigure VSCode with httpYac for API testing and automation. This skill should be used specifically when converting API documentation to executable .http files513skills.sh installs
4cfircoo avatarsqlalchemy-postgrescfircoo/claude-code-toolkitExpert guidance for SQLAlchemy 2.0 + Pydantic + PostgreSQL. Use when setting up database layers, defining models, creating migrations, or any database-related w507skills.sh installs
5hkuds avatarcli-anything-adguardhomehkuds/cli-anythingCommand-line interface for AdGuard Home - Network-wide ad blocking and DNS management via AdGuard Home REST API. Designed for AI agents and power users who need507skills.sh installs
6kernel avatarkernel-clikernel/skillsUse the Kernel CLI to manage cloud browsers, apps, profiles, proxies, managed auth, API keys, projects, and organization limits. Use when installing or authenti507skills.sh installs