Commit 6c5d4417 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Add index to improve contribution graph query

Adds an index on created_at so that the queries for a user's
contribution graph is much faster.

Changelog: performance
parent 539a48e8
# frozen_string_literal: true
class CreateCalendarEventsIndexSynchronously < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_events_author_id_project_id_action_target_type_created_at'
def up
add_concurrent_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :events, INDEX_NAME
end
end
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class RemoveOldCalendarEventsIndex < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
OLD_INDEX_NAME = 'index_events_on_author_id_and_project_id'
def up
remove_concurrent_index_by_name :events, OLD_INDEX_NAME
end
def down
add_concurrent_index :events, [:author_id, :project_id], name: OLD_INDEX_NAME
end
end
403592fda1d82ed3c3fb8d5315593b67954a4ecbc368d9bcd5eedc75bb3c9821
\ No newline at end of file
ba1c0d20e21ef51278109d0eaeb23f1c541eb5eb9aeb9a92583ee6de83c68918
\ No newline at end of file
...@@ -25991,14 +25991,14 @@ CREATE INDEX index_et_errors_on_project_id_and_status_first_seen_at_id_desc ON e ...@@ -25991,14 +25991,14 @@ CREATE INDEX index_et_errors_on_project_id_and_status_first_seen_at_id_desc ON e
CREATE INDEX index_et_errors_on_project_id_and_status_last_seen_at_id_desc ON error_tracking_errors USING btree (project_id, status, last_seen_at DESC, id DESC); CREATE INDEX index_et_errors_on_project_id_and_status_last_seen_at_id_desc ON error_tracking_errors USING btree (project_id, status, last_seen_at DESC, id DESC);
CREATE INDEX index_events_author_id_project_id_action_target_type_created_at ON events USING btree (author_id, project_id, action, target_type, created_at);
CREATE INDEX index_events_on_action ON events USING btree (action); CREATE INDEX index_events_on_action ON events USING btree (action);
CREATE INDEX index_events_on_author_id_and_created_at ON events USING btree (author_id, created_at); CREATE INDEX index_events_on_author_id_and_created_at ON events USING btree (author_id, created_at);
CREATE INDEX index_events_on_author_id_and_created_at_merge_requests ON events USING btree (author_id, created_at) WHERE ((target_type)::text = 'MergeRequest'::text); CREATE INDEX index_events_on_author_id_and_created_at_merge_requests ON events USING btree (author_id, created_at) WHERE ((target_type)::text = 'MergeRequest'::text);
CREATE INDEX index_events_on_author_id_and_project_id ON events USING btree (author_id, project_id);
CREATE INDEX index_events_on_created_at_and_id ON events USING btree (created_at, id) WHERE (created_at > '2021-08-27 00:00:00+00'::timestamp with time zone); CREATE INDEX index_events_on_created_at_and_id ON events USING btree (created_at, id) WHERE (created_at > '2021-08-27 00:00:00+00'::timestamp with time zone);
CREATE INDEX index_events_on_group_id_partial ON events USING btree (group_id) WHERE (group_id IS NOT NULL); CREATE INDEX index_events_on_group_id_partial ON events USING btree (group_id) WHERE (group_id IS NOT NULL);
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