Commit b7876cf8 authored by Andreas Brandl's avatar Andreas Brandl

Remove unneeded indexes on projects table

Related issue: https://gitlab.com/gitlab-org/gitlab/issues/195881

This removes indexes that we don't need anymore after changing the "tie
breaker" sorting direction. The indexes have been introduced with
https://gitlab.com/gitlab-org/gitlab/merge_requests/22623 to optimally
support the requests. This is not needed anymore since the tie breaker
now also changes its sorting direction.

For more details please refer to
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/22623.

I've validated that these indexes are not being used on GitLab.com
anymore:
https://gitlab.com/gitlab-org/gitlab/issues/195881#note_278816057
parent e01f24f8
---
title: Remove unneeded indexes on projects table
merge_request: 24086
author:
type: performance
# frozen_string_literal: true
class DropUnneededIndexesForProjectsApiRequests < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
indexes = %w(
index_projects_api_vis20_created_at_id_desc
index_projects_api_vis20_last_activity_at_id_desc
index_projects_api_vis20_updated_at_id_desc
index_projects_api_vis20_name_id_desc
index_projects_api_vis20_path_id_desc
)
indexes.each do |index|
remove_concurrent_index_by_name :projects, index
end
end
def down
columns = %i(created_at last_activity_at updated_at name path)
columns.each do |column|
add_concurrent_index :projects, [column, :id], where: 'visibility_level = 20', order: { id: :desc }, name: "index_projects_api_vis20_#{column}_id_desc"
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_01_29_035708) do
ActiveRecord::Schema.define(version: 2020_01_30_161817) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
......@@ -3382,7 +3382,6 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do
t.index "lower((name)::text)", name: "index_projects_on_lower_name"
t.index ["created_at", "id"], name: "index_projects_api_created_at_id_desc", order: { id: :desc }
t.index ["created_at", "id"], name: "index_projects_api_vis20_created_at", where: "(visibility_level = 20)"
t.index ["created_at", "id"], name: "index_projects_api_vis20_created_at_id_desc", order: { id: :desc }, where: "(visibility_level = 20)"
t.index ["created_at", "id"], name: "index_projects_on_created_at_and_id"
t.index ["creator_id"], name: "index_projects_on_creator_id"
t.index ["description"], name: "index_projects_on_description_trigram", opclass: :gin_trgm_ops, using: :gin
......@@ -3392,7 +3391,6 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do
t.index ["id"], name: "index_projects_on_mirror_and_mirror_trigger_builds_both_true", where: "((mirror IS TRUE) AND (mirror_trigger_builds IS TRUE))"
t.index ["last_activity_at", "id"], name: "index_projects_api_last_activity_at_id_desc", order: { id: :desc }
t.index ["last_activity_at", "id"], name: "index_projects_api_vis20_last_activity_at", where: "(visibility_level = 20)"
t.index ["last_activity_at", "id"], name: "index_projects_api_vis20_last_activity_at_id_desc", order: { id: :desc }, where: "(visibility_level = 20)"
t.index ["last_activity_at", "id"], name: "index_projects_on_last_activity_at_and_id"
t.index ["last_repository_check_at"], name: "index_projects_on_last_repository_check_at", where: "(last_repository_check_at IS NOT NULL)"
t.index ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed"
......@@ -3403,13 +3401,11 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do
t.index ["mirror_user_id"], name: "index_projects_on_mirror_user_id"
t.index ["name", "id"], name: "index_projects_api_name_id_desc", order: { id: :desc }
t.index ["name", "id"], name: "index_projects_api_vis20_name", where: "(visibility_level = 20)"
t.index ["name", "id"], name: "index_projects_api_vis20_name_id_desc", order: { id: :desc }, where: "(visibility_level = 20)"
t.index ["name", "id"], name: "index_projects_on_name_and_id"
t.index ["name"], name: "index_projects_on_name_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["namespace_id"], name: "index_projects_on_namespace_id"
t.index ["path", "id"], name: "index_projects_api_path_id_desc", order: { id: :desc }
t.index ["path", "id"], name: "index_projects_api_vis20_path", where: "(visibility_level = 20)"
t.index ["path", "id"], name: "index_projects_api_vis20_path_id_desc", order: { id: :desc }, where: "(visibility_level = 20)"
t.index ["path", "id"], name: "index_projects_on_path_and_id"
t.index ["path"], name: "index_projects_on_path_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["pending_delete"], name: "index_projects_on_pending_delete"
......@@ -3421,7 +3417,6 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do
t.index ["star_count"], name: "index_projects_on_star_count"
t.index ["updated_at", "id"], name: "index_projects_api_updated_at_id_desc", order: { id: :desc }
t.index ["updated_at", "id"], name: "index_projects_api_vis20_updated_at", where: "(visibility_level = 20)"
t.index ["updated_at", "id"], name: "index_projects_api_vis20_updated_at_id_desc", order: { id: :desc }, where: "(visibility_level = 20)"
t.index ["updated_at", "id"], name: "index_projects_on_updated_at_and_id"
end
......
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