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.

Unusually high row reads

See original GitHub issue

Bug description

This issue can probably largely be ignored because it’s likely an edge case, but wanted to post it here for anyone else running into a similar issue.

A month ago, I noticed extremely high row reads in our PlanetScale database — over 1 billion row reads over a period of 30 days (our plan only allotted us 100M row reads per month). For a small app with a database of ~56K, these many row reads pointed to an error somewhere.

How to reproduce

It turns out that a nested some: {} Prisma query was responsible for the excess. I had implemented the following schema that accounted for a User as well as a UserAlias table since some users used multiple email addresses to sign in, and we wanted to make sure that whichever email they used would get them to the same account:

model User {
  UserAliases      UserAlias[] @relation("UserAliasesToOUser")
  UserAlias        UserAlias?  @relation("OUserAliasToOUser")
  email            String      @unique
}

model UserAlias {
  id          String   @id @default(uuid())
  User        User?    @relation("UserAliasesToOUser", fields: [userEmail], references: [email])
  userEmail   String? // User’s default email
  Alias       User?    @relation("OUserAliasToOUser", fields: [aliasEmail], references: [email])
  aliasEmail  String?  @unique

  @@index([aliasEmail])
  @@index([userEmail])
}

Each time a user logged in, the following Prisma query was run:

prisma1

The purpose of this was to get the user’s information, regardless of which email they used.

It turns out that doing a nested query using some: {} effectively scans the entire table. So each time a user logged in, all 56K records where read, and this soon ended up being over a billion rows being read each month.

The fix itself was easy: I just broke up the where query into two separate Prisma reads:

prisma2

Expected behavior

No response

Prisma information

See above.

Environment & setup

  • OS: macOS
  • Database: MySQL using PlanetScale
  • Node.js version: v16.10.0

Prisma Version

v3.4.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
heymartinadamscommented, Feb 2, 2022

Sorry my delay @janpio. I’ve definitely been including indices (@@index([someId])) according to recommended guidelines.

1reaction
pantharshit00commented, Jan 10, 2022

Thanks for the details. I can also confirm that some is causing the read upsurge here. We should review its implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Machine High Row: Correct Form, Muscles Worked, & ...
Back rows and massive backs go together like the bench press and a huge chest. It just makes sense. They are an extremely...
Read more >
BI performance counter: Rows read
This page explains BI Performance counter Rows read which keeps track of total number of input rows that have been read.
Read more >
High Row - Back Exercises
Stand with the feet hip-width apart, the hips straight, the back tall, and the knees slightly bent. Place the cable pulley at about...
Read more >
How to Do Machine High Rows (Form & Benefits)
Machine high rows can build strength and muscle in your back! ... to your muscle groups and can be very beneficial to muscle...
Read more >
Machine High Row Exercise: Benefits And Alternatives - SOMA
Exercise Overview. If you don't have time to read the entire article, check out this lists of exercises you can incorporate into your...
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