Commit 78c5f2b3 authored by Reuben Pereira's avatar Reuben Pereira

Add index for project_features.container_registry_access_level

The index can replace the existing
index_project_feature_usages_on_project_id. This commit does
not remove the existing index though, since the existing (and new)
index is a unique index and we don't want there to be no index
for any amount of time.

Changelog: performance
parent 7fafd468
# frozen_string_literal: true
class AddIndexForContainerRegistryAccessLevel < ActiveRecord::Migration[6.1]
include Gitlab::Database::SchemaHelpers
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
INDEX = 'index_project_features_on_project_id_include_container_registry'
def up
if index_exists_by_name?('project_features', INDEX)
Gitlab::AppLogger.warn "Index not created because it already exists (this may be due to an aborted migration or similar): table_name: project_features, index_name: #{INDEX}"
return
end
begin
disable_statement_timeout do
execute "CREATE UNIQUE INDEX CONCURRENTLY #{INDEX} ON project_features " \
'USING btree (project_id) INCLUDE (container_registry_access_level)'
end
rescue ActiveRecord::StatementInvalid => ex
raise "The index #{INDEX} couldn't be added: #{ex.message}"
end
create_comment(
'INDEX',
INDEX,
'Included column (container_registry_access_level) improves performance of the ContainerRepository.for_group_and_its_subgroups scope query'
)
end
def down
remove_concurrent_index_by_name('project_features', INDEX)
end
end
1f99d446428ddac2a0fa7d64bdce9fc300bf02e88c35cdb3d726c501641e721d
\ No newline at end of file
...@@ -24144,6 +24144,10 @@ CREATE UNIQUE INDEX index_project_features_on_project_id ON project_features USI ...@@ -24144,6 +24144,10 @@ CREATE UNIQUE INDEX index_project_features_on_project_id ON project_features USI
CREATE INDEX index_project_features_on_project_id_bal_20 ON project_features USING btree (project_id) WHERE (builds_access_level = 20); CREATE INDEX index_project_features_on_project_id_bal_20 ON project_features USING btree (project_id) WHERE (builds_access_level = 20);
CREATE UNIQUE INDEX index_project_features_on_project_id_include_container_registry ON project_features USING btree (project_id) INCLUDE (container_registry_access_level);
COMMENT ON INDEX index_project_features_on_project_id_include_container_registry IS 'Included column (container_registry_access_level) improves performance of the ContainerRepository.for_group_and_its_subgroups scope query';
CREATE INDEX index_project_features_on_project_id_ral_20 ON project_features USING btree (project_id) WHERE (repository_access_level = 20); CREATE INDEX index_project_features_on_project_id_ral_20 ON project_features USING btree (project_id) WHERE (repository_access_level = 20);
CREATE INDEX index_project_group_links_on_group_id ON project_group_links USING btree (group_id); CREATE INDEX index_project_group_links_on_group_id ON project_group_links USING btree (group_id);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment