data-analyst-sql-optimization

Optimize slow SQL queries using execution-plan analysis and index recommendations.

1|Updated Nov 11, 2025
One-click install
npx skills add https://github.com/takemi-ohama/ai-agent-marketplace --skill data-analyst-sql-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-analyst-sql-optimization
Source: https://github.com/takemi-ohama/ai-agent-marketplace/tree/main/plugins/ndf/skills/data-analyst-sql-optimization
Command: npx skills add https://github.com/takemi-ohama/ai-agent-marketplace --skill data-analyst-sql-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps SQL analysts optimize slow queries using proven patterns, improving performance and reducing debugging time.

Core Features & Use Cases

  • Optimization pattern library: catalog of common patterns (N+1, index usage, join optimization, window functions, etc.)
  • Before/After examples: show concrete improvements.
  • Index recommendations: guidance on indexing strategies.
  • Execution plan analysis: how to read EXPLAIN and validate improvements.
  • Use Case: optimize a lagging dashboard query to meet SLA.

Quick Start

Provide an example: "optimize this slow query: SELECT * FROM orders WHERE status='completed' AND created_at > '2023-01-01'".

Frequently Asked Questions about data-analyst-sql-optimization

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

FAQPage Schema
How do I optimize slow SQL queries for better performance?

SQL query optimization improves performance by applying proven patterns like indexing, eliminating N+1 queries, and refining JOINs and window functions. Analyze your query's execution plan with EXPLAIN to identify bottlenecks, then apply targeted optimizations such as adding indexes on frequently filtered columns or restructuring joins to reduce data scans.

What's the best way to use indexes to speed up analytics queries?

Indexes accelerate query performance by enabling faster data lookups on frequently filtered or joined columns. Strategy involves analyzing your query's WHERE and JOIN conditions, creating indexes on those columns, and validating improvements through EXPLAIN output to ensure the query planner actually uses the new indexes.

How do I read and interpret SQL EXPLAIN plans to find performance issues?

EXPLAIN plans show how your database executes a query, revealing costly operations like full table scans or inefficient joins. Look for sequential scans on large tables, high row counts, or nested loops; these indicate where indexes or query restructuring can help. Compare EXPLAIN output before and after optimization to measure impact.

Can I fix N+1 query problems and slow dashboard queries with query optimization?

Yes. N+1 problems and slow dashboards typically stem from inefficient query structure or missing indexes. Optimization patterns address both: consolidate multiple queries into single efficient statements, add appropriate indexes, and use window functions or JOINs instead of correlated subqueries to reduce round trips and scans.

What optimization techniques work for both analytics and operational SQL workloads?

Index tuning, JOIN optimization, window-function improvements, and N+1 elimination apply across analytics and operational workloads. These patterns reduce execution time and resource consumption whether queries serve reporting dashboards or production applications, validated through EXPLAIN-based performance comparison.

Do I need database-specific knowledge to optimize SQL queries?

Basic SQL and understanding of your database type help, but proven optimization patterns are largely universal: indexing strategy, JOIN structure, and execution-plan analysis work across PostgreSQL, MySQL, and similar systems. Syntax for EXPLAIN and index creation varies slightly by database, but core concepts remain consistent.