Commit 49aed743 authored by Eulyeon Ko's avatar Eulyeon Ko

Index issues on project_id, state_id, created, id

The following existing index
'idx_issues_on_project_id_and_created_at_and_id_and_state_id'
has `state_id` as the last column.

Because GitLab's domain logic usually requires querying
issues in a particular state and the primary key comes before
state_id, the above existing index could prevent a range scan.

The newly added index modifies the order of the columns.
(project_id, state_id, created_at, id).

We will add the new index and collect data on the old and new
indices before disabling/eventually retiring one of them.

Changelog: added
parent 80c745a3
# frozen_string_literal: true
class AddIndexIssuesOnProjectIdAndStateIdAndCreatedAtAndId < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_issues_on_project_id_and_state_id_and_created_at_and_id'
disable_ddl_transaction!
def up
add_concurrent_index :issues, [:project_id, :state_id, :created_at, :id], name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :issues, INDEX_NAME
end
end
1b55c50a9ba085ae7a0552da4985755c67eafb74e76b06590179803b4b215f81
\ No newline at end of file
......@@ -24100,6 +24100,8 @@ CREATE UNIQUE INDEX index_issues_on_project_id_and_external_key ON issues USING
CREATE UNIQUE INDEX index_issues_on_project_id_and_iid ON issues USING btree (project_id, iid);
CREATE INDEX index_issues_on_project_id_and_state_id_and_created_at_and_id ON issues USING btree (project_id, state_id, created_at, id);
CREATE INDEX index_issues_on_project_id_and_upvotes_count ON issues USING btree (project_id, upvotes_count);
CREATE INDEX index_issues_on_promoted_to_epic_id ON issues USING btree (promoted_to_epic_id) WHERE (promoted_to_epic_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