Skip to content

Add a temporary index for Member.state

Vijay Hawoldar requested to merge vij-tmp-member-state-index into master

What does this MR do and why?

Adds a temporary index against Member.state so that we can more efficiently run a data migration to mass update member states (!76653 (merged)).

Further information around the reasoning behind this can be found here: !76750 (comment 790086191)

This index takes the data migration from 117s to 2ms (see thread linked above for more info)

Migrate up

rake db:migrate:up VERSION=20211223125921

== 20211223125921 AddTempIndexToMembersState: migrating =======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:members, :state, {:name=>"tmp_index_members_on_state", :where=>"state = 2", :algorithm=>:concurrently})
   -> 0.0048s
-- execute("SET statement_timeout TO 0")
   -> 0.0007s
-- add_index(:members, :state, {:name=>"tmp_index_members_on_state", :where=>"state = 2", :algorithm=>:concurrently})
   -> 0.0115s
-- execute("RESET statement_timeout")
   -> 0.0008s
== 20211223125921 AddTempIndexToMembersState: migrated (0.0199s) ==============

Migrate down

 rake db:migrate:down VERSION=20211223125921
== 20211223125921 AddTempIndexToMembersState: reverting =======================
-- transaction_open?()
   -> 0.0000s
-- indexes(:members)
   -> 0.0064s
-- execute("SET statement_timeout TO 0")
   -> 0.0007s
-- remove_index(:members, {:algorithm=>:concurrently, :name=>"tmp_index_members_on_state"})
   -> 0.0060s
-- execute("RESET statement_timeout")
   -> 0.0008s
== 20211223125921 AddTempIndexToMembersState: reverted (0.0162s) ==============
  CREATE INDEX tmp_index_members_on_state ON members USING btree (state) WHERE (state = 2)

Time to apply the index in #database-lab:

Cold cache: 1.977 mins (internal slack)

Warm cache: 11.847s (internal slack)

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mayra Cabrera

Merge request reports