Skip to content

Remove index in deployments table asynchronously

What does this MR do and why?

Index: index_deployments_on_environment_id_and_iid_and_project_id

This is part of an epic to optimize the deployments table by removing unused indexes: &10185

The sync index removal will be done in a follow-up MR.

Index definition:

"index_deployments_on_environment_id_and_iid_and_project_id" btree (environment_id, iid, project_id)

This index has a usage of 11.660303887309766 from the last 30 days. However, there is nothing in the GitLab codebase that is actually using this exact combination of indexes (see thread: #402509 (comment 1379476671))

There is a query that uses a combination of project_id and iid, see: https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/deployment.rb#L39 used by https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/graphql/resolvers/deployment_resolver.rb#L17, but there is an index that's only for these 2 fields:

"index_deployments_on_project_id_and_iid" UNIQUE, btree (project_id, iid)

Screenshots or screen recordings

Migration output

main: == [advisory_lock_connection] object_id: 223460, pg_backend_pid: 93744
main: == 20230704050739 PrepareRemovalIndexDeploymentsOnEnvironmentIdAndIidAndProjectId: migrating 
main: -- index_exists?(:deployments, [:environment_id, :iid, :project_id], {:name=>"index_deployments_on_environment_id_and_iid_and_project_id"})
main:    -> 0.1042s
main: -- quote_column_name("index_deployments_on_environment_id_and_iid_and_project_id")
main:    -> 0.0000s
main: == 20230704050739 PrepareRemovalIndexDeploymentsOnEnvironmentIdAndIidAndProjectId: migrated (0.1252s) 

How to set up and validate locally

N/A

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #402509 (closed)

Edited by Pam Artiaga

Merge request reports

Loading