language-tools
language-tools copied to clipboard
Recommend adding indices to foreign keys when `referentialIntegrity = "prisma"`
Problem
See the problem in more detail here https://github.com/prisma/prisma/issues/7292#issuecomment-963118192
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/
Related Issue https://github.com/prisma/prisma/issues/10611