Commit fff098e4 authored by Stan Hu's avatar Stan Hu

Add project ID index to `project_authorizations` table to optimize queries

As described in #27443, the `project_authorizations` table is often used to retrieve
all team members of this project. This can lead to a number of slow queries impacting
load times. This MR adds an index for just `project_id`.

Closes #27443
parent 3995baad
---
title: Add project ID index to `project_authorizations` table to optimize queries
merge_request:
author:
class AddIndexToProjectAuthorizations < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index(:project_authorizations, :project_id)
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170121130655) do ActiveRecord::Schema.define(version: 20170130204620) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -874,6 +874,7 @@ ActiveRecord::Schema.define(version: 20170121130655) do ...@@ -874,6 +874,7 @@ ActiveRecord::Schema.define(version: 20170121130655) do
t.integer "access_level" t.integer "access_level"
end end
add_index "project_authorizations", ["project_id"], name: "index_project_authorizations_on_project_id", using: :btree
add_index "project_authorizations", ["user_id", "project_id", "access_level"], name: "index_project_authorizations_on_user_id_project_id_access_level", unique: true, using: :btree add_index "project_authorizations", ["user_id", "project_id", "access_level"], name: "index_project_authorizations_on_user_id_project_id_access_level", unique: true, using: :btree
create_table "project_features", force: :cascade do |t| create_table "project_features", force: :cascade do |t|
......
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