Skip to content

Add index for merge_requests.merge_commit_sha

This adds a composite index on (target_project_id, merge_commit_sha, id), solving the problem described in https://gitlab.com/gitlab-org/gitlab-ce/issues/38507.

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 & Timings

== 20170928100231 AddCompositeIndexOnMergeRequestsMergeCommitSha: migrating ===                                                                                                                                                                                                                                                
-- transaction_open?()                                                                                                                                                                                                                                                                                                         
   -> 0.0000s                                                                                                                                                                                                                                                                                                                  
-- execute("SET statement_timeout TO 0")                                                                                                                                                                                                                                                                                       
   -> 0.0003s                                                                                                                                                                                                                                                                                                                  
-- add_index(:merge_requests, [:target_project_id, :merge_commit_sha, :id], {:name=>"index_merge_requests_on_tp_id_and_merge_commit_sha_and_id", :algorithm=>:concurrently})                                                                                                                                                   
   -> 0.0168s                                                                                                                                                                                                                                                                                                                  
== 20170928100231 AddCompositeIndexOnMergeRequestsMergeCommitSha: migrated (0.0173s)           

General Checklist

Merge request reports