Commit f8717400 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ci-improve-users-cancelable-pipelines-query' into 'master'

Improve the perfomance of finding cancelable pipelines for users

See merge request gitlab-org/gitlab!56314
parents 6112adcc 73276dfa
---
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
......@@ -22104,6 +22104,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_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_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