db-optimization
Skill8 starsChanged 2 months agoMITView on GitHub
Use when the bottleneck is database-shaped — slow queries, lock timeouts, connection exhaustion, N+1 patterns, index questions, schema migrations on hot tables. Evidence-first DB playbook for PostgreSQL, MySQL/MariaDB, MongoDB, and Redis backing the db-performance-tuner agent.
In this repository51 other files it gives its agents.
- adrSkill
- agency-tier-uiSkill
- api-designSkill
- banner-designSkill
- brainstormingSkill
- brandSkill
- cavemanSkill
- coding-standardsSkill
- designSkill
- design-systemSkill
- design-to-codeSkill
- dispatching-parallel-agentsSkill
- django-securitySkill
- dotnet-patternsSkill
- e2e-testingSkill
- executing-plansSkill
- explainmeSkill
- finishing-a-development-branchSkill
- golang-patternsSkill
- greenfield-architectSkill
- hydraiaSkill
- karpathy-guidelinesSkill
- microservices-architectSkill
- mobile-design-framesSkill
- node-patternsSkill
- performance-tuningSkill
- production-auditSkill
- python-patternsSkill
- react-patternsSkill
- receiving-code-reviewSkill
- redesign-upliftSkill
- repo-scanSkill
- requesting-code-reviewSkill
- security-bounty-hunterSkill
- security-reviewSkill
- security-scanSkill
- slidesSkill
- springboot-patternsSkill
- springboot-securitySkill
- story-analysisSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- ui-stylingSkill
- ui-ux-pro-maxSkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- web-design-framesSkill
- writing-plansSkill
- writing-skillsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Read-first: no change is proposed without its EXPLAIN plan, stat, or code evidence.
- Distinctive: line 12
All write-shaped operations (create index, schema change, config change) are PLAN TASKS — reviewed, gated, never executed by a diagnosis …
- Very specific: line 20
Expand: add the new column/table/index alongside the old — additive, backward-compatible, online.
- Distinctive: line 23
Contract: only after a full bake period, remove the old shape in a later release.
- Distinctive: line 41
Always set: acquisition timeout, idle timeout, max lifetime.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DB Optimization — EXPLAIN before you touch anything
Playbook for the DB half of the Hydraia perf route. The db-performance-tuner agent does the diagnosis; this skill sets the rules the route runs under.
<HARD-RULES>
- Read-first: no change is proposed without its EXPLAIN plan, stat, or code evidence. Live DB unavailable → code/schema inference only, tagged UNVERIFIED, with the confirming commands listed for the human.
- All write-shaped operations (create index, schema change, config change) are PLAN TASKS — reviewed, gated, never executed by a diagnosis agent.
- Destructive or blocking operations (table rewrites, long locks) are flagged for explicit human approval in the plan; prefer and name the online variant per engine: `CREATE INDEX CONCURRENTLY` (Postgres), `ALGORITHM=INPLACE, LOCK=NONE` (MySQL), rolling index builds (Mongo).
- Schema changes on live tables follow EXPAND-CONTRACT, no exceptions.
- Redact literal data values from any plan/log excerpt that lands in a committed artifact.
</HARD-RULES>Expand-contract migration protocol
- Expand: add the new column/table/index alongside the old — additive, backward-compatible, online.
- Dual-write + backfill: application writes both shapes; backfill history in batches (bounded, throttled, resumable).
- Switch reads to the new shape behind a verified flag; watch metrics.
- Contract: only after a full bake period, remove the old shape in a later release. Contract is its own plan task, never bundled with expand.
Index design guidance
- Composite order: equality columns first, then range, then sort — match the query, not intuition.
- Covering indexes to eliminate lookups for hot read paths; weigh write amplification (every index taxes every write).
- Partial/filtered indexes for skewed predicates (
WHERE deleted_at IS NULL). - Hunt UNUSED indexes too (
pg_stat_user_indexes,sys.schema_unused_indexes) — dropping one is also an optimization. - The index is not always the answer: sometimes it is the query shape, the schema, or the caller (N+1, missing cache).
N+1 patterns per ORM family
- Detection: a loop in code + per-iteration query in the log/profile. The agent cites the code location.
- Fix families: eager loading (
include/select_related/prefetch_related/preload), query batching (INlists), dataloader pattern (GraphQL), denormalized read models for hot aggregates.
Pooling guidance
- Pool size starts near
connections = cores * 2 + effective_spindles(HikariCP heuristic) — not hundreds; queueing beats connection thrash. - Always set: acquisition timeout, idle timeout, max lifetime. Connection churn (open/close per request) is itself a finding.
Per-engine evidence commands
See the db-performance-tuner agent definition for the full read-only evidence list per engine (EXPLAIN variants, stat views, lock views, SLOWLOG). This skill and that agent must stay in sync — update both or neither.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

