sql-optimization-patterns

Optimizes SQL queries using EXPLAIN analysis, indexing strategies, and refactoring for relational databases.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill tackles slow database queries and inefficient data retrieval, ensuring your applications run faster and your database resources are used optimally.

Core Features & Use Cases

  • Query Analysis: Understand and interpret EXPLAIN plans to pinpoint bottlenecks.
  • Indexing Strategies: Learn to create and apply effective B-Tree, Hash, GIN, GiST, BRIN, and composite indexes.
  • Query Optimization Patterns: Master techniques like eliminating N+1 queries, optimizing pagination, efficient aggregation, and subquery transformation.
  • Batch Operations: Efficiently handle bulk inserts and updates.
  • Advanced Techniques: Explore materialized views, partitioning, and query hints.
  • Use Case: You're experiencing slow load times on your e-commerce site. Use this Skill to analyze your orders table queries, identify missing indexes, and refactor slow SELECT statements to improve performance.

Quick Start

Use the sql-optimization-patterns skill to analyze a slow SQL query by providing its EXPLAIN plan.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I use EXPLAIN plans to fix slow SQL queries?

To fix slow SQL queries, use EXPLAIN plans to pinpoint execution bottlenecks like full table scans. This Skill analyzes those query plans to pinpoint bottlenecks and applies pattern-based refactoring to resolve them.

What is the best way to eliminate N+1 queries and optimize pagination?

The best way to eliminate N+1 queries and optimize pagination is applying query optimization patterns like subquery transformation and efficient aggregation. This Skill refactors slow SELECT statements using these exact techniques to improve performance.

When do I need composite indexes or materialized views for database optimization?

You need composite indexes or materialized views for database optimization when addressing scalability issues and slow data retrieval in relational databases. This Skill determines effective indexing strategies and when to apply advanced techniques like partitioning.

Does this query tuning approach handle bulk inserts and batch operations?

Yes, this query tuning approach efficiently handles bulk inserts and batch operations. It provides specific patterns for batch operations to ensure your database resources are used optimally during bulk data updates.

Why does my e-commerce site experience slow load times on the orders table?

Your e-commerce site experiences slow load times on the orders table due to missing indexes and inefficient SELECT statements. This Skill identifies missing indexes and refactors slow queries to boost database performance and slash query times.