sql-optimization-patterns

Analyze slow SQL queries with EXPLAIN ANALYZE and apply indexing optimizations.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Slow SQL queries degrade application performance and increase latency; this skill provides structured optimization techniques to speed up data access.

Core Features & Use Cases

  • EXPLAIN/ANALYZE-driven plan analysis to identify bottlenecks and guide indexing decisions.
  • Index strategy design: composite, partial, and covering indexes to support common queries.
  • Pattern optimization: eliminate N+1 queries, optimize pagination, and improve aggregations for large datasets.
  • Use Case: optimize a reporting workload with expensive joins to deliver results faster.

Quick Start

Use the sql-optimization-patterns skill to analyze a slow query by running EXPLAIN ANALYZE on the statement, then apply the recommended indexing and pattern optimizations from the references and examples.

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 ANALYZE?

To optimize slow SQL queries, run EXPLAIN ANALYZE to identify execution plan bottlenecks, then apply indexing strategies and pattern optimizations like efficient joins to reduce latency. This approach guides targeted index design based on actual query plan costs.

When do I need composite or partial indexes for database performance optimization?

You need composite or partial indexes for database performance optimization when supporting common queries with multiple filter conditions or isolating frequently accessed rows. These index strategies reduce scan overhead and accelerate data retrieval for large datasets.

What's the best way to eliminate N+1 queries and optimize SQL pagination?

The best way to eliminate N+1 queries and optimize SQL pagination is to refactor query patterns by batching related data fetches and applying efficient pagination techniques. This prevents redundant database calls and improves application performance.

Does this SQL optimization approach work for reporting workloads with expensive joins?

Yes, this SQL optimization approach works for reporting workloads with expensive joins by analyzing execution plans and applying covering indexes. It transforms slow aggregations and joins into efficient executions to deliver reporting results faster.

Why does avoiding SELECT * improve relational database workload performance?

Avoiding SELECT * improves relational database workload performance by minimizing data transfer and enabling covering indexes to satisfy queries directly. Fetching only required columns reduces memory consumption and speeds up execution.