sql-query-optimizer

Analyzes and optimizes SQL queries using EXPLAIN plans, index recommendations, and query rewrites.

2|Updated Jun 5, 2026
One-click install
npx skills add https://github.com/sathishssj3/NexVR-Engine --skill sql-query-optimizer-sathishssj3
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sql-query-optimizer
Source: https://github.com/sathishssj3/NexVR-Engine/tree/main/.agents/skills/sql-query-optimizer
Command: npx skills add https://github.com/sathishssj3/NexVR-Engine --skill sql-query-optimizer-sathishssj3

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @prisma/client.

What problem does it solve? Slow SQL queries degrade application performance, and diagnosing them requires expertise in reading EXPLAIN plans, choosing indexes, and rewriting queries. This Skill provides a structured workflow for identifying bottlenecks and applying proven optimizations. ## Core Features & Use Cases - EXPLAIN Plan Analysis: Interpret query execution plans to spot sequential scans, missing indexes, and expensive joins. - Index Recommendations: Create single-column, composite, covering, and functional indexes matched to query patterns. - Query Rewrites: Replace SELECT *, IN subqueries, and functions on indexed columns with faster equivalents. - Benchmarking & Detection: Measure before/after performance with TypeScript scripts and detect slow queries via pg_stat_statements. - Use Case: A dashboard endpoint takes 250ms because of a sequential scan on the orders table; use this Skill to add an index on user_id and cut execution time to under 1ms. ## Quick Start Analyze this slow PostgreSQL query with EXPLAIN ANALYZE and recommend indexes and rewrites to improve its performance.

Frequently Asked Questions about sql-query-optimizer

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

FAQPage Schema
How do I optimize a slow SQL query?▼

Run EXPLAIN ANALYZE on the query to identify sequential scans and expensive operations, then add indexes on filtered or joined columns and rewrite the query to fetch only needed columns. Benchmark before and after to measure improvement.

How to read a PostgreSQL EXPLAIN ANALYZE plan?▼

Look for Seq Scan nodes on large tables, high row counts removed by filters, and costly sort or hash operations. These indicate missing indexes or inefficient joins that should be addressed first.

Should I use EXISTS or IN for SQL subqueries?▼

EXISTS is generally faster because it short-circuits on the first matching row, while IN evaluates the full subquery. On large datasets, rewriting IN as EXISTS can be roughly three times faster.

Why is my index not being used by the query planner?▼

Indexes are skipped when functions wrap the indexed column, such as LOWER(email), or when the query filter does not match the leading columns of a composite index. Use a functional index or reorder composite index columns to match the query pattern.

How do I find slow queries in PostgreSQL?▼

Enable slow query logging with log_min_duration_statement and query pg_stat_statements for statements with high mean execution time. Sort by mean_exec_time to prioritize the worst offenders.

What is a covering index and when should I use one?▼

A covering index includes all columns a query needs, created with the INCLUDE clause, enabling index-only scans without touching the table. Use it for frequent queries that read a small, fixed set of columns.