Commit 7a890ae9 authored by Andreas Brandl's avatar Andreas Brandl

Create index for users.unconfirmed_email

This speeds up the following query:

```sql
SELECT  users.* FROM users WHERE users.unconfirmed_email = ? ORDER BY
users.id ASC LIMIT 1
```

Presumably, this is a query coming from Devise.

Context is https://gitlab.com/gitlab-org/gitlab-ce/issues/66958.
parent 21924175
---
title: Create index for users.unconfirmed_email
merge_request: 32664
author:
type: performance
# frozen_string_literal: true
class AddIndexOnUsersUnconfirmedEmail < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :users, :unconfirmed_email, where: 'unconfirmed_email IS NOT NULL'
end
def down
remove_concurrent_index :users, :unconfirmed_email, where: 'unconfirmed_email IS NOT NULL'
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_09_02_160015) do
ActiveRecord::Schema.define(version: 2019_09_04_173203) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
......@@ -3562,6 +3562,7 @@ ActiveRecord::Schema.define(version: 2019_09_02_160015) do
t.index ["state"], name: "index_users_on_state"
t.index ["state"], name: "index_users_on_state_and_internal", where: "(ghost IS NOT TRUE)"
t.index ["state"], name: "index_users_on_state_and_internal_ee", where: "((ghost IS NOT TRUE) AND (bot_type IS NULL))"
t.index ["unconfirmed_email"], name: "index_users_on_unconfirmed_email", where: "(unconfirmed_email IS NOT NULL)"
t.index ["username"], name: "index_users_on_username"
t.index ["username"], name: "index_users_on_username_trigram", opclass: :gin_trgm_ops, using: :gin
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