sql-optimization-patterns

Analyze slow SQL queries and recommend indexes using EXPLAIN.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/robinxin/AIFlomo --skill sql-optimization-patterns-robinxin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/robinxin/AIFlomo/tree/main/.claude/skills/sql-optimization-patterns
Command: npx skills add https://github.com/robinxin/AIFlomo --skill sql-optimization-patterns-robinxin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Transform slow database queries into faster operations by applying systematic optimization patterns, proper indexing, and query plan analysis to reduce latency and database load.

Core Features & Use Cases

  • EXPLAIN-driven plan interpretation and cost awareness
  • Index design patterns (B-Tree, composite, partial, expression, covering, and text indexes)
  • Query rewrite patterns to eliminate N+1 queries, optimize joins, and improve aggregation
  • Pagination and batching strategies for scalable data access
  • Advanced techniques like materialized views and partitioning to precompute results

Quick Start

Analyze a slow SQL query and return an optimized plan with concrete index recommendations.

Frequently Asked Questions about sql-optimization-patterns

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

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

To optimize slow SQL queries, use the EXPLAIN command to interpret query plans and identify high-cost operations. This Skill analyzes the plan output to recommend concrete indexing strategies and query rewrites that reduce latency and database load.

What are the best indexing patterns for PostgreSQL and MySQL performance?

The best indexing patterns for PostgreSQL and MySQL performance include B-Tree, composite, partial, expression, covering, and text indexes. This Skill helps select the appropriate index design based on your specific schema and query execution plans.

How can I eliminate N+1 queries and optimize SQL joins?

You can eliminate N+1 queries and optimize SQL joins by applying targeted query rewrite patterns. This Skill identifies inefficient data access loops in your queries and provides batching and join optimization strategies for scalable data retrieval.

Does this SQL optimization approach work with materialized views and partitioning?

Yes, this SQL optimization approach works with materialized views and partitioning. It applies these advanced techniques to precompute results and partition large datasets, significantly improving aggregation performance and overall database scalability.

When should I use pagination and batching strategies for database access?

You should use pagination and batching strategies for database access when dealing with large result sets that cause memory spikes or latency. This Skill implements scalable data access patterns to limit query scope and improve application response times.

Why is my database query slow even with indexes applied?

Your database query might be slow because of suboptimal index design or inefficient query structure. This Skill performs EXPLAIN-driven cost analysis to validate index usage and rewrites queries to ensure the database planner selects the most efficient execution path.