sql-optimization-patterns

Analyze EXPLAIN plans and optimize SQL queries with indexing strategies.

2|Updated Jan 18, 2026
One-click install
npx skills add https://github.com/as4584/antigravity-skills --skill sql-optimization-patterns-as4584
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/as4584/antigravity-skills/tree/main/agents-wshobson/plugins/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/as4584/antigravity-skills --skill sql-optimization-patterns-as4584

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill tackles slow database queries and inefficient data retrieval, ensuring your applications run faster and databases are more scalable.

Core Features & Use Cases

  • Query Plan Analysis: Understand EXPLAIN output to pinpoint bottlenecks.
  • Indexing Strategies: Learn to create and use various index types effectively.
  • Optimization Patterns: Implement techniques like eliminating N+1 queries, optimizing pagination, and efficient aggregation.
  • Use Case: Debug a slow-running report by analyzing its EXPLAIN plan, identifying a missing index, creating it, and re-running the query to see a significant performance improvement.

Quick Start

Use the sql-optimization-patterns skill to analyze the explain plan for the query 'SELECT * FROM orders WHERE created_at > NOW() - INTERVAL '30 days';'.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I read an EXPLAIN plan to fix slow SQL queries?

An EXPLAIN plan reveals execution bottlenecks by showing how the database processes your query. The Skill guides you through analyzing this output to pinpoint sequential scans, missing indexes, and inefficient joins causing slow SQL query performance.

What are the best indexing strategies to optimize database performance?

Indexing strategies involve creating targeted index types to accelerate data retrieval. The Skill details how to design and apply these indexes effectively, reducing query times and resolving common performance anti-patterns across PostgreSQL and general SQL databases.

How do I eliminate N+1 queries and optimize pagination in SQL?

Eliminating N+1 queries and optimizing pagination are core optimization patterns. The Skill provides practical techniques to restructure these operations, enabling efficient aggregation and significantly faster data retrieval for complex queries.

Can I use these SQL optimization patterns for PostgreSQL specifically?

Yes, the optimization patterns explicitly support PostgreSQL. The Skill includes practical examples for PostgreSQL alongside general SQL best practices, ensuring the query tuning and indexing strategies apply directly to your database environment.

Why does my database query slow down when filtering by date ranges?

Slow date-range queries often indicate a missing index on the filtered column. The Skill demonstrates analyzing the EXPLAIN plan for such queries, identifying the gap, creating the necessary index, and re-running to achieve a performance improvement.

What should I do to design efficient database schemas for high scalability?

Designing efficient schemas requires applying optimization patterns to prevent performance bottlenecks. The Skill offers comprehensive guidance on structuring schemas and resolving anti-patterns to ensure your databases remain fast and highly scalable.