Add partial index on identities table to speed up LDAP lookups

For customers with thousands of entries in the table, lookups for an
LDAP identity dominated the PostgreSQL statistics because of sequential
scans. We can speed this up by adding a partial index with the
extern_uid and provider.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59630
This commit is contained in:
Stan Hu 2019-07-23 14:54:04 -07:00
parent 11f82c891a
commit 5bb2f0c6fc
3 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
title: Add partial index on identities table to speed up LDAP lookups
merge_request: 26710
author:
type: performance

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class AddIndexOnIdentitiesLowerExternUidAndProvider < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX_NAME = "index_on_identities_lower_extern_uid_and_provider"
def up
add_concurrent_index(:identities, 'lower(extern_uid), provider', name: INDEX_NAME)
end
def down
remove_concurrent_index_by_name(:identities, INDEX_NAME)
end
end

View file

@ -1580,6 +1580,7 @@ ActiveRecord::Schema.define(version: 2019_07_29_090456) do
t.datetime "updated_at"
t.integer "saml_provider_id"
t.string "secondary_extern_uid"
t.index "lower((extern_uid)::text), provider", name: "index_on_identities_lower_extern_uid_and_provider"
t.index ["saml_provider_id"], name: "index_identities_on_saml_provider_id", where: "(saml_provider_id IS NOT NULL)"
t.index ["user_id"], name: "index_identities_on_user_id"
end