sql-optimization-patterns

Diagnose slow SQL queries and database bottlenecks across PostgreSQL and MySQL.

Updated May 16, 2026
One-click install
npx skills add https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory --skill sql-optimization-patterns-p-o-ke-nae
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization-patterns
Source: https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory/tree/main/.github/skills/sql-optimization-patterns
Command: npx skills add https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory --skill sql-optimization-patterns-p-o-ke-nae

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you find and fix slow SQL by turning opaque query performance issues into concrete optimization actions, so databases respond faster and scale more predictably.

Core Features & Use Cases

  • Execution Plan Analysis: Read EXPLAIN output to identify scans, joins, cost drivers, and missing indexes.
  • Indexing Strategy: Choose the right index type and column order for equality, range, partial, covering, and expression-based access patterns.
  • Query Rewrite Guidance: Improve joins, pagination, aggregates, subqueries, and batch operations to reduce load and latency.
  • Use Case: A backend team notices a dashboard endpoint timing out under load; this Skill can pinpoint the bottleneck query, recommend an index, and suggest a more efficient rewrite.

Quick Start

Ask the SQL optimization skill to analyze your slow query, explain the execution plan, and recommend the best index and rewrite strategy.

Frequently Asked Questions about sql-optimization-patterns

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

FAQPage Schema
How do I read an EXPLAIN plan to find slow SQL queries?

To find slow SQL queries, read the EXPLAIN execution plan output to identify full table scans, nested loop joins, high cost drivers, and missing indexes. Analyzing the execution plan reveals specific bottlenecks causing high database latency under load.

What is the best way to choose indexes for PostgreSQL and MySQL?

The best way to choose indexes for PostgreSQL and MySQL is matching index types and column orders to specific access patterns. Select covering, partial, expression-based, or range indexes based on equality and range queries in your workload.

Does this query optimization approach work for both PostgreSQL and MySQL workloads?

Yes, this query optimization approach works for both PostgreSQL and MySQL workloads. It diagnoses execution plans, indexing decisions, pagination tuning, joins, and partitioning strategies across both database platforms to reduce latency and improve scalability.

How do I rewrite SQL pagination and aggregation queries to reduce latency?

To rewrite SQL pagination and aggregation queries to reduce latency, replace offset-based pagination with keyset pagination, optimize join structures, and use materialized views for heavy aggregates. These query rewrites minimize load and improve response times.

When should I use partitioning or materialized views for database performance?

Use partitioning or materialized views for database performance when query rewrites and standard indexing cannot handle large data volumes. Partitioning splits large tables for faster scans, while materialized views precompute aggregations to eliminate runtime bottlenecks.