Commit 55f87dd8 authored by Andreas Brandl's avatar Andreas Brandl

Add missing expression indexes

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/280826
parent fd087488
---
title: Add missing expression indexes
merge_request: 47424
author:
type: performance
# frozen_string_literal: true
class AddMissingExpressionIndexes < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEXES = [
[:namespaces, :index_on_namespaces_lower_name, 'LOWER(name)'],
[:namespaces, :index_on_namespaces_lower_path, 'LOWER(path)'],
[:projects, :index_on_projects_lower_path, 'LOWER(path)'],
[:routes, :index_on_routes_lower_path, 'LOWER(path)'],
[:users, :index_on_users_lower_username, 'LOWER(username)'],
[:users, :index_on_users_lower_email, 'LOWER(email)']
]
def up
# Those indexes had been introduced before, but they haven't been
# captured in structure.sql. For installations that already have it,
# this is a no-op - others will get it retroactively with
# this migration.
tables = Set.new
INDEXES.each do |(table, name, expression)|
unless index_name_exists?(table, name)
add_concurrent_index table, expression, name: name
tables.add(table)
end
end
# Rebuild statistics on affected tables only
tables.each do |table|
execute("ANALYZE #{table}")
end
end
def down
# no-op
end
end
4c5baa6a09a339fac544f830d5ef822b1e7e4eae8431bd91df5113125accbc77
\ No newline at end of file
...@@ -21326,12 +21326,24 @@ CREATE UNIQUE INDEX index_on_instance_statistics_recorded_at_and_identifier ON a ...@@ -21326,12 +21326,24 @@ CREATE UNIQUE INDEX index_on_instance_statistics_recorded_at_and_identifier ON a
CREATE INDEX index_on_label_links_all_columns ON label_links USING btree (target_id, label_id, target_type); CREATE INDEX index_on_label_links_all_columns ON label_links USING btree (target_id, label_id, target_type);
CREATE INDEX index_on_namespaces_lower_name ON namespaces USING btree (lower((name)::text));
CREATE INDEX index_on_namespaces_lower_path ON namespaces USING btree (lower((path)::text));
CREATE INDEX index_on_projects_lower_path ON projects USING btree (lower((path)::text));
CREATE INDEX index_on_routes_lower_path ON routes USING btree (lower((path)::text));
CREATE UNIQUE INDEX index_on_segment_selections_group_id_segment_id ON analytics_devops_adoption_segment_selections USING btree (group_id, segment_id); CREATE UNIQUE INDEX index_on_segment_selections_group_id_segment_id ON analytics_devops_adoption_segment_selections USING btree (group_id, segment_id);
CREATE UNIQUE INDEX index_on_segment_selections_project_id_segment_id ON analytics_devops_adoption_segment_selections USING btree (project_id, segment_id); CREATE UNIQUE INDEX index_on_segment_selections_project_id_segment_id ON analytics_devops_adoption_segment_selections USING btree (project_id, segment_id);
CREATE INDEX index_on_segment_selections_segment_id ON analytics_devops_adoption_segment_selections USING btree (segment_id); CREATE INDEX index_on_segment_selections_segment_id ON analytics_devops_adoption_segment_selections USING btree (segment_id);
CREATE INDEX index_on_users_lower_email ON users USING btree (lower((email)::text));
CREATE INDEX index_on_users_lower_username ON users USING btree (lower((username)::text));
CREATE INDEX index_on_users_name_lower ON users USING btree (lower((name)::text)); CREATE INDEX index_on_users_name_lower ON users USING btree (lower((name)::text));
CREATE INDEX index_open_project_tracker_data_on_service_id ON open_project_tracker_data USING btree (service_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