Commit 7b3f6d4e authored by Alper Akgun's avatar Alper Akgun

Optimize ci builds AMAU queries

Adds an index to ensure computation for the queries
parent d8729627
---
title: Optimize ci builds counters in usage data
merge_request: 27770
author:
type: performance
# frozen_string_literal: true
class AddIndexOnUserAndCreatedAtToCiBuilds < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX_NAME = 'index_ci_builds_on_user_id_and_created_at_and_type_eq_ci_build'
def up
add_concurrent_index :ci_builds, [:user_id, :created_at], where: "type = 'Ci::Build'", name: INDEX_NAME
end
def down
remove_concurrent_index :ci_builds, INDEX_NAME
end
end
......@@ -8603,6 +8603,8 @@ CREATE INDEX index_ci_builds_on_upstream_pipeline_id ON public.ci_builds USING b
CREATE INDEX index_ci_builds_on_user_id ON public.ci_builds USING btree (user_id);
CREATE INDEX index_ci_builds_on_user_id_and_created_at_and_type_eq_ci_build ON public.ci_builds USING btree (user_id, created_at) WHERE ((type)::text = 'Ci::Build'::text);
CREATE INDEX index_ci_builds_project_id_and_status_for_live_jobs_partial2 ON public.ci_builds USING btree (project_id, status) WHERE (((type)::text = 'Ci::Build'::text) AND ((status)::text = ANY (ARRAY[('running'::character varying)::text, ('pending'::character varying)::text, ('created'::character varying)::text])));
CREATE UNIQUE INDEX index_ci_builds_runner_session_on_build_id ON public.ci_builds_runner_session USING btree (build_id);
......@@ -12746,5 +12748,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200318165448'),
('20200318175008'),
('20200319203901'),
('20200323075043');
('20200323075043'),
('20200323122201');
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