prisma / studio

🎙️ The easiest way to explore and manipulate your data in all of your Prisma projects.
https://www.prisma.io/studio
1.87k stars 48 forks source link

Prisma Studio Out of Memory #1164

Open jacob-hansen opened 1 year ago

jacob-hansen commented 1 year ago

Bug description

Creating a one to many relationship table with a large quantity of many (1M+) causes prisma studio to fail to load the table due to memory issues. This makes sense if I was trying to display the entire row, including the relations. But when I select just a column or two that are not part of the relations, it still fails to load.

How to reproduce

// schema.prisma

datasource db {
  provider = "postgresql" // Change this to the database you are using
  url      = env("DATABASE_URL")
}

model Product {
  id    Int    @id @default(autoincrement())
  name  String
  sales Sale[] // Relation field
}

model Sale {
  id        Int      @id @default(autoincrement())
  saleDate  DateTime
  amount    Float
  productId Int
  product   Product  @relation(fields: [productId], references: [id])
}

// with 2-5 products, write 1M+ sales

Expected behavior

Query just the columns of question as to not run out of memory

Prisma information

prisma                  : 5.3.1
@prisma/client          : 5.1.1
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 61e140623197a131c2a6189271ffee05a7aa9a59 (at node_modules/.pnpm/@prisma+engines@5.3.1/node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Schema Engine           : schema-engine-cli 61e140623197a131c2a6189271ffee05a7aa9a59 (at node_modules/.pnpm/@prisma+engines@5.3.1/node_modules/@prisma/engines/schema-engine-debian-openssl-1.1.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.3.1-2.61e140623197a131c2a6189271ffee05a7aa9a59
Default Engines Hash    : 61e140623197a131c2a6189271ffee05a7aa9a59
Studio                  : 0.494.0

Environment & setup

Prisma logs

prisma:query COMMIT prisma:query SELECT 1 prisma:query BEGIN

phoenix-ru commented 2 days ago

@janpio

I don't know if this is related, but here is the error we are getting when trying to load a table with lots of relations (from our cluster):

node:events:498
      throw er; // Unhandled 'error' event
      ^
Error: ENOENT: no such file or directory, open '/app/node_modules/prisma/engines/34ace0eb2704183d2c05b60b52fba5c43c13f303/libquery_engine-debian-openssl-3.0.x.so.node'
Emitted 'error' event on ReadStream instance at:
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/app/node_modules/prisma/engines/34ace0eb2704183d2c05b60b52fba5c43c13f303/libquery_engine-debian-openssl-3.0.x.so.node'
}
Node.js v22.3.0

It is very consistent and reproduces every time, regardless of:

Changing any params (such as doing Take 1) still crashes the Prisma Studio pod, as I assume it tries to load relations in-memory.

Here's part of our schema.prisma:

generator client {
  provider = "prisma-client-js"
  // TODO: Enabling this actually _reduces_ performance (albeit it should be increasing it). What we are experiencing is similar to the issue described here https://github.com/prisma/prisma/discussions/22288#discussioncomment-7847470
  // previewFeatures = ["relationJoins", "nativeDistinct"]
}

datasource db {
  provider = "postgresql"

  url = env("DATABASE_URL")
}