Commit 73276dfa authored by Marius Bobin's avatar Marius Bobin Committed by Mayra Cabrera

Add database index for cancelable ci_pipelines on user_id and id

It improves the performance of the query that searches for cancelable
pipelines for a given user.
parent 3f1c24ce
---
title: Add database index for cancelable ci_pipelines on user and id
merge_request: 56314
author:
type: performance
# frozen_string_literal: true
class AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_ci_pipelines_on_user_id_and_id_and_cancelable_status'
INDEX_FILTER_CONDITION = <<~SQL
((status)::text = ANY (
ARRAY[
('running'::character varying)::text,
('waiting_for_resource'::character varying)::text,
('preparing'::character varying)::text,
('pending'::character varying)::text,
('created'::character varying)::text,
('scheduled'::character varying)::text
]
))
SQL
disable_ddl_transaction!
def up
add_concurrent_index :ci_pipelines, [:user_id, :id], where: INDEX_FILTER_CONDITION, name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :ci_pipelines, INDEX_NAME
end
end
6af1c870e685b5a7fbc31b658959018c313713f0f35ad776f97d0a804f1c0f05
\ No newline at end of file
...@@ -22103,6 +22103,8 @@ CREATE INDEX index_ci_pipelines_on_user_id_and_created_at_and_config_source ON c ...@@ -22103,6 +22103,8 @@ CREATE INDEX index_ci_pipelines_on_user_id_and_created_at_and_config_source ON c
CREATE INDEX index_ci_pipelines_on_user_id_and_created_at_and_source ON ci_pipelines USING btree (user_id, created_at, source); CREATE INDEX index_ci_pipelines_on_user_id_and_created_at_and_source ON ci_pipelines USING btree (user_id, created_at, source);
CREATE INDEX index_ci_pipelines_on_user_id_and_id_and_cancelable_status ON ci_pipelines USING btree (user_id, id) WHERE ((status)::text = ANY (ARRAY[('running'::character varying)::text, ('waiting_for_resource'::character varying)::text, ('preparing'::character varying)::text, ('pending'::character varying)::text, ('created'::character varying)::text, ('scheduled'::character varying)::text]));
CREATE UNIQUE INDEX index_ci_project_monthly_usages_on_project_id_and_date ON ci_project_monthly_usages USING btree (project_id, date); CREATE UNIQUE INDEX index_ci_project_monthly_usages_on_project_id_and_date ON ci_project_monthly_usages USING btree (project_id, date);
CREATE UNIQUE INDEX index_ci_refs_on_project_id_and_ref_path ON ci_refs USING btree (project_id, ref_path); CREATE UNIQUE INDEX index_ci_refs_on_project_id_and_ref_path ON ci_refs USING btree (project_id, ref_path);
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