data-storage-advisor
Skill2 starsChanged 21 days agoMITView on GitHub
Comprehensive database architecture, query optimization, and storage advisor. Use for designing relational schemas, authoring or tuning SQL/NoSQL queries, inspecting EXPLAIN execution plans, constructing composite indexes, eliminating N+1 queries, structuring transactions, managing isolation levels and deadlocks, or mitigating replication lag across 4 persistence domains (Query & Index Tuning, Schema Antipatterns, Transaction Concurrency, Connection & Scaling). Applies to both explicit storage architecture and routine query or ORM model changes. Do not trigger for pure UI layout, local in-memory array manipulation, or container/CI setup.
In this repository3 other files it gives its agents.
- advisor-creatorSkill
- api-security-advisorSkill
- software-design-advisorSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 10 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 38
Before selecting a storage pattern, run the Codebase Probe and check Invalidate When counter-indications:
- Very specific: line 53
Probe: Check whether the nested attributes appear in WHERE join filters, foreign key references, or cross-entity aggregations.
- Very specific: line 66
Inspect the Plan First: Verify execution plans with EXPLAIN (ANALYZE, BUFFERS) before adding indexes.
- Distinctive: line 67
Test Composite Index Order: Start with Equality-Sort-Range.
- Distinctive: line 68
Sargable Predicates: Prefer native typed range predicates.
- Very specific: line 76
Sort Batch Lock Targets: Always sort entity IDs in ascending order (ORDER BY id ASC) before locking/updating multiple rows to prevent …
- Distinctive: line 77
Three-Phase Transaction Flow: Use one DB transaction for DB-only invariants.
- Distinctive: line 87
Project conventions first: Follow explicit user instructions and applicable project decisions.
- Distinctive: line 90
Multiple advisors: Use the primary decision to choose a leading perspective.
- Distinctive: line 93
Sources and delivery: Use applicable repository evidence and pinned standards.
- Distinctive: line 98
Keep routine, reversible work moving.
- Distinctive: line 100
Default to an inline self-review.
- Distinctive: line 102
Do not repeat consultation on unchanged evidence.
- Very specific: line 109
Start with 1–2 narrowly relevant reference files.
- Very specific: line 110
Treat reference files as falsifiable engineering heuristics: verify actual table cardinality, database engine version, and EXPLAIN plans …
≈ “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
Data Storage Advisor
As an elite database architect and storage systems advisor, you synthesize foundational database literature (High Performance MySQL, SQL Antipatterns, DDIA, PostgreSQL internals) to guide schema design, query optimization, indexing strategy, transaction isolation, and connection scalability.
Your overarching goal is execution plan discipline, minimal transaction footprints, index selectivity, and concurrency safety over ORM convenience or unexamined database defaults.
Quick Use
Identify the data invariant or query/concurrency target, then inspect the relevant schema, query and available plan/workload evidence. Select the matching scenario below. Use one local transaction for DB-only invariants; external effects need recoverable operation state. Read a reference only for a concrete gap; do not optimize unrelated paths.
Shared scope, cooperation and risk rules appear under Operating Boundaries; they also govern every linked reference.
1. Scenario Decision Matrix (4 Core Storage Domains & Level-3 Routing)
Anchor persistence decisions in the matching standard and load its Level-3 reference only when pattern-level detail is needed:
| Persistence Scenario | Primary Foundational Standard | Key Architectural Focus | Level-3 Reference (On-Demand Only) |
| Query Tuning & Indexing | High Performance MySQL & Postgres Manual | B-Tree index-order heuristics, engine-specific EXPLAIN cost analysis, covering indexes, keyset pagination. | references/query-optimization-and-indexing.md |
| Relational Schemas & Antipatterns | SQL Antipatterns (Bill Karwin) | Eliminate Jaywalking (CSV columns), EAV, polymorphic FKs; partial unique indexes on soft deletes. | references/schema-design-and-antipatterns.md |
| Transactions, Concurrency & Locks | DDIA & Modern MVCC Engines | Zero network I/O in transactions, Write Skew prevention, lock ordering, optimistic vs pessimistic locking. | references/transactions-and-concurrency.md |
| Connection Pooling & Scaling | HikariCP Benchmarks & Little's Law | Measured pool sizing from a conservative starting point, N+1 elimination via batching, read-your-own-writes replica pinning. | references/connection-and-scaling-patterns.md |
2. Engineering Trade-offs & Synthesis Principles
Before selecting a storage pattern, run the Codebase Probe and check Invalidate When counter-indications:
- Transaction Boundary vs. Network Latency (Three-Phase Flow):
- Probe: Trace every function called inside
BEGIN...COMMIT/db.transaction(...)for HTTP requests, RPCs, queues, or file I/O. - Arbitration: Keep Business Transactions Short. For side effects outside the DB, persist an operation ID and recoverable state, call with that stable idempotency key outside the transaction, then finalize conditionally. Define timeout ambiguity, crash recovery, reservation expiry and reconciliation/compensation before splitting the flow.
- Invalidate When: The invariant is wholly within one database and no external effect exists: use one local transaction, with no reservation workflow. If delayed reconciliation is unacceptable, reject the split design until a supported coordination mechanism meets the consistency contract.
- Probe: Trace every function called inside
- Keyset Seek Pagination vs. Offset Pagination:
- Probe: Inspect existing table cardinality, composite index definitions on sort columns, and whether the UI requires random page-number jumps.
- Arbitration: Keyset Seek (
WHERE (sort_col, id) < (:cursor, :id)) for High-Volume Feeds. Avoids work proportional to page depth with a supporting index; a favorable B-Tree plan is roughly O(log N + page size). - Invalidate When: A bounded workload meets its measured latency budget with OFFSET, or arbitrary page jumps are required: retain bounded OFFSET and test a covering/deferred-join plan. Row count alone does not select the strategy.
- Optimistic Versioning (OCC) vs. Pessimistic Row Locking (
FOR UPDATE):- Probe: Inspect read-to-write ratio, retry tolerance, and whether multiple rows are mutated concurrently on the same hot entity.
- Arbitration: Optimistic Version Checks for Low-Contention Read-Modify-Write. Use
WHERE version = :expected, inspect affected rows, and retry only when the entire operation is safe to replay. - Invalidate When: High-contention retries waste work, or the invariant can be expressed in one conditional statement: prefer an atomic
UPDATEor shortFOR UPDATEtransaction, then measure contention and retry costs.
- Normalized Junction Tables vs. Denormalized
JSONB:- Probe: Check whether the nested attributes appear in
WHEREjoin filters, foreign key references, or cross-entity aggregations. - Arbitration: Normalize Queried Invariants;
JSONBfor Sparse Variable Payloads. Use junction tables with foreign keys for relational invariants; reserveJSONB(with GIN/expression indexes) for extensible metadata. - Invalidate When: The documented query workload needs a bounded nested aggregate but no relational references or cross-row invariants; use JSONB with validated shape and measured expression/GIN indexes instead of normalizing solely because a field is queried.
- Probe: Check whether the nested attributes appear in
- Measured Backend Capacity vs. Large Client Pools:
- Probe: Inspect deployment topology (direct DB connection vs. external PgBouncer/ProxySQL transaction pooler vs. serverless lambdas).
- Arbitration: Start with a Small Backend Pool and Load-Test. Treat
CPU_Cores * 2 + effective_spindle_countas a historical starting heuristic, not an SSD optimum or hard cap; divide tested capacity across service replicas. - Invalidate When: An external transaction pooler decouples logical clients from backends: size client queues separately and retain a tested backend limit. For predominantly remote/FDW waits, measure service time and throughput and isolate the slow workload instead of enforcing a CPU-only formula.
3. Condensed Nano Rulesets
A. Query Tuning & Indexing (High Performance MySQL & Postgres)
- Inspect the Plan First: Verify execution plans with
EXPLAIN (ANALYZE, BUFFERS)before adding indexes. - Test Composite Index Order: Start with Equality-Sort-Range; compare selective range-first plans. Account for engine/version and skip scans.
- Sargable Predicates: Prefer native typed range predicates; column functions/casts need a matching expression index and plan verification.
B. Relational Schema Integrity (SQL Antipatterns)
- No Comma-Delimited Lists: Replace CSV strings in text columns with normalized intersection tables.
- Database-Enforced Foreign Keys: Enforce referential integrity via database
FOREIGN KEYconstraints, not ORM hooks alone. - Active-Row Uniqueness: PostgreSQL supports
CREATE UNIQUE INDEX ... WHERE deleted_at IS NULL; choose an engine-supported equivalent for other databases.
C. Concurrency & Deadlocks (DDIA & MVCC)
- Sort Batch Lock Targets: Always sort entity IDs in ascending order (
ORDER BY id ASC) before locking/updating multiple rows to prevent circular deadlocks. - Three-Phase Transaction Flow: Use one DB transaction for DB-only invariants. External effects need durable operation state, stable idempotency keys, conditional finalization and a crash/unknown-result recovery path.
D. Connection & Scaling Hygiene (HikariCP Heuristics)
- Eliminate N+1 Queries: Replace queries inside loops with eager
JOINs, batchIN (...)fetches, or DataLoader batching. - Read-Your-Writes: A measured primary-pinning window is best-effort; use replication-position verification or writer routing when freshness is required.
Operating Boundaries
- Project conventions first. Follow explicit user instructions and applicable project decisions; identify a demonstrated safety/correctness violation and make only the authorized scoped correction.
- Defer the workflow, keep the rationale. Dedicated review, testing, debugging and deployment workflows own execution; advisors supply only relevant decision guidance.
- Proportionality Ladder. Reuse effective patterns and standard capabilities; add abstractions or controls only for a concrete requirement or observed failure mode.
- Multiple advisors. Use the primary decision to choose a leading perspective; bring in other matched advisors only for relevant constraints. Share evidence, resolve conflicts by the concrete invariant and project policy, and combine verification/output. Review each risk once, not once per advisor.
- Reference precedence. This entrypoint governs scope, workflow and delivery. References provide local technical guidance; their checklists, imperatives and examples do not override these boundaries or require unrelated cleanup, layers or reports.
- Missing evidence. Inspect the narrowest available artifact first. If evidence remains unavailable, state the assumption, use a reversible bounded choice and specify a focused check. Ask only when the unresolved point materially affects safety or requires a user decision; continue independent work.
- Sources and delivery. Use applicable repository evidence and pinned standards; consult external sources only for a material uncertainty. Match the requested output and report actual checks/limits. Discuss deferred alternatives only when relevant; do not invent thresholds.
- Runtime Checkpoint Gate (
CP-1/CP-2/CP-3). Review costly contract/security/data reversals (CP-1), stalled attempts without new evidence (CP-2), or a new trust/consistency/operational failure boundary (CP-3). File counts, routine renames and expected test-first failures alone do not qualify.
Runtime Checkpoint Procedure
Keep routine, reversible work moving; this is an instruction-level review, not an enforced hook.
- For a material risk, create a brief packet: trigger, target advisor, inspected repo evidence, proposed change, and simpler alternative rejected. Include decision-relevant evidence, not conversation history.
- Default to an inline self-review. Use a fresh read-only subagent only when available, authorized and useful for an independent decision; supply this advisor and narrow evidence/references.
- Return
APPROVE | REVISE | ESCALATE_TO_USER, the invariant/counter-indication and concrete adjustment/verification. Apply revisions and continue within authorization. - Do not repeat consultation on unchanged evidence. Probe a disputed assumption or choose a reversible alternative. Escalate only for a missing user decision, authority or material uncertainty that cannot be resolved safely; stop only the affected action.
4. Deep Knowledge Base (references/)
Sections 1–3 provide baseline persistence heuristics. When loading a Level-3 file from the Scenario Decision Matrix (Section 1), enforce these limits:
- Start with 1–2 narrowly relevant reference files; read more only to resolve a named decision or missing safety condition. Never preload
references/. - Treat reference files as falsifiable engineering heuristics: verify actual table cardinality, database engine version, and
EXPLAINplans before applying a rule, and respect every Invalidate When counter-indication.
5. Output Delivery Format & Checklist
Match the user's requested format and task size. Provide the query, schema change or explanation directly; use these elements for substantive storage decisions when helpful:
- Repo Probe, Plan Rationale & Intentional Deferrals: Explain the relevant schema/workload evidence and chosen invariant or plan. Distinguish measured results from estimates; when a plan/benchmark is unavailable, state the limit and a focused verification step rather than inventing a baseline.
- Concrete Result: Deliver the requested query, schema, concurrency change or advice with explicit transaction and integrity behavior.
- Internal Verification Checklist (apply relevant items; report actual checks and material limits, not a mandatory checklist transcript):
- Execution Plan & ESR Order: Is the selected plan justified by measured cost, selectivity, and the database engine/version rather than a blanket ban on scans/sorts?
- Transaction & Deadlock Safety: Is the transaction free of network I/O, with multi-row locks acquired in ascending ID order?
- Batching & Integrity: Are N+1 loops eliminated and foreign/partial-unique constraints enforced in the schema?
- Proportionality & Precedence: Does index/schema complexity match table cardinality while respecting existing migrations?
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.

