Commit 275ceeee authored by Shinya Maeda's avatar Shinya Maeda

Optimize database query for last deployment

This commit optimizes the database query for
last deployment by introducing a new database index.
parent 17c4304e
---
title: Optimize database query for last deployment
merge_request: 57979
author:
type: performance
# frozen_string_literal: true
class AddIndexForLastDeployment < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_deployments_on_environment_id_status_and_id'
disable_ddl_transaction!
def up
add_concurrent_index :deployments, [:environment_id, :status, :id], name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :deployments, INDEX_NAME
end
end
f27446d1950acaf45f623b2cec7733cd7ba4b82eefddfa2203acbbaf77d59e18
\ No newline at end of file
......@@ -22518,6 +22518,8 @@ CREATE INDEX index_deployments_on_environment_id_and_iid_and_project_id ON deplo
CREATE INDEX index_deployments_on_environment_id_status_and_finished_at ON deployments USING btree (environment_id, status, finished_at);
CREATE INDEX index_deployments_on_environment_id_status_and_id ON deployments USING btree (environment_id, status, id);
CREATE INDEX index_deployments_on_environment_status_sha ON deployments USING btree (environment_id, status, sha);
CREATE INDEX index_deployments_on_id_and_status_and_created_at ON deployments USING btree (id, status, created_at);
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