Skip to content
Back to skills

Sql Optimization

ASecurity

SQL query optimization — reading execution plans, index design (composite order, covering, partial), N+1 detection, join strategies, pagination (keyset), statistics, avoiding functions on indexed columns, batching, measuring under realistic data. Use for slow queries or query review (SQL optimization, EXPLAIN, slow query, index, N+1, keyset pagination).

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentsgosqlperformance

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add vectora-os/kit --skill sql-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Optimization?

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

Security grade badge for Sql Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectora-os-sql-optimization/badge)](https://www.skillsdirectory.com/skills/vectora-os-sql-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: sql-optimization
description: SQL query optimization — reading execution plans, index design (composite order, covering, partial), N+1 detection, join strategies, pagination (keyset), statistics, avoiding functions on indexed columns, batching, measuring under realistic data. Use for slow queries or query review (SQL optimization, EXPLAIN, slow query, index, N+1, keyset pagination).
metadata:
  category: performance
---

# SQL optimization

## Purpose

Make queries fast by evidence, not folklore.

**Use when:** slow queries or reviews of data access code.

**Not for:** schema redesign.

## Inputs

- Query, plan, data distribution.

## Outputs

- Optimized query/index with plans and timings before/after.

## Read first

- [Project Brain](../../../project-brain/README.md) — `npm run brain -- query "sql optimization"` for prior decisions, patterns and anti-patterns.
- [Performance report template](../../../templates/performance-report.md)

## Steps

1. **Measure.** Capture the plan with actual timings on realistic data.
   Done when baseline recorded.
2. **Diagnose.** Find the cost: seq scans, misestimates, sorts, nested loops over many rows.
   Done when cost location named.
3. **Fix.** Index, rewrite, batch, or keyset paginate.
   Done when one change at a time.
4. **Verify.** Same data, same parameters, compare plans and timings.
   Done when improvement is evidenced.

## Best practices

- Composite index order: equality, then range/sort.
- Check write cost of new indexes.

## Common mistakes

- Optimizing on tiny dev datasets.
- Adding indexes without checking plans.

## Example

Offset 50,000 page took 1.9 s; keyset on `(created_at,id)` 6 ms.

## Reusable prompt

```text
Apply the SQL optimization skill (.agents/skills/sql-optimization/SKILL.md).
Context: {{task card or question; links to PRD, ADRs, code paths}}
Constraints: {{approved thresholds, deadlines, allowed files}}
Capture the plan, locate the cost, propose a fix and verify with before/after plans on the same data.
Return: Optimized query/index with plans and timings before/after..
Cite evidence (file:line, command output, source) for every claim; list open questions separately.
```

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.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.