Add index to improve query performance

For Environment.deployed_to_cluster
This commit is contained in:
Thong Kuah 2019-08-20 01:17:28 +12:00
parent b34120336d
commit 1dec74808c
3 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
title: Add index to improve group cluster deployments query performance
merge_request: 31988
author:
type: other

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
class AddClusterStatusIndexToDeployments < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :deployments, [:cluster_id, :status]
end
def down
remove_concurrent_index :deployments, [:cluster_id, :status]
end
end

View File

@ -1146,6 +1146,7 @@ ActiveRecord::Schema.define(version: 2019_08_28_083843) do
t.integer "status", limit: 2, null: false
t.datetime_with_timezone "finished_at"
t.integer "cluster_id"
t.index ["cluster_id", "status"], name: "index_deployments_on_cluster_id_and_status"
t.index ["cluster_id"], name: "index_deployments_on_cluster_id"
t.index ["created_at"], name: "index_deployments_on_created_at"
t.index ["deployable_type", "deployable_id"], name: "index_deployments_on_deployable_type_and_deployable_id"