Commit 0074a8b0 authored by Arturo Herrero's avatar Arturo Herrero

Replace index for service usage data

There is an index index_services_on_type_and_id_and_template_when_active
introduced in 3a44d110 to optimize the queries performance for the
services usage data.

The usage data counter is iterating over the index in 10K batches,
without covering all the fields (type, id, template, instance), the
database would need to constantly look at the table for the instance
column (extra I/O).
parent 748d9544
---
title: Replace index for service usage data
merge_request: 38147
author:
type: performance
# frozen_string_literal: true
class ReplaceIndexForServiceUsageData < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
OLD_INDEX_NAME = 'index_services_on_type_and_id_and_template_when_active'
NEW_INDEX_NAME = 'index_services_on_type_id_when_active_not_instance_not_template'
disable_ddl_transaction!
def up
add_concurrent_index :services, [:type, :id], where: 'active = TRUE AND instance = FALSE AND template = FALSE', name: NEW_INDEX_NAME
remove_concurrent_index_by_name :services, OLD_INDEX_NAME
end
def down
add_concurrent_index :services, [:type, :id, :template], where: 'active = TRUE', name: OLD_INDEX_NAME
remove_concurrent_index :services, NEW_INDEX_NAME
end
end
5bda9ae726077c1ea0df2158138f85ca43bfbf5b1a8cf3516bcdf012eac5c0b8
\ No newline at end of file
...@@ -20523,12 +20523,12 @@ CREATE INDEX index_services_on_template ON public.services USING btree (template ...@@ -20523,12 +20523,12 @@ CREATE INDEX index_services_on_template ON public.services USING btree (template
CREATE INDEX index_services_on_type ON public.services USING btree (type); CREATE INDEX index_services_on_type ON public.services USING btree (type);
CREATE INDEX index_services_on_type_and_id_and_template_when_active ON public.services USING btree (type, id, template) WHERE (active = true);
CREATE UNIQUE INDEX index_services_on_type_and_instance_partial ON public.services USING btree (type, instance) WHERE (instance = true); CREATE UNIQUE INDEX index_services_on_type_and_instance_partial ON public.services USING btree (type, instance) WHERE (instance = true);
CREATE UNIQUE INDEX index_services_on_type_and_template_partial ON public.services USING btree (type, template) WHERE (template = true); CREATE UNIQUE INDEX index_services_on_type_and_template_partial ON public.services USING btree (type, template) WHERE (template = true);
CREATE INDEX index_services_on_type_id_when_active_not_instance_not_template ON public.services USING btree (type, id) WHERE ((active = true) AND (instance = false) AND (template = false));
CREATE UNIQUE INDEX index_shards_on_name ON public.shards USING btree (name); CREATE UNIQUE INDEX index_shards_on_name ON public.shards USING btree (name);
CREATE INDEX index_slack_integrations_on_service_id ON public.slack_integrations USING btree (service_id); CREATE INDEX index_slack_integrations_on_service_id ON public.slack_integrations USING btree (service_id);
......
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