Hello all, we use a nodejs prisma backend hosted o...
# orm-help
n
Hello all, we use a nodejs prisma backend hosted on Heroku. When we perform certain queries, that involve nested queries on child tables, we lose connection to the database ("Can't reach database server"):
Copy code
"Can't reach database server at `<http://ec2-3-68-54-65.eu-central-1.compute.amazonaws.com|ec2-3-68-54-65.eu-central-1.compute.amazonaws.com>`:`5432`
Please make sure your database server is running at `<http://ec2-3-68-54-65.eu-central-1.compute.amazonaws.com|ec2-3-68-54-65.eu-central-1.compute.amazonaws.com>`:`5432`.
\",\"stack\":\"Error: Can't reach database server at `<http://ec2-3-68-54-65.eu-central-1.compute.amazonaws.com|ec2-3-68-54-65.eu-central-1.compute.amazonaws.com>`:`5432`
Please make sure your database server is running at `<http://ec2-3-68-54-65.eu-central-1.compute.amazonaws.com|ec2-3-68-54-65.eu-central-1.compute.amazonaws.com>`:`5432`.
at Object.request (/app/node_modules/@prisma/client/runtime/index.js:45629:15)
at async PrismaClient._request (/app/node_modules/@prisma/client/runtime/index.js:46456:18)
at async getDataFromNestedQuery (/app/src/api/v3/nestedqueryendpoint/controller.js:228:24)\"}}"
1. When checking the backend-logs we noticed that Prisma runs a nested query instead of a JOIN query (a similar issue is mentioned in https://github.com/seromenho/prisma-join-performance). Can we change the generated queries to a JOIN query? Anybody faced a similar issue? 2. Does setting the
connection_limit=1
help? Unfortunately in heroku we are unable to append it to the DATABASE_URL variable. Does anybody have experience with this?
👀 2
n
Hey 👋 1. It's not possible at the moment to convert the internal query to use JOIN, what is the size of your dataset? 2. Do you get any error if you append
connection_limit
parameter? You might be interested in this thread: https://prisma.slack.com/archives/CA491RJH0/p1650467459626829
n
We query around 90k records in the query. It's the same issue that Ricardo described. Looks like we need to replace the prisma query with a raw query that uses JOIN. Or is there any better way to overcome this?
n
As of now, Raw query would be ideal solution
👍 1