summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-09-04 19:33:18 +0200
committerAndreas Brandl <abrandl@gitlab.com>2019-09-05 09:28:05 +0200
commit8b8fbcd67f23227ce02de8f0f66a10cdc5349999 (patch)
tree892ef8b11ebda74b87454c124a9faa6845484406
parente7f23d683a963cebd51c82e5452570cbd4b86e04 (diff)
downloadgitlab-ce-12-3-auto-deploy-20190901-32664.tar.gz
Create index for users.unconfirmed_email12-3-auto-deploy-20190901-32664
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.
-rw-r--r--changelogs/unreleased/ab-unconfirmed-email-index.yml5
-rw-r--r--db/migrate/20190904173203_add_index_on_users_unconfirmed_email.rb17
-rw-r--r--db/schema.rb3
3 files changed, 24 insertions, 1 deletions
diff --git a/changelogs/unreleased/ab-unconfirmed-email-index.yml b/changelogs/unreleased/ab-unconfirmed-email-index.yml
new file mode 100644
index 00000000000..3887cd87e41
--- /dev/null
+++ b/changelogs/unreleased/ab-unconfirmed-email-index.yml
@@ -0,0 +1,5 @@
+---
+title: Create index for users.unconfirmed_email
+merge_request: 32664
+author:
+type: performance
diff --git a/db/migrate/20190904173203_add_index_on_users_unconfirmed_email.rb b/db/migrate/20190904173203_add_index_on_users_unconfirmed_email.rb
new file mode 100644
index 00000000000..e78d47f023f
--- /dev/null
+++ b/db/migrate/20190904173203_add_index_on_users_unconfirmed_email.rb
@@ -0,0 +1,17 @@
+# 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
diff --git a/db/schema.rb b/db/schema.rb
index 5b89cdf0b98..12aeebf79cb 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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_131045) 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"
@@ -3553,6 +3553,7 @@ ActiveRecord::Schema.define(version: 2019_09_02_131045) 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