Commit 405d079c authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '208923-enable-batch-counting-for-some-individual-queries-4' into 'master'

Optimize projects_service_active queries

See merge request gitlab-org/gitlab!27093
parents 59b731a5 3a44d110
---
title: Optimize projects_service_active queries performance in usage data
merge_request: 27093
author:
type: performance
# frozen_string_literal: true
class AddIndexOnActiveAndTemplateAndTypeAndIdToServices < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_services_on_type_and_id_and_template_when_active'
disable_ddl_transaction!
def up
add_concurrent_index :services, [:type, :id, :template], where: 'active = TRUE', name: INDEX_NAME
end
def down
remove_concurrent_index :services, INDEX_NAME
end
end
......@@ -3977,6 +3977,7 @@ ActiveRecord::Schema.define(version: 2020_03_13_123934) do
t.boolean "instance", default: false, null: false
t.index ["project_id", "type"], name: "index_services_on_project_id_and_type"
t.index ["template"], name: "index_services_on_template"
t.index ["type", "id", "template"], name: "index_services_on_type_and_id_and_template_when_active", where: "(active = true)"
t.index ["type", "instance"], name: "index_services_on_type_and_instance", unique: true, where: "(instance IS TRUE)"
t.index ["type", "template"], name: "index_services_on_type_and_template", unique: true, where: "(template IS TRUE)"
t.index ["type"], name: "index_services_on_type"
......
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