P
Prismaā€¢4mo ago
Emi

prisma nested fields

is it okay in terms of performance to have many nested fields in prisma?

const user = await prismadb.user.findUnique({
where: { id },
include: {
licenses: {
include: {
subscription: {
include: { organization: { include: { admin: true } } },
},
},
},
},
});

const user = await prismadb.user.findUnique({
where: { id },
include: {
licenses: {
include: {
subscription: {
include: { organization: { include: { admin: true } } },
},
},
},
},
});
3 Replies
RaphaelEtim
RaphaelEtimā€¢4mo ago
Hi @Emi šŸ‘‹ Having to include many nested fields in your queries can have performance implications. Each level of include results in an additional SQL query. For example, if you have a user model that includes licenses, which in turn includes subscription, which includes organization, which includes admin, this would result in multiple SQL queries. The more nested your include statements are, the more SQL queries will be generated, which could potentially impact performance. There are open issues with respect to this here and here. Also you should note that we recently released the relationJoins preview feature which aims to improve the performance of nested reads as stated here
GitHub
Network latency increases with selecting nested relations Ā· Issue #...
Bug description Per #5043 (comment), I am making this issue. I have found that joins have worse performance as the client <-> database latency increases. How to reproduce Check out the typesc...
GitHub
Issues Ā· prisma/prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - Issues Ā· prisma/prisma
GitHub
Release 5.7.0 Ā· prisma/prisma
šŸŒŸ Help us spread the word about Prisma by starring the repo or posting on X (formerly Twitter) about the release. Highlights āœØ In this release, we improved the SQL queries Prisma Client generates f...
Emi
Emiā€¢4mo ago
thanks just what I needed!
RaphaelEtim
RaphaelEtimā€¢4mo ago
You're welcome.