Commit 3a44d110 authored by Alex Buijs's avatar Alex Buijs

Optimize projects_service_active queries

by adding an index and converting the
grouping to individual batch queries
parent ed9dd7ca
---
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
......@@ -3964,6 +3964,7 @@ ActiveRecord::Schema.define(version: 2020_03_12_163407) 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