backend-db-performance
Installation
SKILL.md
Database Optimization Skill
Degree of freedom: MIXED. Which query/index/N+1 to fix [HIGH freedom];
existing-index probes and EXPLAIN ANALYZE [LOW freedom — run exactly].
How to reason
- Observe — EXPLAIN ANALYZE /
pg_stat_statements/ existingpg_indexes - Interpret — seq scan vs N+1 vs over-fetch vs missing pagination
- Classify — add-index / eager-load / narrow-select / paginate / leave-alone
- Severity — write-path timeout outranks a 200ms list page
Worked example
Observe:
/feedp95 2.4s; Prisma logs 81 queries;pg_indexeshas noidx_posts_user_created. Interpret:findManyposts then per-rowuser.findUnique— N+1;ORDER BY created_atis a seq scan. Classify: eager-loadinclude: { author }+ composite index(user_id, created_at DESC). Verify: EXPLAIN ANALYZE → Index Scan; query count 2; p95 < 200ms. Did not add a duplicate index.