Skip to content

Remove unnecessary index on services for usage data

What does this MR do?

After adding index_services_on_type_id_when_active_and_project_id_not_null index in !44726 (merged), we can remove index_services_on_type_id_when_active_not_instance_not_template.

  • index_services_on_type_id_when_active_not_instance_not_template was added !27093 (merged) and updated !38147 (merged) just for the usage data.
  • There is no other query for template = FALSE in the codebase.
  • We will maintain the partial index for (type, id).

Migration script output

$ rails db:migrate
== 20201020102551 RemoveIndexServiceForUsageData: migrating ===================
-- transaction_open?()
   -> 0.0000s
-- indexes(:services)
   -> 0.0050s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- remove_index(:services, {:algorithm=>:concurrently, :name=>"index_services_on_type_id_when_active_not_instance_not_template"})
   -> 0.0033s
-- execute("RESET ALL")
   -> 0.0002s
== 20201020102551 RemoveIndexServiceForUsageData: migrated (0.0092s) ==========
$ rails db:migrate:down VERSION=20201020102551
== 20201020102551 RemoveIndexServiceForUsageData: reverting ===================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:services, [:type, :id], {:where=>"active = TRUE AND instance = FALSE AND template = FALSE", :name=>"index_services_on_type_id_when_active_not_instance_not_template", :algorithm=>:concurrently})
   -> 0.0045s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- add_index(:services, [:type, :id], {:where=>"active = TRUE AND instance = FALSE AND template = FALSE", :name=>"index_services_on_type_id_when_active_not_instance_not_template", :algorithm=>:concurrently})
   -> 0.0034s
-- execute("RESET ALL")
   -> 0.0002s
== 20201020102551 RemoveIndexServiceForUsageData: reverted (0.0086s) ==========

Closes #268248 (closed)

Edited by Arturo Herrero

Merge request reports