Skip to content
Development
Skill

/database-query-performance

Diagnose database latency with explain plans, index ownership, and query amplification review. Use when a query is slow, an index is missing, or scans, loops, and N+1 patterns appear.

From plugin
agent-skills-standard
583200 skills21 agents33 commands1 MCP

Claude Code

$ npx -y skills add hoangnguyen0403/agent-skills-standard --skill database-query-performance --agent claude-code

SKILL.md

database-query-performance.SKILL.md
name: database-query-performance
description: Diagnose database latency with explain plans, index ownership, and query amplification review. Use when a query is slow, an index is missing, or scans, loops, and N+1 patterns appear.
metadata:
  triggers:
    files:
    - '**/*.sql'
    - '**/*.entity.ts'
    - 'prisma/schema.prisma'
    keywords:
    - slow query
    - explain
    - index
    - scan
    - n+1
    - query amplification
    - dataloader

Database Query Performance

**Priority: P0 (CRITICAL)**

Slow query work starts with the query shape and evidence, not with random index creation.

Rules

  • Capture the exact query, parameters, and access path; redact sensitive values.
  • Run explain or equivalent plan inspection before adding indexes; do not use explain as a request counter.
  • Match indexes to filter, join, sort, and coverage needs; evaluate index write cost.
  • Classify amplification evidence: static loops/serializers are `suspected`, architectural proposals are `design risk`, and telemetry/statement logs are `observed`.
  • Distinguish true query amplification (loops, serializer lazy loads, per-record aggregates, resolver fan-out) from constant-count queries and non-query redundancy.
  • Fix N+1 amplification with the smallest justified remedy: push down aggregates (`GROUP BY`), use bounded batch key lookups ($Q_{base} + R \cdot \lceil N / B \rceil$), or use request-scoped DataLoaders.
  • Preserve parent pagination (`LIMIT`/`OFFSET`), tenant/authorization scope, empty collections, and deterministic ordering across batch loading.

Verify

  • [ ] Explain plan was reviewed; query plan verified.
  • [ ] Proposed index maps to a named query path with acceptable write cost.
  • [ ] Amplification classified by evidence tier (suspected vs design risk vs observed).
  • [ ] Remedy uses smallest justified loading strategy; preserves pagination and tenant scope.
  • [ ] Negative controls verified: constant-count queries, already-batched queries, and spare-instance redundancy are rejected as N+1 defects.

Anti-Patterns

  • **No blind indexes**: every index needs a query owner; indexing does not fix $O(N)$ query loops.
  • **No cache-first latency fix**: fix query shape before hiding it; never use a global cache for request-scoped DataLoaders.
  • **No blanket giant JOIN**: joining 1:N relations multiplies rows, inflates memory, and breaks parent pagination.
  • **No ORM opacity**: inspect generated SQL when the ORM is involved.
  • **No conflation of redundancy**: high-availability N+1 spare compute nodes are not database query amplification.

References

  • [Framework Map](../references/framework-map.md)
  • [Index Strategies](references/index-strategies.md)
  • [N+1 Amplification Diagnosis & Remedies](references/nplus1-diagnosis.md)
Read more
@hoangnguyen0403
Ships withagent-skills-standard

The portable standards layer for AI coding agents. Sync once, then work in your own runtime.

583200 skills21 agents1 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
583
Star history of hoangnguyen0403/agent-skills-standard on GitHub, a chart by star-history.com

Other skills on agent-skills-standard.

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills13d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc2w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react4d252k
@facebook@facebookInstall Skill

Questions about database-query-performance.

Which coding agents can use database-query-performance?
database-query-performance installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.