Skip to main content

过度获取

Optimize 提供的建议可帮助你识别和解决由过度获取数据引起的性能问题。

¥Optimize provides recommendations to help you identify and resolve performance issues caused by over-fetched data.

以下查询可能会在针对 User 模型的查询中过度获取数据:

¥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.

  • 更大的资源消耗:检索不必要的字段会给数据库和运行应用的计算机的内存和 CPU 资源带来压力。

    ¥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.