From 25ce6841a01a8a06fd8ce7191557a06f25eb29cf Mon Sep 17 00:00:00 2001 From: Robert May <rmay@gitlab.com> Date: Mon, 24 Jul 2023 16:15:30 +0100 Subject: [PATCH] Add index to projects on namespace_id and repository_size_limit Changelog: performance --- ...n_namespace_id_and_repository_size_limit.rb | 18 ++++++++++++++++++ db/schema_migrations/20230724150939 | 1 + db/structure.sql | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb create mode 100644 db/schema_migrations/20230724150939 diff --git a/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb b/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb new file mode 100644 index 0000000000000..b066cb248fbfe --- /dev/null +++ b/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class IndexProjectsOnNamespaceIdAndRepositorySizeLimit < Gitlab::Database::Migration[2.1] + INDEX_NAME = "index_projects_on_namespace_id_and_repository_size_limit" + + disable_ddl_transaction! + + def up + add_concurrent_index :projects, [:namespace_id, :repository_size_limit], name: INDEX_NAME + end + + def down + remove_concurrent_index :projects, [:namespace_id, :repository_size_limit], name: INDEX_NAME + end +end diff --git a/db/schema_migrations/20230724150939 b/db/schema_migrations/20230724150939 new file mode 100644 index 0000000000000..c3190c22f278e --- /dev/null +++ b/db/schema_migrations/20230724150939 @@ -0,0 +1 @@ +4047c6746335957fc3d274036e20a176080fb7aa695a98667ed9170370960212 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 39fc992eafe01..d1ef2098cd5c5 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -32718,6 +32718,8 @@ CREATE INDEX index_projects_on_name_trigram ON projects USING gin (name gin_trgm CREATE INDEX index_projects_on_namespace_id_and_id ON projects USING btree (namespace_id, id); +CREATE INDEX index_projects_on_namespace_id_and_repository_size_limit ON projects USING btree (namespace_id, repository_size_limit); + CREATE INDEX index_projects_on_path_and_id ON projects USING btree (path, id); CREATE INDEX index_projects_on_path_trigram ON projects USING gin (path gin_trgm_ops); -- GitLab