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
"Join" performance: (Not so) huge data set throws an error #13306
Comments
I think we're hitting the same issue. Any ideas on what exact limit is hit, causing the request to fail? I was first thinking about the parameter count, but prisma seems to limit that to 2^15. The next thing I could imagine would be some payload limit (because our IDs are UUIDs, so having at least ~32k*40 characters explodes the query size), but I don't know how to debug the engine. Is there perhaps any workaround? (e.g. by manually increasing some of those limits?) |
So I've logged one of the "offending" queries in our case, which resulted in a ~1.2MB sql file. I then manually executed it on our postgresql server. It took a while (~1.5min, including the network time to download and log the results), but it worked first try - which, to me, rules out any misconfiguration on the DB server and confirms that the prisma engine is the culprit here. |
Hitting similar issues with 9 JOINS, raw SQL had a 10x speedup. |
Sorry, forgot about this issue and didn't post my latest update here. We stumbled upon this discussion and this issue, which seemed related. In our case, I got thrown off a bit by the number of query parameters. It seemed that prisma indeed started to chunk queries to not exceed 2^15 parameters, so I was thinking it must be something else. But actually, 2^15 is exactly one parameter too much, because the limit in JDBC when connecting to a postgres database is 32,767 (or 2^15 - 1). The workaround was quite simple in that case: set the (unfortunately not well documented) |
Thank you for opening this issue. Closing this in favour of #8832, which we were recently able to reproduce (different Prisma Client query, but same problem under the hood). We're also aware of performance concerns in some particular cases, which we are investigating. |
We have closed the original issue in |
Bug description
"Joining" 5-6 tables with a data set > 20k rows (not that big) is a bottleneck on the DB given how Prisma does the "joins". Each join creates queries with all the ids from the previous one.
This is a non-issue for the DB when using a join but the way Prisma is doing the "join" it is not performant and the CPU doesn't handle it.
Executing
Where table A will return > 20K rows throws an error
Additional context
Could be related to #4744 and a query optimisation can also resolve this
How to reproduce
Created a repo here: https://github.com/seromenho/prisma-join-performance
Failing test here: https://github.com/seromenho/prisma-join-performance/runs/6396987212?check_suite_focus=true
Expected behaviour
Should not throw an error and execute the query.
Meanwhile, it's not resolved even the error message might be improved as I suspect the reason is that it can't connect but instead related to the length of the queries.
I would expect a real join instead of this design choice of splitting it into multiple smaller sub-queries.
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: