database-optimizer

database-optimizer is a skill for Claude Code, Codex from iwritec0de/app-dev. It costs 106 tokens per session (1,103 once invoked), scanned A, original, MIT.

A guide for improving database query performance and index design. A query is a request for stored data, and an index is an additional data structure that can help the database find rows faster.

In plain words
What is it for?
Use it to investigate slow queries, read EXPLAIN output, design indexes, fix N+1 queries, and compare performance before and after an optimization.
Why use it?
It requires examining the query plan and real usage before suggesting changes, helping avoid unnecessary indexes or fixes based on guesses. It also checks for N+1 queries, where an application makes many small database requests instead of one efficient request.

Skill for Claude CodeCodex

Part of the app-dev plugin — 17 skills, 11 commands, 4 agents, 3 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/iwritec0de/app-dev/database-optimizer
Any agent
npx skills add iwritec0de/app-dev --skill database-optimizer
Clone the repo
git clone --depth 1 https://github.com/iwritec0de/app-dev

Made for: Claude Code, Codex.

Or install app-dev, the plugin that ships this one along with the rest of its 17 skills, 11 commands, 4 agents, 3 hooks.

Per session 106 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,103 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00106 $0.01103
Opus 5 $0.00053 $0.00551
Sonnet 5 $0.00021 $0.00221
Haiku 4.5 $0.00011 $0.00110

Measured 3d ago against content hash 562e4d61a117, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/database-optimizer/SKILL.md · 107 lines

How it starts

The opening of the file, as written. The whole thing — 107 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Optimizer Skill

You are a database performance expert specializing in query optimization and index design.

Critical Rules

  • Always EXPLAIN first — never optimize without reading the query plan
  • Index based on actual queries — not guesses; check slow query logs
  • Don't over-index — each index slows writes and consumes storage
  • Measure before and after — performance claims require numbers
  • Prefer covering indexes — avoid heap lookups when possible
  • Watch for N+1 — the most common performance killer in ORMs
  • Understand your data distribution — selectivity determines index effectiveness

EXPLAIN Analysis

Key metrics to check in query plans:

Metric Good Bad
Scan type Index Scan, Index Only Scan Seq Scan on large tables
Rows Estimated ≈ Actual Off by 10x+ (stale statistics)
Loops 1 (or low) Thousands (nested loop on unindexed join)
Sort Index-backed In-memory or disk sort on large sets

Common node types: Seq Scan, Index Scan, Index Only Scan, Bitmap Index Scan, Hash Join, Merge Join, Nested Loop. Read reference/explain-analysis.md for full interpretation guide.

Index Design

-- Composite index: column order matters (most selective first for equality)
CREATE INDEX idx_orders_status_date ON orders (status, created_at);

-- Partial index: index only what you query
CREATE INDEX idx_orders_active ON orders (created_at) WHERE status = 'active';

-- Covering index: include columns to avoid heap lookup
CREATE INDEX idx_orders_cover ON orders (user_id) INCLUDE (total, status);

Index types: B-tree (default, most cases), Hash (equality only), GIN (arrays, JSONB, full-text), GiST (geometry, range), BRIN (naturally ordered large tables). Read reference/index-strategies.md for details.

Query Patterns

  • **Avoid SELECT *** — fetch only needed columns
  • Use cursor pagination — not OFFSET for large datasets (WHERE id > ? ORDER BY id LIMIT ?)
  • Batch operations — bulk INSERT with VALUES lists, not row-by-row
  • Push filtering to DB — don't fetch all rows and filter in application code
  • Use JOINs efficiently — ensure join columns are indexed
  • Prefer EXISTS over IN — for correlated subqueries on large sets

Read the full file on GitHub · 107 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 107 lines · 106 tokens per session scan A 562e4d61a117

Subscribe to this mod's changes

database-optimizer is a skill published in the GitHub repository iwritec0de/app-dev (3 stars, last pushed 4mo ago), licensed MIT. It adds 106 tokens to every session and 1,103 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

sql-queries

Generate SQL queries from natural language descriptions. Supports BigQuery, PostgreSQL, MySQL, and other dialects. Reads database schemas from uploaded diagrams or documentation. Use when writing SQL, building data reports, exploring databases, or translating business questions into queries.

phuryn/pm-skills · 55 tokens

postgres-database-migration

Use this skill for planning, testing, and safely executing PostgreSQL schema migrations — especially when working with production data or shared databases. Trigger when user asks to: Test a schema migration before applying it to production Add, remove, or rename columns safely on a live table Change a column's data…

timescale/pg-aiguide · 222 tokens

setup-timescaledb-hypertables

Use this skill when creating database schemas or tables for Timescale, TimescaleDB, TigerData, or Tiger Cloud, especially for time-series, IoT, metrics, events, or log data. Use this to improve the performance of any insert-heavy table. Trigger when user asks to: Create or design SQL schemas/tables AND…

timescale/pg-aiguide · 219 tokens

migrate-postgres-tables-to-hypertables

Use this skill to migrate identified PostgreSQL tables to Timescale/TimescaleDB hypertables with optimal configuration and validation. Trigger when user asks to: Migrate or convert PostgreSQL tables to hypertables Execute hypertable migration with minimal downtime Plan blue-green migration for large tables Validate…

timescale/pg-aiguide · 181 tokens

pgvector-semantic-search

Use this skill for setting up vector similarity search with pgvector for AI/ML embeddings, RAG applications, or semantic search. Trigger when user asks to: Store or search vector embeddings in PostgreSQL Set up semantic search, similarity search, or nearest neighbor search Create HNSW or IVFFlat indexes for vectors…

timescale/pg-aiguide · 190 tokens

find-hypertable-candidates

Use this skill to analyze an existing PostgreSQL database and identify which tables should be converted to Timescale/TimescaleDB hypertables. Trigger when user asks to: Analyze database tables for hypertable conversion potential Identify time-series or event tables in an existing schema Evaluate if a table would…

timescale/pg-aiguide · 184 tokens