question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Very slow nested writes when connecting with remote DB Postrgsql on AWS

See original GitHub issue

I am currently testing different ORMs to find a good fit for our project. I write a very basic query with a nested write in Prisma which takes an extremly long time.

See my schema:

model Context {
  id          Int         @id @default(autoincrement())
  contextName String
  createdAt   DateTime    @default(now())
  statements  Statement[]
}

model Statement {
  id        Int      @id @default(autoincrement())
  content   String
  context   Context  @relation(fields: [contextId], references: [id], onDelete: Cascade)
  contextId Int
  createdAt DateTime @default(now())
}

I create a new context with around 600 statements inside. This the code sample:

const context = await this.prisma.context.create({
      data: {
        contextName: contextData.name,
        statements: {
          create: statements,
        },
      },
      include: {
        statements: true,
      },
    });

I’ve tried to debug the request but haven’t noticed anything suspicious from the Prisma output.

Check out the repo to see the full code and the request.

If I write to the local DB with prisma it takes around 4s vs to remote DB is more than 100s

The same operation with typeorm takes around 2s to the remote DB.

Any hints on how can improve the query?

_Originally posted by @monapasan in https://github.com/prisma/prisma/discussions/9552_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
TasinIshmamcommented, Oct 25, 2021

It is not. See here. Moreover you make a point on your website when comparing typeorm and prisma about nested writes. I hope this has not been left out intentionally. Many thanks for your reply and your help! And let me know if I should create a PR to the docs with this information. Happy to contribute!

I understand your point. Thanks for agreeing to help, I have already created an issue about this in the docs repository. Please feel free to follow it or drop a comment if you have any suggestions!

And you can be assured this wasn’t an intentional omission 😅

1reaction
TasinIshmamcommented, Oct 22, 2021

This solution worked very well. It’s fast enough. This also has fixed my issue with MongoDB. Thank you so much!

Awesome. Glad I could help 😄

This is such a crucial point. I am wondering why do you not mention this in the API docs? Specifically, that you create a separate query for every nested write?

This is a very good point. We need to make this information more discoverable if it isn’t already. I will make sure to bring this up internally 👌

Btw I’m closing this issue as I’m assuming your problem has been resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma: very slow nested writes when connecting with remote ...
When connecting to PostgreSQL on AWS it goes up to 90 seconds. Any ideas why is it taking so long? Please find an...
Read more >
Troubleshoot performance issues in RDS and Aurora ...
My Amazon Relational Database Service (Amazon RDS) for PostgreSQL instance is slow. I want to identify and troubleshoot the slow-running ...
Read more >
Improving query performance - Amazon Redshift
To fix this issue, run ANALYZE. Nested loop. If a nested loop is present, you might see a nested loop alert event in...
Read more >
Factors affecting query performance - Amazon Redshift
Dataset size – A higher volume of data in the cluster can slow query performance for queries, because more rows need to be...
Read more >
Diagnostic queries for query tuning - Amazon Redshift
This topic provides queries to identify issues with queries or their underlying tables that can affect query performance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found