Overfetching
Optimize provides recommendations to help you identify and resolve performance issues caused by over-fetched data.
The following query might be overfetching data in queries on the User
model:
await prisma.user.findMany({
where: {
email: { contains: "gmail" },
},
include: {
links: true,
},
});
What is the problem?
Retrieving data from all columns of a table, especially in large tables or those with complex relationships, can result in:
- Increased load times: Fetching more data than necessary prolongs query processing and data transfer times.
- Greater resource consumption: Retrieving unnecessary fields places strain on memory and CPU resources, both in the database and on the machines running your application.
- Higher costs: Reading and transferring excess data can lead to increased processing costs.
- Security risks: You might unintentionally expose sensitive data that should remain within the database.