Prisma Studio crashes with large databases
I have the following model:
When i try to view this model in Prisma studio, the tab crashes. The GTFSImport label has only 1 row.
The issue is that all of the relations of this row combined return about 1M records.
It seems like Prisma Studio fetches all relations just to display the relation count in the UI.
Although Prisma Studio uses pagination (Only the first 100) in the model you view, it fetches all relations, making the pagination useless.
Related: https://github.com/prisma/studio/issues/1260
GitHub
Prisma studio easily hits Planetscale's 100,000 row read system lim...
Bug description When prisma studio spins up, it defaults to fetching all of the relations in order to show a count in the UI. This causes it to hit Planetscale's row read limit of 100,000 in a ...
15 Replies
Strangly it only crashes when I open the GTFSImport model (contains only 1 row). Opening all other models works.
"Paused before potential out-of-memory crash"
Hi @schettn 👋
Thank you for raising this. You are correct that at the moment, all relations are loaded by default which might be causing this issue.
We are working on Prisma Studio improvements, so this is something we definitely want to fix 🙏
Hi @Nurul I ran the query inside my service:
So its about 8 seconds. Should Prisma Studio crash in this timeframe?
I believe prisma studio is crashing because the gTFSImport database record has multiple relation fields fetching a large amount of record
What happens if you omit a few relation fields?
I mean only select a subset of relations. Does it still fail?
Querying only the stoptimes takes about 7 seconds. But the StopTimes works well in Prisma Studio
How is this possible? The "Fields" filter only hides the UI elements
I think that prisma studio runs into memory problem when processing this large amout of data client side. So its not directly related to the response time.
I calculated the total size of the query that is performed by Prisma Studio for the GTFSImport table (with relations):
That's possible. I am sharing this with our team internally so that we can improve next iteration of studio and fix these issues
Thanks
Is it a design decision that currently all relation data is fetched, or is it a "bug"?
Because if the relations are only needed for the relation counts then a simple rewrite to this would do the trick:
@Nurul I have reverse engineered the issue.
Take a look at the following code:
prisma studio used this to calculate the
select
. Normally it would use getRelationIDFieldName
to get the primary keys of the relation.
In my case i use compound primary keys like @@id([tripId, stopId, stopSequence, gtfsImportId])
.
With compound keys the getRelationIDFieldName
returns null
, it sets the relation to true
instead using only the primary keys of the relation.---
I fixed this overfetching issue inside Prisma Studio, but it still crashed due to memory.
The root cause is that Prisma Studio loads every record of relations into its
RecordStore
Thanks for debugging 🙏
I shared your observations to our team internally. We are planning on improving memory consumption of Studio.
One idea would be to not load all relations by default and instead give users an option if they would like to load relations or not.