You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prisma not combining queries for GraphQL server, leading to N+1 issues #5274
I've created a small server running Prisma, Apollo, and type-graphql with a few entities. A simple fetch that traverses multiple edges on the graph causes N+1 db queries when I'd have expected Prisma to combine them.
How to reproduce
Check out https://github.com/dickfickling/prisma-n1 for a repro. I'm not sure whether the culprit is within prisma, type-graphql, typegraphql-prisma, or somewhere in the way i'm structuring my code. Regardless if you install deps and run npm run test in this example, you'll see the test creates 10 users with 10 posts each, and then fetches the feed, which should return all 100 posts and their attached users. The test passes, but you see a massive number of queries logged.
There's a github action workflow that demonstrates this as well.
Expected behavior
I'd expect a constant number of db queries to run
Prisma information
prisma 2
Environment & setup
OS: debian/ubuntu
Database: mysql
Node.js version: reproduced on 14 and 15
Prisma version: 2.15.0
Reacted by Paddy Corr, Yama-Tomo, Sahil Deliwala, Daniel Norman, Darryl Young and Omer
I'm facing the same issue with same environment setup. Prisma's findUnique just runs queries individually with SELECT .... WHERE user.id = 2 instead of batching them like SELECT... WHERE user.id in [1,2,3,4]
Thanks everyone for reporting. We just implemented a fix for this. It's available in @prisma/[email protected].
Please let us know if that fixes it for you! @dickfickling in your project I also needed to add the prisma for the typegraphql generator.
Activity
sahildeliwala commentedon Jan 30, 2021
I'm facing the same issue with same environment setup. Prisma's
findUniquejust runs queries individually withSELECT .... WHERE user.id = 2instead of batching them likeSELECT... WHERE user.id in [1,2,3,4]timsuchanek commentedon Feb 2, 2021
Thanks for reporting! We'll have a look.
Related: prisma/prisma-examples#2464
janpio commentedon Feb 8, 2021
2 more cases were reported in #5485 - one was explicitly confirmed to be the same problem as described above.
timsuchanek commentedon Feb 10, 2021
Thanks everyone for reporting. We just implemented a fix for this. It's available in
@prisma/[email protected].Please let us know if that fixes it for you!
@dickfickling in your project I also needed to add the
prismafor the typegraphql generator.dickfickling commentedon Feb 10, 2021
it works! thanks @timsuchanek
timsuchanek commentedon Feb 10, 2021
Awesome @dickfickling! Thanks again for the reproduction and also for getting back to me!
That's not a given.
janpio commentedon Feb 12, 2021
Can confirm that the reproduction from #5485 is also back to normal performance with
2.17.0-dev.67👍