Skip to content

Remove unused indexes on `merge_requests` table

Related to #402490 (closed)

There are many indexes on the merge_requests table that have no usage or very low usage. All indexes slow down write operations and consume disk space. This is particularly problematic at the moment as the primary database is consuming a lot of CPU. Every update to this table needs to update all references in all indexes so unused indexes are very wasteful for large tables.

Unused indexes

From the the index usage metrics the following indexes have not been used at all in the last 8 weeks:

Index Issue MR
idx_merge_requests_on_state_id_and_merge_status #402490 (closed) !115926 (merged)
index_merge_requests_on_target_project_id_and_iid_jira_title #403327 (closed)
index_merge_requests_on_target_project_id_iid_jira_description #403327 (closed)
merge_request_mentions_temp_index This one !116729 (merged)
merge_requests_state_id_temp_index This one !116726 (merged)

What to do?

Take a look through the indexes and unless you can find a good reason to keep them then create an MR like !115926 (merged) to remove them. Some good reasons to keep them:

  1. They are used for upcoming features that are being implemented or disabled by a feature flag (you can determine this by seeing when they were added)
  2. They are known to be used for self-managed features. To determine this you might need deeper knowledge of the features and possibly looking up the MR that introduced this index. Absent all evidence that it is used for self-managed then we should probably delete them

Availability and Testing

Regression testing, please make sure e2e:package-and-test job is passing.

Process

The process to remove database index uses 3 steps (as documented here: https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#drop-indexes-asynchronously )

  1. Schedule the index to be removed in the database as asynchronously (usually on a weekend):
  1. Verify the MR was deployed and the index doesn't exist in production:
  1. After confirming the indexes are removed, they can be removed from structure.sql synchronously:
Edited by Gary Holtz