-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
INCLUDE
clause on indexes
#8584
Comments
Merging this issue with #14699 which is the same, but on MS SQL Server.
|
INCLUDE
clause on indexes
INCLUDE
clause on indexesINCLUDE
clause on indexes
CockroachDB has its own variant with |
Hello, this is a very unfortunate issue. We have to write a custom index for performance and now it tries to drop it every migration. Can anyone help us understand what to do next here? We don't really know what else to do here other than like delete that line out of every migration? Does anyone have a hack or workaround for this? |
A hint: If you add 'WHERE something IS NOT NULL' to the index, prisma leaves it alone during migration diffing. |
Problem
Postgres has the ability to INCLUDE non-key columns in an index which allows the columns to be returned by the index scan without having to lookup on the table.
https://www.postgresql.org/docs/11/sql-createindex.html
https://www.postgresql.org/docs/11/sql-createindex.html#:~:text=EXISTS%20is%20specified.-,INCLUDE,-The%20optional%20INCLUDE
Currently, prisma migrate dev (or introspection) thinks the non-key columns in the INCLUDE clause are key columns that are part of the index. Instead it should exclude non-key columns when checking for schema drift
Suggested solution
Adding support for INCLUDE clauses in indexes would allow use of this postgres feature. Potential syntax:
@@index([email], include: [id])
Alternatives
Alternative is to omit INCLUDE clauses from the database indexes. Since it affects only db performance, it's not critical for most applications.
Additional context
Original reported as a bug in #8547 which has a minimal repro to test this functionality https://github.com/awinograd/prisma-include-clause-bug
The text was updated successfully, but these errors were encountered: