database-optimization

Guidance for designing database tables, choosing indexes, reviewing queries, and planning safer database changes. A database stores application data in organized tables, while indexes help it find rows faster.

In plain words
What is it for?
Use it when designing a schema, adding or changing tables and indexes, writing a migration, or investigating a slow query. It covers normalization, index choices, migration risks, rollback planning, and lock impact.
Why use it?
It helps avoid slow queries and database changes that could lock, break, or lose data. It also clarifies when an index helps and when it adds unnecessary overhead.

Skill for Claude CodeCodex

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/komluk/scaffolding/database-optimization
Any agent
npx skills add komluk/scaffolding --skill database-optimization
Clone the repo
git clone --depth 1 https://github.com/komluk/scaffolding

Made for: Claude Code, Codex.

Per session 58 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,704 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.00058 $0.01704
Opus 5 $0.00029 $0.00852
Sonnet 5 $0.00012 $0.00341
Haiku 4.5 $0.00006 $0.00170

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

Security

Grade A, and why

database-optimization 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 2d 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-optimization/SKILL.md · 215 lines

How it starts

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

Schema Design Principles

Form Use When
1NF Always (atomic values)
2NF Most tables
3NF Transactional data
Denormalized Read-heavy, reporting

Index Strategy

Type Use Case
B-Tree Default, range queries
Hash Exact match only
GIN (Postgres) Full-text, JSONB, arrays
Partial Subset of rows
Composite Multi-column queries

Index type names vary by engine (e.g. GIN/GiST/BRIN are Postgres-specific; MySQL/SQLite expose a different set). Treat engine-specific rows as examples.

When to Index

  • Primary keys (automatic)
  • Foreign keys
  • WHERE clause columns
  • ORDER BY columns
  • JOIN columns

When NOT to Index

  • Low cardinality columns
  • Frequently updated columns
  • Small tables (< 1000 rows)

Migration Safety

Safe Operations

  • ADD COLUMN (nullable)
  • ADD INDEX CONCURRENTLY
  • CREATE TABLE
  • ADD CONSTRAINT (with validation)

Dangerous Operations

  • DROP COLUMN
  • RENAME COLUMN
  • ALTER COLUMN TYPE
  • DROP TABLE

Migration Checklist

  • Tested on production-like data
  • Rollback script ready
  • Estimated execution time
  • Lock impact assessed
  • Application compatibility verified

Query Analysis

Common Issues

Issue Symptom Solution
Missing index Sequential scan Add index
N+1 queries Many similar queries Eager loading
Over-fetching SELECT * Select specific columns
No pagination Large result sets Add LIMIT/OFFSET
Cartesian join Exploding rows Fix JOIN conditions

Analysis Commands

Frontend

  • npm run build -- --analyze - Bundle analysis
  • lighthouse - Performance audit
  • Browser DevTools Performance tab

Backend (Python)

  • py-spy - CPU profiling
  • memory_profiler - Memory analysis
  • EXPLAIN ANALYZE - Query analysis

Best Practices

DO

  • Measure before optimizing
  • Design database for future scale
  • Document schema decisions
  • Use foreign keys and index them
  • Plan migrations carefully
  • Test with production-like data
  • Focus on user-impacting metrics

Read the full file on GitHub · 215 lines

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. 2d ago First seen · 215 lines · 58 tokens per session scan A 378e0f2d8a76

Subscribe to this mod's changes

database-optimization is a skill published in the GitHub repository komluk/scaffolding (15 stars, last pushed 26d ago), licensed MIT. It adds 58 tokens to every session and 1,704 once invoked, about $0.0003 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-30.

Related

Other skills, from other repositories

ideogram-ultra

Build Ideogram 4 (Ideogram Ultra) txt2img and img2img workflows with the local open-weights model, dual conditional/unconditional models with DualModelGuider, Qwen3-VL text encoder, and structured JSON ("compositional deconstruction") prompts for strong text rendering and layout control.

artokun/comfyui-mcp · 68 tokens

model-compatibility

Model family compatibility matrix covering loaders, resolutions, samplers, CFG, VAE, ControlNet, and LoRA compatibility for SD 1.5, SDXL, Flux, SD3, and video models.

artokun/comfyui-mcp · 47 tokens

panel-node-pack-sync

Keep the ComfyUI sidebar panel node-pack (comfyui-agent-panel) in step with the orchestrator after comfyui-mcp updates. Use this whenever the orchestrator was just updated (installcomfyui (action:"selfupdate"), npm i -g comfyui-mcp, a new version in the ENVIRONMENT line), when a panel/bridge command fails in a way…

artokun/comfyui-mcp · 206 tokens

civitai

Discover Civitai models with the BUILT-IN downloadmodel action:"searchcivitai" and install/generate them locally. Find a checkpoint/LoRA/embedding on Civitai, download it into ComfyUI, and use its trigger words. Optionally pair the official Civitai MCP for community features (images browsing, posting, collections).

artokun/comfyui-mcp · 76 tokens

31-offer-design-global

Use when the WHAT being sold needs work, not the price and not the copy — core promise, value stack, bonuses, guarantee and risk reversal, honest scarcity and urgency, tier packaging, upsell and downsell paths, and high-ticket or productized service structures. Trigger on 'design an offer', 'irresistible offer'…

minhnv0807/ai-business-skills · 172 tokens

aeo-geo

Strategy module for Answer Engine / Generative Engine Optimization — audits AI visibility, restructures content for citation, runs entity-consistency checks across Knowledge Graph, Wikidata, Wikipedia, Crunchbase, and LinkedIn, and produces JSON-LD schema specs, monitoring frameworks, and a 90-day LLM content…

indranilbanerjee/digital-marketing-pro · 156 tokens