Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Add indexes to support faster `/v6/my-reviews` queries.

CREATE EXTENSION IF NOT EXISTS pg_trgm;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Ensure that the pg_trgm extension is supported and available in all environments where this migration will be applied. If not, this could lead to errors during deployment.


CREATE INDEX IF NOT EXISTS "challenge_status_type_track_created_at_idx"
ON "Challenge" ("status", "typeId", "trackId", "createdAt" DESC);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
Consider the impact of the createdAt DESC ordering on the index size and performance. If the table is large, this could affect write performance. Evaluate if this ordering is necessary for the query patterns.


CREATE INDEX IF NOT EXISTS "challenge_phase_challenge_open_end_idx"
ON "ChallengePhase" ("challengeId", "isOpen", "scheduledEndDate", "actualEndDate");

CREATE INDEX IF NOT EXISTS "challenge_name_trgm_idx"
ON "Challenge"
USING gin ("name" gin_trgm_ops);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
Using a GIN index with gin_trgm_ops on the name column can significantly increase storage requirements. Ensure that this trade-off is justified by the performance gains in query execution.

3 changes: 3 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ model Challenge {
@@index([endDate])
@@index([status, startDate])
@@index([trackId, typeId, status])
@@index([status, typeId, trackId, createdAt(sort: Desc)], map: "challenge_status_type_track_created_at_idx")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
The new composite index [status, typeId, trackId, createdAt(sort: Desc)] could potentially improve query performance if these fields are frequently queried together. However, be cautious of the increased write overhead due to maintaining multiple indices. Consider analyzing query patterns to ensure this index is necessary.

@@index([name], type: Gin, ops: [gin_trgm_ops], map: "challenge_name_trgm_idx")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The use of a GIN index with gin_trgm_ops on the name field is appropriate for text search. However, ensure that the pg_trgm extension is enabled in your PostgreSQL database, as it is required for gin_trgm_ops to function correctly.

@@index([legacyId])
@@index([projectId, status])
}
Expand Down Expand Up @@ -540,6 +542,7 @@ model ChallengePhase {
@@index([challengeId])
@@index([challengeId, isOpen])
@@index([challengeId, name])
@@index([challengeId, isOpen, scheduledEndDate, actualEndDate], map: "challenge_phase_challenge_open_end_idx")
}

//////////////////////////////////////////
Expand Down