Skip to content

Add index on snippets type and id attributes

What does this MR do?

Adds a new index to the snippets table to help with count queries for usage data.

Some of the generated queries take more than 1s to finish so usually an index is added to optimize them.

See !32885 (merged)'s description for more details.

Relates to #215200 (closed)

Output from the migration

Up

VERBOSE=true bundle exec rake db:migrate:up VERSION=20200522235146
== 20200522235146 AddIndexOnSnippetTypeAndId: migrating =======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:snippets, [:id, :type], {:algorithm=>:concurrently})
   -> 0.0050s
-- add_index(:snippets, [:id, :type], {:algorithm=>:concurrently})
   -> 0.0040s
== 20200522235146 AddIndexOnSnippetTypeAndId: migrated (0.0094s) ==============

Down

VERBOSE=true bundle exec rake db:migrate:down VERSION=20200522235146
== 20200522235146 AddIndexOnSnippetTypeAndId: reverting =======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:snippets, [:id, :type], {:algorithm=>:concurrently})
   -> 0.0059s
-- remove_index(:snippets, {:algorithm=>:concurrently, :column=>[:id, :type]})
   -> 0.0086s
== 20200522235146 AddIndexOnSnippetTypeAndId: reverted (0.0149s) ==============

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports

Loading