Commit b0e07fec authored by pbair's avatar pbair

Indexes for API search of archived Projects

Add two new indexes to support the default search options on archived
projects, since the archived projects are very sparse in the overall
table, leading to slow queries.
parent 5ab115e9
---
title: Improve API response for archived project searchs
merge_request: 27717
author:
type: performance
# frozen_string_literal: true
class AddApiIndexesForArchivedProjects < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
PUBLIC_AND_ARCHIVED_INDEX_NAME = "index_projects_api_created_at_id_for_archived_vis20"
ARCHIVED_INDEX_NAME = "index_projects_api_created_at_id_for_archived"
disable_ddl_transaction!
def up
add_concurrent_index :projects, [:created_at, :id],
where: "archived = true AND visibility_level = 20 AND pending_delete = false",
name: PUBLIC_AND_ARCHIVED_INDEX_NAME
add_concurrent_index :projects, [:created_at, :id], where: "archived = true AND pending_delete = false",
name: ARCHIVED_INDEX_NAME
end
def down
remove_concurrent_index_by_name :projects, ARCHIVED_INDEX_NAME
remove_concurrent_index_by_name :projects, PUBLIC_AND_ARCHIVED_INDEX_NAME
end
end
......@@ -9654,6 +9654,10 @@ CREATE UNIQUE INDEX index_project_tracing_settings_on_project_id ON public.proje
CREATE INDEX index_projects_api_created_at_id_desc ON public.projects USING btree (created_at, id DESC);
CREATE INDEX index_projects_api_created_at_id_for_archived ON public.projects USING btree (created_at, id) WHERE ((archived = true) AND (pending_delete = false));
CREATE INDEX index_projects_api_created_at_id_for_archived_vis20 ON public.projects USING btree (created_at, id) WHERE ((archived = true) AND (visibility_level = 20) AND (pending_delete = false));
CREATE INDEX index_projects_api_last_activity_at_id_desc ON public.projects USING btree (last_activity_at, id DESC);
CREATE INDEX index_projects_api_name_id_desc ON public.projects USING btree (name, id DESC);
......@@ -12793,6 +12797,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200320123839
20200323075043
20200323122201
20200323134519
20200324115359
\.
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