sql-optimization

Diagnose slow SQL queries by analyzing execution plans and recommending indexing strategies.

81|22|Updated Nov 23, 2025
One-click install
npx skills add https://github.com/applied-artificial-intelligence/claude-code-toolkit --skill sql-optimization-applied-artificial-intelligence
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization
Source: https://github.com/applied-artificial-intelligence/claude-code-toolkit/tree/main/skills/general-dev/sql-optimization
Command: npx skills add https://github.com/applied-artificial-intelligence/claude-code-toolkit --skill sql-optimization-applied-artificial-intelligence

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers diagnose and optimize slow SQL queries by analyzing execution plans, recommending indexing strategies, and rewriting queries for better performance.

Core Features & Use Cases

  • EXPLAIN plan interpretation: Inspect actual plans and bottlenecks, such as Seq scans vs Index scans, cost, and actual time.
  • Index design strategies: Propose single-, composite-, partial, and covering indexes to accelerate frequent queries.
  • Query rewriting patterns: Suggest rewrites to avoid N+1 queries, reduce data fetched, and optimize JOINs.
  • Cross-database applicability: Works with PostgreSQL, MySQL, SQLite, and other SQL databases.
  • Use Case: Speed up a reporting query on a large orders table by adding appropriate indexes and rewriting for index-friendly access.

Quick Start

Analyze a slow SQL query and output an optimized version with indexing recommendations.

Frequently Asked Questions about sql-optimization

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

FAQPage Schema
How do I optimize slow SQL queries using EXPLAIN plan analysis?

Analyze EXPLAIN plans to identify bottlenecks like Seq scans, then apply indexing and query rewriting strategies to switch to Index scans and reduce execution cost for slow SQL queries.

What is the best way to design indexes for PostgreSQL and MySQL performance optimization?

Design single, composite, partial, and covering indexes to accelerate frequent queries, ensuring the index semantics match your query predicates to avoid sequential scans and improve database performance.

How do I fix N+1 query problems in SQL databases?

Fix N+1 query problems by applying query rewriting patterns to batch data fetching and optimize JOINs, reducing the number of database round trips and minimizing redundant data retrieval.

Does this SQL optimization approach work with SQLite as well as PostgreSQL?

Yes, the query optimization approach works across PostgreSQL, MySQL, and SQLite by analyzing execution plans and recommending database-agnostic index selection and query rewrites for real-world applications.

When should I use a covering index instead of a composite index for query optimization?

Use a covering index when you want to avoid fetching data from the main table by including all queried columns in the index, whereas a composite index is best for optimizing multi-column filter predicates.