optimizing-query-selection

Select only required fields and load relations in Prisma queries.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill teaches selecting only required fields, using include/select, and avoiding N+1 queries in Prisma.

Core Features & Use Cases

  • Selective Loading: Use select to fetch only needed fields.
  • Relation Management: Properly load relations with include/select and _count.
  • Pagination & Performance: Improve performance by minimizing data transfer.

Quick Start

Replace broad queries with targeted select/include patterns and add _count where appropriate.

Frequently Asked Questions about optimizing-query-selection

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

FAQPage Schema
How do I prevent N+1 queries when loading relations in Prisma?

N+1 queries occur when you fetch a list then query each item's relations separately. Use Prisma's select or include to load relations in a single query, and apply _count to fetch relation counts without additional requests.

What's the difference between select and include in Prisma queries?

Include fetches all fields plus specified relations; select fetches only specified fields and relations. Select is more efficient for APIs and large datasets because it reduces data transfer and memory usage.

How do I optimize Prisma queries to reduce memory usage?

Use select to fetch only required fields instead of entire records, apply take to limit result set size, and nest selects for related data. This minimizes data transfer and memory consumption on large result sets.

Can I use Prisma select with pagination?

Yes. Combine select with take and skip parameters to paginate while fetching only needed fields. Add _count to relations if you need relation counts without loading full related records.

Why are my Prisma queries slow when fetching related data?

Slow queries often result from loading unnecessary fields or relations, or querying fields without database indexes. Use select for precise field control, add indexes on filtered or ordered fields, and enable query logging to identify bottlenecks.