Commit 449d67ac authored by Alex Buijs's avatar Alex Buijs

Add indexes to onboarding_progresses table

For optimizing the groups_for_track queries
parent db796737
---
title: Add indexes for onboarding progress table
merge_request: 50679
author:
type: performance
# frozen_string_literal: true
class AddIndexesToOnboardingProgresses < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CREATE_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_create_track'
VERIFY_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_verify_track'
TRIAL_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_trial_track'
TEAM_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_team_track'
disable_ddl_transaction!
def up
add_concurrent_index :onboarding_progresses, :created_at, where: 'git_write_at IS NULL', name: CREATE_TRACK_INDEX_NAME
add_concurrent_index :onboarding_progresses, :git_write_at, where: 'git_write_at IS NOT NULL AND pipeline_created_at IS NULL', name: VERIFY_TRACK_INDEX_NAME
add_concurrent_index :onboarding_progresses, 'GREATEST(git_write_at, pipeline_created_at)', where: 'git_write_at IS NOT NULL AND pipeline_created_at IS NOT NULL AND trial_started_at IS NULL', name: TRIAL_TRACK_INDEX_NAME
add_concurrent_index :onboarding_progresses, 'GREATEST(git_write_at, pipeline_created_at, trial_started_at)', where: 'git_write_at IS NOT NULL AND pipeline_created_at IS NOT NULL AND trial_started_at IS NOT NULL AND user_added_at IS NULL', name: TEAM_TRACK_INDEX_NAME
end
def down
remove_concurrent_index_by_name :onboarding_progresses, CREATE_TRACK_INDEX_NAME
remove_concurrent_index_by_name :onboarding_progresses, VERIFY_TRACK_INDEX_NAME
remove_concurrent_index_by_name :onboarding_progresses, TRIAL_TRACK_INDEX_NAME
remove_concurrent_index_by_name :onboarding_progresses, TEAM_TRACK_INDEX_NAME
end
end
7ef5cb1f167c133c67fc98c0abe929516ec700179747d3353d19cf8219ebd0ef
\ No newline at end of file
......@@ -22511,6 +22511,14 @@ CREATE INDEX index_on_users_lower_username ON users USING btree (lower((username
CREATE INDEX index_on_users_name_lower ON users USING btree (lower((name)::text));
CREATE INDEX index_onboarding_progresses_for_create_track ON onboarding_progresses USING btree (created_at) WHERE (git_write_at IS NULL);
CREATE INDEX index_onboarding_progresses_for_team_track ON onboarding_progresses USING btree (GREATEST(git_write_at, pipeline_created_at, trial_started_at)) WHERE ((git_write_at IS NOT NULL) AND (pipeline_created_at IS NOT NULL) AND (trial_started_at IS NOT NULL) AND (user_added_at IS NULL));
CREATE INDEX index_onboarding_progresses_for_trial_track ON onboarding_progresses USING btree (GREATEST(git_write_at, pipeline_created_at)) WHERE ((git_write_at IS NOT NULL) AND (pipeline_created_at IS NOT NULL) AND (trial_started_at IS NULL));
CREATE INDEX index_onboarding_progresses_for_verify_track ON onboarding_progresses USING btree (git_write_at) WHERE ((git_write_at IS NOT NULL) AND (pipeline_created_at IS NULL));
CREATE UNIQUE INDEX index_onboarding_progresses_on_namespace_id ON onboarding_progresses USING btree (namespace_id);
CREATE INDEX index_open_project_tracker_data_on_service_id ON open_project_tracker_data 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