# Database

> Diagnose and fix slow database queries. Runs EXPLAIN ANALYZE, identifies missing indexes, eliminates N+1 ORM patterns, and provides exact CREATE INDEX statements.

- **Type:** Skill
- **Install:** `agentstack add skill-v0idos-performance-deity-database`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [v0idOS](https://agentstack.voostack.com/s/v0idos)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [v0idOS](https://github.com/v0idOS)
- **Source:** https://github.com/v0idOS/performance-deity/tree/main/skills/database
- **Website:** https://v0idos.github.io/performance-deity/

## Install

```sh
agentstack add skill-v0idos-performance-deity-database
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

Execute all three phases in order.

## Phase 1 — Analysis

1. Take the slow query or ORM code.
2. Generate the equivalent raw SQL.
3. Either instruct the user to run `EXPLAIN QUERY PLAN` (SQLite) or `EXPLAIN ANALYZE` (Postgres/MySQL), or infer missing indexes directly from the `WHERE`, `JOIN`, and `ORDER BY` clauses.

## Phase 2 — N+1 Audit

Check whether queries are issued inside a loop. If yes, rewrite using:
- `IN (...)` batch clause
- SQL `JOIN`
- ORM eager loading:
  - `.include()` — Prisma
  - `.populate()` — Mongoose
  - `select_related()` / `prefetch_related()` — Django

## Phase 3 — Rewrite

1. Provide the optimized SQL or ORM code.
2. Provide the exact `CREATE INDEX` statements required.
3. Explain the disk I/O reduction: Full Table Scan O(N) → Index Lookup O(log N).

Before/after query plan summary:

| Metric | Before | After |
|---|---|---|
| Scan type | Full Table Scan | Index Lookup |
| Complexity | O(N) | O(log N) |
| Query count (per page load) | N+1 | 1 |

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [v0idOS](https://github.com/v0idOS)
- **Source:** [v0idOS/performance-deity](https://github.com/v0idOS/performance-deity)
- **License:** MIT
- **Homepage:** https://v0idos.github.io/performance-deity/

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-v0idos-performance-deity-database
- Seller: https://agentstack.voostack.com/s/v0idos
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
