studio icon indicating copy to clipboard operation
studio copied to clipboard

Prisma Studio handles models with n:m relations in a way that makes it unusable for larger DBs

Open henrikuper opened this issue 3 years ago • 9 comments

Bug description

I use Prisma Studio in the browser as well as the Mac app.

Prisma studio throws timeouts when querying some tables or is extremely slow or freezes all the time. I guess this is because the requested data comes from a model that has n:m relations. Some of these relations have over 10000 connections. I guess Prisma studio uses the include option for all attributes. This leads to more than 10,000 connections being requested and sent. Since this leads to very large amounts of data, it results in a timeout/freeze.

For example, imagine you have a model user with the attribute Follower. A user has 10k followers. Prisma studio would then request the data of all 10k followers as soon as this user is requested.

Even if you unselect certain attributes in Prisma studio, they are still requested.

How to reproduce

  1. create a model User with the n:m relation follower
  2. create 100k user and connect them with each other
  3. open Prisma Studio and open the model user

Maybe not on local host but definitely on dev/prod server the query will timeout or take forever.

Expected behavior

There is more than one option:

  • not query (not include) not selected attributes of a model
  • only query connected objects, if you click on a specific object and not by default.

Maybe you have some more or better ideas.

Prisma information

Just use a schema with large n:m relations

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL

Prisma Version

prisma 2.27.0

henrikuper avatar Jul 27 '21 17:07 henrikuper

Hey @henrikuper yeah your assessment is 100% correct:

Right now, Studio does a include for all relations of a model when you open the model. All it needs is the number of relation connections to display the count, so I can aggregate this separately. That should help significantly.

sdnts avatar Jul 29 '21 15:07 sdnts

Hi @madebysid Thanks for pointing that out. I know that the include is currently also used to click on the connections to manually add / remove connections. But it would safe a lot of time, if this would happen in a second query as soon as it is needed (most of the time it is not needed).

henrikuper avatar Jul 29 '21 15:07 henrikuper

Hey there! I just upgraded prisma to the 2.29 version, as I was facing this issue on a large db with many relations. This issue has been added to the 2.29 milestone, but prisma studio still behave in the same way it did before, performing an include of all the related model in the first query, making prisma studio to collapse as soon as I try to view some data.

Which is the milestone to expect this fix in? thank you!

tobiaghiraldini avatar Aug 16 '21 13:08 tobiaghiraldini

@madebysid any update here? Still having the issue. I really cant work with studio right now. It takes up to 1 min to load the lists...

It would already help if you would allow to only load 10 or 5 objects instead of 100 as a default. This would not solve the issue, but it would decrease the time by 90% Which would be ok for the time until there is a real fix/improvement.

henrikuper avatar Sep 15 '21 10:09 henrikuper

I'm looking into a bunch of Studio issues this week, and this is pretty high on that list. I will try my best to make sure this gets shipped with the next stable version of Prisma (scheduled for next Tuesday), but I should be able to ship a dev version before that with the fix. I will let you know when that happens.

Thanks for being patient!

sdnts avatar Sep 15 '21 11:09 sdnts

@madebysid Have you had the time to look at the problem? The bigger the database gets, the worse the problem gets... meanwhile I can't look at more than half of the tables, because they all don't load within several minutes...

I now have to build a script for everything I want to read/write. This really can't be the solution.

henrikuper avatar Nov 16 '21 18:11 henrikuper

I'm having this issue as well with relations with hundreds of thousands of records. My suggestion would be some kind of flag that turns off the row count, if it is otherwise not possible to optimize this further.

NicolajKN avatar Mar 16 '22 11:03 NicolajKN

For me, the problem starts much earlier - I have just hundreds of records.

I have a User model and 7 other models that links to it.

Prisma Studio fails to load User list when I have just hundreds of records in tables.

neoromantic avatar Jul 04 '22 12:07 neoromantic

Any updates on this one?

salcedosalad avatar Mar 22 '24 08:03 salcedosalad