# Optimize Database Performance

Slow queries and weak indexes can make applications costly and unreliable. This skill guides SQL tuning, index design, caching, and N+1 fixes.

## Install

```bash
npx skillstore add joseph obrien/89jobrien-database-optimization
```

## Metadata

- Status: approved
- Slug: 89jobrien-database-optimization
- Version: 1.0.1
- Author version: 1.0.1
- Skillstore revision: r1
- Version status: valid
- Tree hash: 562bbfa717ee74a9fdd9bb6430944b47cab4057e27e6045b9a89120f18d97067
- Author: Joseph OBrien
- GitHub username: 89jobrien
- License: MIT
- Repository: https://github.com/89jobrien/steve/tree/main/steve/skills/database-optimization
- Ref: c4037264bbd363c572662d6154a3ab28f5ca4f53
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 77
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/89jobrien-database-optimization
- Manifest: https://skillstore.pages.dev/api/skills/89jobrien-database-optimization/manifest

## Capabilities

- Reviews slow SQL queries and explains likely performance bottlenecks.
- Suggests indexes for common WHERE, JOIN, sort, and covering index patterns.
- Identifies N\+1 access patterns in ORM code examples.
- Recommends caching strategies using Redis or similar cache layers.
- Guides migration and monitoring improvements for database performance.

## Use Cases

- Tune slow customer queries: Review a slow query, explain likely causes, and suggest safer SQL and indexes.
- Reduce ORM query volume: Find N\+1 patterns in application code and suggest eager loading or joins.
- Plan database performance work: Create a practical optimization checklist for indexes, caching, monitoring, and migrations.

## Prompt Templates

### Review a slow query

```
Review this slow SQL query. Explain the main bottlenecks and suggest simple improvements.
```

### Suggest useful indexes

```
Given this schema and query workload, recommend indexes and explain why each index helps.
```

### Fix N\+1 database access

```
Analyze this ORM code for N+1 query patterns. Suggest eager loading, joins, or batching where appropriate.
```

### Create an optimization plan

```
Build a database optimization plan using these queries, schema details, query plans, and traffic patterns.
```

## Limitations

- It does not connect to live databases or collect runtime metrics by itself.
- Recommendations depend on the schema, query plan, and workload details provided.
- It cannot guarantee production speedups without testing on real data.
- It focuses on relational databases and common cache patterns.

## Best Practices

- Share query plans, table sizes, existing indexes, and workload patterns for better recommendations.
- Measure before and after each change using production-like data and realistic traffic.
- Balance read speed, write cost, storage growth, and operational complexity.

## Anti Patterns

- Do not add indexes without checking query patterns and write impact.
- Do not cache database results without an invalidation or freshness plan.
- Do not optimize one query while ignoring total request query count.

## Security Audit

- Audited at: 2026-07-05T11:39:56.488\+00:00
- Summary: The static command execution alerts are Markdown code fences and database examples, not executable shell use. The reconnaissance alerts are SQL optimization examples about SELECT patterns and indexing. No prompt injection, data exfiltration, or malicious intent was found in SKILL.md or references/query-patterns.md.

## Stats

- Views: 241
- Downloads: 23
- Favorites: 0
- Popularity score: 0
