Skip to content
Back to skills

Query Optimization

ASecurity

Workflow for identifying and fixing slow database queries. Use when a query is slow or the user asks to optimize database performance.

  • 30 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added May 27, 2026
developmentdatabaseperformance

Works with

  • cursor

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add girijashankarj/cursor-handbook --skill query-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Query Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Query Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/girijashankarj-query-optimization/badge)](https://www.skillsdirectory.com/skills/girijashankarj-query-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: query-optimization
description: Workflow for identifying and fixing slow database queries. Use when a query is slow or the user asks to optimize database performance.
---

# Skill: Optimize Database Query

## Trigger
When a query is slow or user asks to optimize database performance.

## Steps

### Step 1: Identify Slow Query
- [ ] Get the query text
- [ ] Measure current execution time
- [ ] Check query frequency (how often it runs)

### Step 2: Analyze Query Plan
- [ ] Run EXPLAIN ANALYZE on the query
- [ ] Identify sequential scans on large tables
- [ ] Check for missing indexes
- [ ] Look for unnecessary joins or subqueries
- [ ] Check sort operations (external sorts)

### Step 3: Optimize
Common optimizations:
- [ ] Add missing indexes
- [ ] Rewrite subqueries as JOINs
- [ ] Add WHERE clause filters to reduce data
- [ ] Use cursor-based pagination instead of OFFSET
- [ ] Add partial indexes for filtered queries
- [ ] Denormalize if read performance is critical

### Step 4: Benchmark
- [ ] Run optimized query with EXPLAIN ANALYZE
- [ ] Compare before/after execution times
- [ ] Test with production-like data volume
- [ ] Verify results are identical

### Step 5: Implement
- [ ] Update query in code
- [ ] Create migration for new indexes
- [ ] Add monitoring for the query
- [ ] Update any affected tests

## Completion
Query optimized with measurable improvement and monitoring in place.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…