Skip to content

Add full index on namespaces for type and id and remove partial index

What does this MR do and why?

As discussed here, add an index on namespaces table targeting type and id.

There currently exists a partial index on these columns

CREATE INDEX "index_namespaces_on_type_and_id_partial" ON "public"."namespaces" USING btree (
  "type" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "id" "pg_catalog"."int4_ops" ASC NULLS LAST
) WHERE type IS NOT NULL;

Since we're making all namespaces have a type, such as User or Group, we now need a full index rather than a partial. The partial will be removed in this MR as well.

Migration

up

== 20211006174114 AddNamespaceIndexOnTypeSync: migrating ======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:namespaces, [:type, :id], {:name=>"index_namespaces_on_type_and_id", :algorithm=>:concurrently})
   -> 0.0110s
-- execute("SET statement_timeout TO 0")
   -> 0.0006s
-- add_index(:namespaces, [:type, :id], {:name=>"index_namespaces_on_type_and_id", :algorithm=>:concurrently})
   -> 0.0060s
-- execute("RESET statement_timeout")
   -> 0.0007s
-- transaction_open?()
   -> 0.0000s
-- indexes(:namespaces)
   -> 0.0081s
-- remove_index(:namespaces, {:algorithm=>:concurrently, :name=>"index_namespaces_on_type_and_id_partial"})
   -> 0.0056s
== 20211006174114 AddNamespaceIndexOnTypeSync: migrated (0.0359s) =============

down

== 20211006174114 AddNamespaceIndexOnTypeSync: reverting ======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:namespaces, [:type, :id], {:where=>"type IS NOT NULL", :name=>"index_namespaces_on_type_and_id_partial", :algorithm=>:concurrently})
   -> 0.0123s
-- execute("SET statement_timeout TO 0")
   -> 0.0013s
-- add_index(:namespaces, [:type, :id], {:where=>"type IS NOT NULL", :name=>"index_namespaces_on_type_and_id_partial", :algorithm=>:concurrently})
   -> 0.0053s
-- execute("RESET statement_timeout")
   -> 0.0008s
-- transaction_open?()
   -> 0.0000s
-- indexes(:namespaces)
   -> 0.0084s
-- remove_index(:namespaces, {:algorithm=>:concurrently, :name=>"index_namespaces_on_type_and_id"})
   -> 0.0078s
== 20211006174114 AddNamespaceIndexOnTypeSync: reverted (0.0397s) =============

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 #342544 (closed)

Edited by Brett Walker

Merge request reports