Commit ab7bb183 authored by Tan Le's avatar Tan Le

Add index for compliance merged MRs to events

This helps to improve query time on Compliance Dashboard where we query
for latest merged action events across projects. This change also
benefits count query which is later invoked on the tab headers.
parent e9dc7f29
---
title: Add index for compliance merged MRs to events
merge_request: 38885
author:
type: performance
# frozen_string_literal: true
class AddIndexForComplianceMergedMergeRequestToEvents < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_events_on_project_id_and_id_desc_on_merged_action'
disable_ddl_transaction!
def up
add_concurrent_index :events, [:project_id, :id],
order: { id: :desc },
where: "action = 7", name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :events, INDEX_NAME
end
end
a1fb6b5d486eee27aaed5083aa6340073bf05abab8f201fd9097374dbd345b90
\ No newline at end of file
......@@ -19572,6 +19572,8 @@ CREATE INDEX index_events_on_project_id_and_created_at ON public.events USING bt
CREATE INDEX index_events_on_project_id_and_id ON public.events USING btree (project_id, id);
CREATE INDEX index_events_on_project_id_and_id_desc_on_merged_action ON public.events USING btree (project_id, id DESC) WHERE (action = 7);
CREATE INDEX index_events_on_target_type_and_target_id ON public.events USING btree (target_type, target_id);
CREATE UNIQUE INDEX index_events_on_target_type_and_target_id_and_fingerprint ON public.events USING btree (target_type, target_id, fingerprint);
......
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