optimizing-query-performance

Optimize Prisma queries with indexes, batching, and cursor pagination.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill optimizing-query-performance
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimizing-query-performance
Source: https://github.com/djankies/claude-configs/tree/main/prisma-6/skills/optimizing-query-performance
Command: npx skills add https://github.com/djankies/claude-configs --skill optimizing-query-performance

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Data access patterns that are slow in production due to missing indexes, unoptimized queries, and N+1 issues. This skill teaches systematic query optimization for Prisma.

Core Features & Use Cases

  • Index strategy: place/adjust indexes on frequently filtered and sorted fields.
  • Batch operations: replace per-record loops with createMany, updateMany, and deleteMany.
  • Query analysis: use field selection, cursor pagination, and explain analysis to prevent N+1 problems.

Quick Start

Enable query logging, add appropriate indexes, replace loops with batch operations, and validate improvements with EXPLAIN ANALYZE and latency measurements.

Frequently Asked Questions about optimizing-query-performance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix slow Prisma queries in production?

Slow Prisma queries typically stem from missing indexes, N+1 problems, or unoptimized field selection. Add indexes on frequently filtered and sorted fields, use batch operations (createMany, updateMany, deleteMany) instead of loops, and apply cursor pagination for large result sets. Validate improvements with EXPLAIN ANALYZE and latency metrics.

What is N+1 problem and how do I prevent it in Prisma?

N+1 occurs when a query fetches one record, then triggers N additional queries for related data. Prevent it by selecting only needed fields, batching operations, and using cursor pagination. Monitor query logs to detect patterns where a single action generates cascading queries.

When should I add database indexes to optimize Prisma performance?

Add indexes on columns used frequently in WHERE clauses, sorting (ORDER BY), and joins. Index strategy focuses on fields accessed in filtered and sorted queries. Enable Prisma query logging to identify hot paths, then place indexes strategically to reduce scan time on large tables.

Can I use batch operations like createMany with Prisma to speed up bulk inserts?

Yes, batch operations replace per-record loops with single database calls. Use createMany, updateMany, and deleteMany to process multiple records at once, significantly reducing network round trips and improving throughput on production workloads handling bulk data.

How does cursor pagination improve Prisma query performance?

Cursor pagination fetches fixed-size result windows using keyset filtering instead of offset skipping. This approach scales better on large tables because it avoids scanning and discarding thousands of rows. Combine with field selection and indexes for optimal performance on sorted, filtered queries.

What tools help me measure if my Prisma query optimizations work?

Use EXPLAIN ANALYZE to inspect query execution plans and identify missing indexes or inefficient scans. Track latency metrics before and after optimization to validate improvements. Prisma query logging reveals N+1 patterns and loop-based inefficiencies you can address with batching.