Skip to content

Remove redundant index_events_on_target_type_and_target_id

Tiger Watson requested to merge remove-redundant-events-index into master

What does this MR do and why?

The events table has these two indexes:

CREATE INDEX index_events_on_target_type_and_target_id ON events USING btree (target_type, target_id);

CREATE UNIQUE INDEX index_events_on_target_type_and_target_id_and_fingerprint ON events USING btree (target_type, target_id, fingerprint);

The former is made redundant by the latter, so we can remove it.

This will free up ~30G of space.

Screenshots or screen recordings

== 20211104044453 RemoveRedundantEventsIndex: reverting =======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:events, [:target_type, :target_id], {:name=>:index_events_on_target_type_and_target_id, :algorithm=>:concurrently})
   -> 0.0063s
-- execute("SET statement_timeout TO 0")
   -> 0.0007s
-- add_index(:events, [:target_type, :target_id], {:name=>:index_events_on_target_type_and_target_id, :algorithm=>:concurrently})
   -> 0.0081s
-- execute("RESET statement_timeout")
   -> 0.0007s
== 20211104044453 RemoveRedundantEventsIndex: reverted (0.0180s) ==============

== 20211104044453 RemoveRedundantEventsIndex: migrating =======================
-- transaction_open?()
   -> 0.0000s
-- indexes(:events)
   -> 0.0104s
-- execute("SET statement_timeout TO 0")
   -> 0.0007s
-- remove_index(:events, {:algorithm=>:concurrently, :name=>:index_events_on_target_type_and_target_id})
   -> 0.0049s
-- execute("RESET statement_timeout")
   -> 0.0011s
== 20211104044453 RemoveRedundantEventsIndex: migrated (0.0195s) ==============

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