Add unique index on services project_id and type
What does this MR do?
This replaces the previous non-unique index on the same columns.
We don't expect any non-unique records after:
- We enforced this for new records with a validation at the AR layer in !26308 (merged)
- We cleaned up existing records with a data migration in #290008 (closed)
Verified in #database-lab
that the new unique index can still be used for querying:
- Before: https://postgres.ai/console/gitlab/gitlab-production-tunnel/sessions/1837/commands/6176
- After: https://postgres.ai/console/gitlab/gitlab-production-tunnel/sessions/1837/commands/6179
- Creating the unique index took 7.958s
Related to #207385 (closed)
Migration Output
up
$ rake db:migrate:up VERSION=20210126091713
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: migrating ===========
-- transaction_open?()
-> 0.0000s
-- index_exists?(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type_unique", :unique=>true, :algorithm=>:concurrently})
-> 0.0045s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type_unique", :unique=>true, :algorithm=>:concurrently})
-> 0.0140s
-- execute("RESET ALL")
-> 0.0002s
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: migrated (0.0194s) ==
$ rake db:migrate:up VERSION=20210126092102
== 20210126092102 RemoveIndexServicesProjectIdAndType: migrating ==============
-- transaction_open?()
-> 0.0000s
-- indexes(:services)
-> 0.0046s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- remove_index(:services, {:algorithm=>:concurrently, :name=>"index_services_on_project_id_and_type"})
-> 0.0105s
-- execute("RESET ALL")
-> 0.0003s
== 20210126092102 RemoveIndexServicesProjectIdAndType: migrated (0.0160s) =====
down
$ rake db:migrate:down VERSION=20210126092102
== 20210126092102 RemoveIndexServicesProjectIdAndType: reverting ==============
-- transaction_open?()
-> 0.0000s
-- index_exists?(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type", :algorithm=>:concurrently})
-> 0.0063s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type", :algorithm=>:concurrently})
-> 0.0055s
-- execute("RESET ALL")
-> 0.0003s
== 20210126092102 RemoveIndexServicesProjectIdAndType: reverted (0.0130s) =====
$ rake db:migrate:down VERSION=20210126091713
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: reverting ===========
-- transaction_open?()
-> 0.0000s
-- indexes(:services)
-> 0.0142s
-- execute("SET statement_timeout TO 0")
-> 0.0008s
-- remove_index(:services, {:algorithm=>:concurrently, :name=>"index_services_on_project_id_and_type_unique"})
-> 0.0043s
-- execute("RESET ALL")
-> 0.0007s
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: reverted (0.0216s) ==
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
- [-] Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
- [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Markus Koller