-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow queries on MongoDB using include
for relations
#15156
Comments
The issue stems from the generate prisma query is too complex to use an index. There is a hack instead of "id_in": prisma.production.findMany({
where: { OR: ids.map(id => ({ id: id })) }
}); But I have found many other prisma queries to have performance issues, so I have unfortunately had to migrate away from prisma. |
I made similar discoveries here: #17142 (comment) |
include
for relations
I am also suffering hard from this. I use serverless instance on Atlas and suddenly I got very expensive bills simply because of unoptimized Prisma queries. |
This performance problem is fixed in Prisma 5.14.0 |
Bug description
When you use
{include: {relationModel: true}}
on prisma with a MongoDB, you can observe several slow queries in the mongo logs.Prisma generates a aggregate query which cannot use the index on _id. Instead mongo falls back to COLLSCAN. This is of course very slow.
How to reproduce
Prisma seems to do the same on include, like loading 500 documents manually like this
This generates the following in mongo:
Expected behavior
When writing this command to mongo directly, it uses the index and is very fast:
Prisma information
Environment & setup
and a collection containing > 1 million documents.
Prisma Version
The text was updated successfully, but these errors were encountered: