sql-optimization-patterns

Analyzes SQL EXPLAIN plans to identify bottlenecks and designs indexing strategies for slow queries.

4|Updated Mar 3, 2026
One-click install
npx skills add https://github.com/AI-Foundry-Core/ril-agents --skill sql-optimization-patterns-ai-foundry-core
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/AI-Foundry-Core/ril-agents/tree/main/plugins/developer-essentials/skills/sql-optimization-patterns
Command: npx skills add https://github.com/AI-Foundry-Core/ril-agents --skill sql-optimization-patterns-ai-foundry-core

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill tackles slow SQL queries by providing a structured approach to identify bottlenecks, optimize execution plans, and design effective indexing strategies to improve performance.

Core Features & Use Cases

  • Analyze query plans with EXPLAIN to locate bottlenecks and costly operations.
  • Apply indexing patterns (B-Tree, composite, partial, expression) and query rewrites to reduce work and improve response times.
  • Use patterns for common scenarios such as N+1 avoidance, paginated results, and aggregate optimization; suitable for debugging, schema design, and performance tuning.

Quick Start

Run EXPLAIN on a slow query, identify bottlenecks, then implement an index and query rewrite to improve performance.

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 resolve slow SQL queries using execution plans?

To resolve slow SQL queries, run EXPLAIN to analyze query plans and locate costly operations like bottlenecks. You can then apply targeted indexing strategies and query rewrites to reduce workload and improve response times.

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

The best way to eliminate N+1 queries and optimize pagination is by applying specific SQL patterns like using covering indexes and rewriting queries to batch operations, reducing redundant database calls and improving response times.

Can I use covering indexes and CTEs to improve query performance on relational schemas?

Yes, you can use covering indexes and CTEs to improve query performance on relational schemas. These patterns reduce data lookup overhead and simplify complex aggregate operations, resulting in faster execution.

How do I design effective indexing strategies using B-Tree and composite indexes?

Design effective indexing strategies by analyzing EXPLAIN output to identify bottlenecks, then implementing B-Tree, composite, partial, or expression indexes to match query predicates and reduce execution workload.

When should I use materialized views and partitioning for SQL optimization?

Use materialized views and partitioning for SQL optimization when dealing with heavy aggregate queries or large datasets. These approaches pre-calculate results and divide tables to minimize scan overhead and scale performance.