query-optimization

Analyze EXPLAIN ANALYZE plans and recommend indexing strategies for PostgreSQL and MySQL.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/Ayub-Khan/immortal_agent_swarm --skill query-optimization-ayub-khan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-optimization
Source: https://github.com/Ayub-Khan/immortal_agent_swarm/tree/main/.agents/skills/query-optimization
Command: npx skills add https://github.com/Ayub-Khan/immortal_agent_swarm --skill query-optimization-ayub-khan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps developers and DBAs diagnose and fix slow SQL queries by guiding indexing decisions, plan interpretation, and query rewrites.

Core Features & Use Cases

  • Explain Analyze interpretation: Understand plan costs, row estimates, and actual vs. expected performance.
  • Indexing strategies: Recommend B-tree, GIN, partial, and composite indexes for PostgreSQL and MySQL workloads.
  • N+1 problem solutions: Provide rewrite patterns and join strategies to reduce excessive queries.
  • Query rewriting techniques: Suggest EXISTS, IN optimizations, and clause restructuring to improve index usage.

Quick Start

Provide a sample SQL query and its explain analyze output to receive targeted optimization recommendations.

Frequently Asked Questions about query-optimization

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

FAQPage Schema
How do I interpret EXPLAIN ANALYZE output to fix slow SQL queries?

To interpret EXPLAIN ANALYZE output, examine plan costs, row estimates, and actual versus expected performance metrics to diagnose bottlenecks and guide indexing or query rewriting strategies for SQL optimization.

What is the best way to resolve N+1 query problems in PostgreSQL and MySQL?

The best way to resolve N+1 query problems in PostgreSQL and MySQL is to apply query rewrite patterns and join strategies that consolidate excessive sequential queries into efficient batched data retrieval operations.

How do I choose the right indexing strategy for complex SQL joins?

Choosing an indexing strategy for complex SQL joins involves evaluating workload patterns to select B-tree, GIN, partial, or composite indexes that accelerate table lookups and improve PostgreSQL and MySQL execution plans.

Does query optimization work with both PostgreSQL and MySQL databases?

Yes, query optimization works with both PostgreSQL and MySQL databases by analyzing provided sample schemas, representative queries, and execution plans to deliver actionable indexing and rewriting improvements tailored to each platform.

What do I need to provide to get actionable SQL query tuning recommendations?

You need to provide a sample SQL query, its corresponding EXPLAIN ANALYZE output, and the relevant database schema to receive accurate indexing decisions, query rewrite patterns, and safe optimization guardrails.

When should I use query rewriting techniques instead of adding database indexes?

Use query rewriting techniques like EXISTS, IN optimizations, and clause restructuring instead of adding indexes when you need to improve existing index usage or restructure complex joins without modifying the underlying database schema.