Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend adding indices to foreign keys when referentialIntegrity = "prisma" #992

Closed
Tracked by #11441
2color opened this issue Dec 7, 2021 · 1 comment · Fixed by prisma/prisma-engines#3429

Comments

@2color
Copy link

2color commented Dec 7, 2021

Problem

See the problem in more detail here prisma/prisma#7292 (comment)

Basically, when referentialIntegrity = "prisma" no foreign keys are created which means no index is created. When using with PlanetScale this leads to full table scans.

Suggested solution

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider             = "mysql"
  url                  = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

model Post {
  id       Int       @id @default(autoincrement())
  title    String
  excerpt  String
  content  String?
  views    Int       @default(0)
  likes    Int       @default(0)
  comments Comment[]
}

model Comment {
  id      Int    @id @default(autoincrement())
  comment String
  postId  Int
  post    Post   @relation(fields: [postId], references: [id], onDelete: Cascade)

  // ADD RECCOMENDATION TO ADD THIS INDEX
  @@index([postId])
}

Alternatives

Maybe there's a different way to suggest this? I'm not too familiar with all the capabilities of a VS Code plugin.

Additional context

https://briananglin.me/posts/spending-5k-to-learn-how-database-indexes-work/

@Jolg42
Copy link
Member

Jolg42 commented Dec 13, 2021

Related Issue prisma/prisma#10611

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants