Improve query performance of attention requests count
In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74800, 2 indexes were added to `merge_request_assignees` and `merge_request_reviewers` tables to improve the performance of the finder query for attention requests. In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80732, the finder query was used to show the count of attention requests. While investigating a bug related to the count, found out that the count query isn't performant enough. Based on this query plan (https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/9497/commands/33700), it takes around 447ms. It's noticeable that the query plan isn't using the index added on the first MR when querying the `merge_request_assignees` and `merge_request_reviewers` tables. To fix this, narrower indexes are added on both tables for `user_id` and `state` columns. This also deletes the `state` indexes that were added before. The query timing dropped to 14ms from 447ms. Query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/9497/commands/33717 Changelog: performance
Showing
Please register or sign in to comment