Commit 42d94806 authored by alinamihaila's avatar alinamihaila

Optimize members query performance in usage data

Add index on user_id, type, source_type,ldap, created_at on members
parent 28f33dcf
---
title: Optimize members counters query performance in usage data
merge_request: 27197
author:
type: performance
# frozen_string_literal: true
class AddIndexOnUserIdTypeSourceTypeLdapAndCreatedAtToMembers < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_members_on_user_id_type_source_type_ldap_and_created_at'
disable_ddl_transaction!
def up
add_concurrent_index :members, [:user_id, :type, :source_type, :ldap, :created_at], where: "ldap = TRUE AND type = 'GroupMember' AND source_type = 'Namespace'", name: INDEX_NAME
end
def down
remove_concurrent_index :members, INDEX_NAME
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_03_12_163407) do
ActiveRecord::Schema.define(version: 2020_03_13_123934) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
......@@ -2442,6 +2442,7 @@ ActiveRecord::Schema.define(version: 2020_03_12_163407) do
t.index ["invite_token"], name: "index_members_on_invite_token", unique: true
t.index ["requested_at"], name: "index_members_on_requested_at"
t.index ["source_id", "source_type"], name: "index_members_on_source_id_and_source_type"
t.index ["user_id", "type", "source_type", "ldap", "created_at"], name: "index_members_on_user_id_type_source_type_ldap_and_created_at", where: "((ldap = true) AND ((type)::text = 'GroupMember'::text) AND ((source_type)::text = 'Namespace'::text))"
t.index ["user_id"], name: "index_members_on_user_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