oliver bagin
oliver bagin
PPrisma
Created by oliver bagin on 8/15/2024 in #help-and-questions
Prisma gets very slow...
TLDR: My query gets massively slower when I add another join that also has another join in it. I have a query, which is pretty big here it is:
selectFullVenue = Prisma.validator<Prisma.VenueInclude>()({
address: true,
location: true,
images: {.},
events: {.},
stars: {.},
busyness: {.},
busynessPredictions: {.},
_count: {.},
// openingHours: {
// orderBy: {
// timeStamp: 'desc'
// },
// take: 1,
// include: {
// hours: true
// }
// },
tags: {.}
}
})
selectFullVenue = Prisma.validator<Prisma.VenueInclude>()({
address: true,
location: true,
images: {.},
events: {.},
stars: {.},
busyness: {.},
busynessPredictions: {.},
_count: {.},
// openingHours: {
// orderBy: {
// timeStamp: 'desc'
// },
// take: 1,
// include: {
// hours: true
// }
// },
tags: {.}
}
})
This query takes about 300ms and when I wrap it in a find many like below it takes about 1-2seconds.
const stars = await prisma.stars.findMany({
include: {
venue: {
include: selectFullVenue
}
},
where: {
userId
},
relationLoadStrategy: 'join'
})
const stars = await prisma.stars.findMany({
include: {
venue: {
include: selectFullVenue
}
},
where: {
userId
},
relationLoadStrategy: 'join'
})
This is slow but not the main problem I have. As you can see some of the query is commented out, when I uncomment this my query time on the 'find many' jumps to over one minuet! There are about 1m entries in openingHours and about 5m in openingHoursData. I feel like this massive jump in query time must be some missing index or potentially a bad query being generated from prisma? Any help would be appreciated! I have attached the explain plan and the graph for the non prod server which unfortunately does not have much data in it. The relevent part of my schema is also included.
3 replies