Optimize queries with indexes, batching, and efficient Prisma operations for production performance.
Identifies slow database queries and applies strategic indexes, batch operations, and field selection to eliminate N+1 problems and reduce latency by 50-90%. Use when query logs show slow execution or when optimizing bulk operations for production workloads.
/plugin marketplace add djankies/claude-configs/plugin install prisma-6@claude-configsThis skill is limited to using the following tools:
references/batch-operations.mdreferences/field-selection.mdreferences/index-strategy.mdreferences/optimization-examples.mdreferences/query-monitoring.mdKey capabilities: Strategic index placement (@@index, @@unique) · Efficient batch operations (createMany, transactions) · Query analysis & N+1 prevention · Field selection optimization & cursor pagination </overview>
<workflow> **Phase 1 — Identify:** Enable query logging; analyze patterns/execution times; identify missing indexes, N+1 problems, or inefficient batchingPhase 2 — Optimize: Add indexes for filtered/sorted fields; replace loops with batch operations; select only needed fields; use cursor pagination for large datasets
Phase 3 — Validate: Measure execution time before/after; verify index usage with EXPLAIN ANALYZE; monitor connection pool under load </workflow>
Index Strategy:
| Scenario | Index Type | Example |
|---|---|---|
| Single field filter | @@index([field]) | @@index([status]) |
| Multiple field filter | @@index([field1, field2]) | @@index([userId, status]) |
| Sort + filter | @@index([filterField, sortField]) | @@index([status, createdAt]) |
Batch Operations:
| Operation | Slow (Loop) | Fast (Batch) |
|---|---|---|
| Insert | for...await create() | createMany() |
| Update | for...await update() | updateMany() |
| Delete | for...await delete() | deleteMany() |
Performance Gains: Indexes (10-100x) · Batch ops (50-100x for 1000+ records) · Cursor pagination (constant vs O(n))
<constraints> **MUST:** Add indexes for WHERE/ORDER BY/FK fields with frequent queries; use createMany for 100+ records; cursor pagination for deep pagination; select only needed fields; monitor query duration in productionSHOULD: Test indexes with production data; chunk 100k+ batches into smaller sizes; use @@index([field1, field2]) for multi-field filters; remove unused indexes
NEVER: Add indexes without performance measurement; offset pagination beyond page 100 on large tables; fetch all
fields when only needing few; loop with individual creates/updates; ignore slow query warnings </constraints>
<validation> **Measure Performance:** ```typescript const start = Date.now() const result = await prisma.user.findMany({ ... }) console.log(`Query took ${Date.now() - start}ms`) ``` Expected: 50-90% improvement for indexed queries, 50-100x for batch operationsVerify Index Usage: Run EXPLAIN ANALYZE; confirm "Index Scan" vs "Seq Scan"
Monitor Production: Track P95/P99 latency; expect reduced slow query frequency
Check Write Performance: Writes may increase 10-30% per index if rarely-used; consider removal </validation>
references/index-strategy.md — indexing patterns and trade-offsreferences/batch-operations.md — bulk operations and chunkingreferences/query-monitoring.md — logging setup and slow query analysisreferences/field-selection.md — select vs include patterns and N+1 preventionreferences/optimization-examples.md — real-world improvementsThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.