sql-optimization

Analyze slow SQL queries and recommend index, JOIN, and aggregation optimizations.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill identifies and resolves performance bottlenecks in slow SQL queries, leading to faster database operations and improved application responsiveness.

Core Features & Use Cases

  • Index Analysis: Detects missing or improperly configured indexes that cause full table scans.
  • Query Structure Optimization: Identifies inefficient query patterns like SELECT *, N+1 queries, and complex subqueries.
  • JOIN and Aggregation Tuning: Analyzes join strategies and aggregation methods for performance improvements.
  • Use Case: A developer provides a slow-running SQL query and its schema. The Skill analyzes it, suggests adding a specific index, rewrites a subquery into a more efficient JOIN, and provides the optimized query with predicted performance gains.

Quick Start

Use the sql-optimization skill to analyze and suggest improvements for the following SQL query: [Paste your SQL query here].

Frequently Asked Questions about sql-optimization

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

FAQPage Schema
How do I optimize slow SQL queries and reduce database latency?

To optimize slow SQL queries, you must analyze execution plans and schema definitions to identify missing indexes and inefficient structures. This process detects full table scans and rewrites complex subqueries into efficient JOINs to improve database performance.

What causes a full table scan in my database query execution plan?

A full table scan in a database query execution plan is typically caused by missing or improperly configured indexes. Analyzing the query structure helps detect these indexing issues, allowing you to add targeted indexes and avoid scanning every row.

How do I fix N+1 queries and inefficient query structures in my SQL?

Fixing N+1 queries and inefficient SQL structures requires query analysis to identify problematic patterns like SELECT *. Rewriting these subqueries into efficient JOIN operations and selecting only necessary columns resolves the performance bottleneck.

What information do I need to provide for SQL performance tuning and query analysis?

For SQL performance tuning and query analysis, you need to provide the slow SQL query, the underlying table definitions or schema, EXPLAIN results, and current execution times to generate accurate index recommendations and performance estimations.

Does this SQL query optimization approach work for complex JOIN and aggregation tuning?

Yes, this SQL query optimization approach works for complex JOIN and aggregation tuning by analyzing join strategies and aggregation methods. It identifies inefficient execution patterns and provides rewritten queries with predicted performance gains.

When should I not use query rewriting for database performance optimization?

You should not use query rewriting for database performance optimization when the schema lacks proper indexing, as rewriting alone cannot fix full table scans. Adding the required indexes first is necessary before structural query changes yield predicted performance gains.