Skip to content

Conversation

@jmgasper
Copy link
Contributor

No description provided.

@jmgasper jmgasper requested a review from kkartunov October 31, 2025 04:34
@@ -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 EXTENSION IF NOT EXISTS pg_trgm;

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_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.

@@index([status, startDate])
@@index([trackId, typeId, status])
@@index([status, typeId, trackId, createdAt(sort: Desc)], map: "challenge_status_type_track_created_at_idx")
@@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([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.

Copy link
Contributor

@kkartunov kkartunov left a comment

Choose a reason for hiding this comment

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

Looks good.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants