sql-optimization-patterns

Optimize slow SQL queries using EXPLAIN analysis and indexing strategies.

1|Updated Nov 23, 2025
One-click install
npx skills add https://github.com/zmre/nix-pai --skill sql-optimization-patterns-zmre
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/zmre/nix-pai/tree/main/claude/skills/developer-essentials/sql-optimization-patterns
Command: npx skills add https://github.com/zmre/nix-pai --skill sql-optimization-patterns-zmre

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Slow SQL queries can severely impact application performance and user experience. This skill provides advanced patterns and techniques to optimize your SQL queries and database schema, ensuring faster data retrieval and a more responsive application.

Core Features & Use Cases

  • Indexing Strategies: Best practices for creating and managing indexes to speed up queries significantly.
  • Query Rewriting: Techniques for refactoring inefficient queries into optimized forms, reducing execution time.
  • Execution Plan Analysis: Guidance on interpreting database execution plans to identify bottlenecks and areas for improvement.
  • Use Case: Your application's dashboard is loading slowly due to complex database queries. Use this skill to analyze the query execution plans, identify missing indexes, and rewrite inefficient joins to drastically improve dashboard load times.

Quick Start

Use the sql-optimization-patterns skill to explain how to use indexes effectively to speed up database queries.

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 and fix slow SQL queries in my application?

Slow SQL queries are identified using EXPLAIN analysis to review execution plans for bottlenecks. Fix them by adding appropriate indexes (B-Tree, Hash, GIN, GiST, BRIN), refactoring inefficient joins, eliminating N+1 patterns, and optimizing aggregations to reduce execution time and improve application responsiveness.

What indexing strategies improve database query performance?

Indexing strategies involve selecting the right index type for your data and query patterns—B-Tree indexes for range queries, Hash indexes for equality lookups, and specialized indexes like GIN or GiST for complex data types. Proper index placement dramatically accelerates data retrieval on relational databases.

How do I optimize schema design for better database performance?

Schema optimization focuses on structuring tables and relationships to enable efficient queries. This includes proper normalization, strategic denormalization where needed, and designing indexes alongside schema layout to ensure queries can access data with minimal disk I/O and computation.

Can I reduce query execution time by rewriting inefficient joins?

Yes. Inefficient joins often stem from N+1 queries or poor join conditions. Rewriting queries to use single optimized joins, proper filtering before joins, and leveraging indexes on join columns reduces execution time significantly and improves dashboard and report load times.

What's the best way to implement pagination in SQL queries?

Pagination patterns use LIMIT and OFFSET clauses efficiently by avoiding full table scans. Combined with proper indexes on sort columns and filtering predicates, pagination ensures consistent query performance regardless of result set size.

How do I interpret SQL execution plans to find performance bottlenecks?

Execution plan analysis reveals which operations consume the most resources—sequential scans, missing indexes, or suboptimal join orders. Reading plans identifies specific bottlenecks, guiding decisions on index creation, query restructuring, and schema adjustments.