Skip to content

Reorganize indexes for the "deployments" table

yorickpeterse-staging requested to merge reoganize-deployment-indexes into master

This reorganises some of the indexes on deployments to remove the need for a default scope as added in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14252.

Database Checklist

When adding migrations:

  • Updated db/schema.rb
  • Added a down method so the migration can be reverted
  • Added the output of the migration(s) to the MR body
  • Added the execution time of the migration(s) to the MR body
  • Made sure the migration won't interfere with a running GitLab cluster, for example by disabling transactions for long running migrations

When adding indexes:

  • Described the need for these indexes in the MR body
  • Made sure existing indexes can not be reused instead

Migration Output

== 20170918222253 ReorganizeDeploymentsIndexes: migrating =====================
-- index_exists?(:deployments, [:environment_id, :iid, :project_id])
   -> 0.0024s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- add_index(:deployments, [:environment_id, :iid, :project_id], {:algorithm=>:concurrently})
   -> 0.0398s
-- index_exists?(:deployments, [:project_id, :environment_id, :iid])
   -> 0.0022s
-- transaction_open?()
   -> 0.0000s
-- select_one("SELECT current_setting('server_version_num') AS v")
   -> 0.0004s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- remove_index(:deployments, {:algorithm=>:concurrently, :column=>[:project_id, :environment_id, :iid]})
   -> 0.0065s
== 20170918222253 ReorganizeDeploymentsIndexes: migrated (0.0521s) ============

== 20170918223303 AddDeploymentsIndexForLastDeployment: migrating =============                                                                                                                                      
-- transaction_open?()                                                                                                                                                                                               
   -> 0.0000s                                                                                                                                                                                                        
-- execute("SET statement_timeout TO 0")                                                                                                                                                                             
   -> 0.0003s                                                                                                                                                                                                        
-- add_index(:deployments, [:environment_id, :id], {:algorithm=>:concurrently})                                                                                                                                      
   -> 0.0183s                                                                                                                                                                                                        
== 20170918223303 AddDeploymentsIndexForLastDeployment: migrated (0.0188s) ====

General Checklist

Merge request reports