optimizing-queries

Analyze and optimize SQL/NoSQL queries with indexing strategies and verification plans.

7|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/galihcitta/dotclaudeskills --skill optimizing-queries
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimizing-queries
Source: https://github.com/galihcitta/dotclaudeskills/tree/main/skills/optimizing-queries
Command: npx skills add https://github.com/galihcitta/dotclaudeskills --skill optimizing-queries

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill tackles the critical issue of slow database performance by automatically identifying and fixing inefficient SQL and NoSQL queries. It helps developers and data professionals improve application responsiveness, reduce database load, and prevent costly performance bottlenecks.

Core Features & Use Cases

  • Multi-Database Support: Analyzes and optimizes queries for a wide range of databases, including PostgreSQL, MySQL, SQLite, MongoDB, Redis, DynamoDB, and Elasticsearch.
  • Anti-Pattern Detection: Automatically flags common performance killers such as SELECT *, N+1 query patterns, large OFFSET values, functions in WHERE clauses, and COLLSCAN in MongoDB.
  • Actionable Recommendations: Provides concrete, copy-pasteable code solutions for creating optimal indexes, rewriting inefficient queries, and implementing ORM eager loading strategies.
  • EXPLAIN Output Analysis: Interprets database execution plans (e.g., EXPLAIN ANALYZE) to pinpoint exact bottlenecks, identify scan types, and verify the impact of optimizations.
  • Codebase Audit: Detects ORM anti-patterns directly in application code and analyzes schema for optimization opportunities like missing foreign key indexes.
  • Use Case: A developer notices a dashboard loading slowly. They provide the SQL query to this skill, which identifies a missing index and an N+1 pattern, then suggests the exact CREATE INDEX statement and an ORM prefetch_related fix, along with EXPLAIN commands to verify the improvement.

Quick Start

Optimize the following SQL query: "SELECT * FROM users WHERE email LIKE '%@example.com' ORDER BY created_at DESC OFFSET 1000 LIMIT 50;"

Frequently Asked Questions about optimizing-queries

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

FAQPage Schema
How do I find and fix slow SQL queries in my database?

Slow SQL queries are identified by analyzing EXPLAIN output to spot full table scans, missing indexes, and N+1 patterns. This Skill reviews your queries against PostgreSQL, MySQL, SQLite, MongoDB, Redis, DynamoDB, and Elasticsearch to pinpoint bottlenecks, then generates concrete rewrites and CREATE INDEX statements you can run immediately.

What are N+1 query patterns and how do I prevent them?

N+1 patterns occur when a single query triggers many additional queries in a loop, typically in ORMs fetching related data. This Skill detects these anti-patterns in your code and provides specific fixes like prefetch_related or eager loading strategies, plus EXPLAIN commands to verify the performance gain.

Can I optimize NoSQL queries like MongoDB and Elasticsearch the same way?

Yes. This Skill analyzes NoSQL performance across MongoDB (detecting COLLSCAN and missing field indexes), Redis, DynamoDB, and Elasticsearch using their native query analysis tools. It flags anti-patterns specific to each database and recommends indexing and access pattern changes with copy-pasteable code.

How do I use EXPLAIN to understand why my queries are slow?

EXPLAIN shows your database's execution plan—scan types, row counts, and join order. This Skill interprets EXPLAIN ANALYZE output to reveal exact bottlenecks like sequential scans instead of index lookups, then recommends indexes or query rewrites and provides verification commands.

What indexing strategies eliminate slow queries without rewriting code?

Missing indexes often cause slow queries. This Skill analyzes your schema and EXPLAIN output to identify which indexes will have the highest impact, generates exact CREATE INDEX statements tailored to your queries, and provides EXPLAIN commands to confirm the performance improvement before deployment.

Does this work with queries that have functions in WHERE clauses or large OFFSET values?

Yes. This Skill detects performance killers like functions in WHERE clauses and large OFFSET pagination, which prevent index use. It flags these anti-patterns and recommends alternative query structures and indexing approaches with measurable performance targets.