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
feat(psl): add validation + warning on missing indexes for relationMode = "prisma"
#3429
Conversation
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few things.
I also think we're missing a test for the case where fields
in the relation is a prefix of an indexe's fields.
Also we're missing code that wolud consider the primary key (which is also an index), but let's make that a separate issue/PR.
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
...ation/attributes/index/missing_index_warning/relation_mode_prisma/one_field_at_unique.prisma
Show resolved
Hide resolved
.any(|index_set| is_left_wise_included(&relation_fields, index_set)); | ||
|
||
if !relation_fields_appear_in_index { | ||
let span = relation_field.ast_field().field_type.span(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The highlighting is going to be on the field type, so only the OtherModel
part in other OtherModel @relation(...)
. I think it would be more readable for users if we highlighted the whole field. So relation_field.ast_field().span
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I had a doubt about this span here. I think we mentioned elsewhere in the Notion doc that we wanted to highlight the @relation
attribute.
Hence, I'd propose the following
let span = ast_field
.span_for_attribute("relation")
.unwrap_or_else(|| ast_field.span());
which falls back to your solution
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
...on/attributes/index/missing_index_warning/relation_mode_prisma/one_field_at_at_unique.prisma
Show resolved
Hide resolved
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
…or better readability
…the rest of index validations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for updated warning message.
About @tomhoule's comment:
Do you mean something like model SomeUser {
id Int @id
successor SomeUser? @relation("UserHistory")
predecessorId Int? @unique
predecessor SomeUser? @relation("UserHistory", fields: [id], references: [id])
} ? |
/// Pure convenience method. Forwards to Diagnostics::push_warning(). | ||
pub(super) fn push_warning(&mut self, warning: DatamodelWarning) { | ||
self.diagnostics.push_warning(warning); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also useful for https://github.com/prisma/prisma-private/issues/198 and for #3435
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small things. Ping me when done, and I'll approve!
psl/psl-core/src/validate/validation_pipeline/validations/relation_indexes.rs
Outdated
Show resolved
Hide resolved
...ation/attributes/index/missing_index_warning/relation_mode_prisma/one_field_at_unique.prisma
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, didn't mean to press approve yet
Note: we can do changes in a follow-up PR, we really need to merge this asap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error msg feedback was ignored, left 2 comments.
Github Actions is green, Buildkite is all green except CockroachDB, which is in progress. I'm merging |
Context: internal Notion doc.
This new validation is disabled when one of the following holds:
relationMode = "foreignKeys"
(or similarly, when norelationMode
is specified)provider = "mongodb"
Contributes to prisma/language-tools#1296.
Closes prisma/language-tools#992.
TODOs (which do not block this PR):
create ahttps://pris.ly/d/relation-mode-prisma-indexes
link in https://github.com/prisma/pris.lypreviewFeatures = ["referentialIntegrity"]
from newly added tests when chore: make referentialIntegrity preview feature GA #3428 is merged.Warning message:
"""
With
relationMode = \"prisma\"
, no foreign keys are used, so relation fields will not benefit from the index usually created by the relational database under the hood.This can lead to poor performance when querying these fields. We recommend adding an index manually.
Learn more at https://pris.ly/d/relation-mode#indexes"
"""