sql-query-optimizer
SkillDatabases & dataAnalyzes SQL queries, execution plans, index usage, and lock contention to optimize database operations.
Instructions available. Your AI can read the instructions. Execution depends on the setup they require.
Account requirements not reviewed. Check the skill instructions before use; ahel provides instructions and does not run this skill.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
Then ask your AI: use the sql-query-optimizer skill
What this skill tells your AI
The instructions your AI receives, as published by codebygarv/ai-skills in skills/development/sql-query-optimizer/SKILL.md and read by ahel’s review.
Purpose
Analyze slow or resource-intensive SQL queries, interpret EXPLAIN / ANALYZE execution plans, and rewrite queries or recommend precise indexes to eliminate sequential scans and lock contention.
When to Use
- A query causes high CPU, memory pressure, or connection saturation on the database.
- Designing complex joins, aggregations, window functions, or subqueries.
- Diagnosing deadlocks or table lock contention under concurrent writes.
What to Analyze
- Execution Plan: Inspect cost nodes, Seq Scans, Index Scans, Bitmap Index Scans, Nested Loops vs Hash Joins.
- Predicate SARGability: Identify functions on indexed columns (e.g.
WHERE DATE(created_at) = ...) preventing index hits. - Join & Subquery Efficiency: Convert correlated subqueries to CTEs, Window Functions, or Hash Joins.
- Indexing Strategy: Single-column, composite (ordering column matches query pattern), partial, or covering indexes.
- Pagination Mechanics: Replace large offset pagination (
OFFSET 100000) with keyset/cursor pagination.
Output Format
- Diagnosis: Why the query is slow (missing index, scan type, cardinality misestimate).
- Optimized SQL: Clean rewritten query with explanation.
- DDL Changes: Exact
CREATE INDEX CONCURRENTLYstatements needed. - Before vs After Metrics: Expected scan cost reduction and latency impact.
Avoid
- Adding indexes on every column without considering write throughput degradation.
- Omitting
CONCURRENTLYon production index creation statements.
Signals
- GitHub stars
- 26
- Forks
- 1
- Last commit
- Aug 2026
Others that do the same job
Advanced
- Item type
- skill
- Key
sql-query-optimizer-codebygarv- Source
- github.com/codebygarv/ai-skills
github.com/codebygarv/ai-skills
Related picks
Skill · supabase
The pick for Postgressupabase
Skill · supabase
More in Databases & dataconnect
Skill · composiohq
More in Databases & dataanalytics
Skill · coreyhaines31
More in Databases & dataazure-kusto
Skill · microsoft
More in Databases & dataagentic-os
Skill · affaan-m
More in Databases & data