Add index to email field on users table if does not already exist
What does this MR do?
This MR tries to bring structure.sql
to be closer to what we actually have on production DB, i.e. on production we actually have both indexes: index_users_on_email ON users USING btree (email)
and index_users_on_lower_email ON users USING btree (lower((email)::text))
but the later one is not reflected in strcuture.sql
for reference:
FYI: I just noticed the indexes
index_on_users_lower_username
andindex_on_users_lower_email
exist on production, but not indb/structure.sql
. Onlyindex_on_users_name_lower
does. We should write a migration to add it if it does not exist.
Output
== 20201104111152 AddIndexOnUsersTableLoweredEmail: migrating =================
-- transaction_open?()
-> 0.0000s
-- index_exists?(:users, "LOWER(email)", {:unique=>true, :name=>"index_users_on_lower_email", :algorithm=>:concurrently})
-> 0.0135s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:users, "LOWER(email)", {:unique=>true, :name=>"index_users_on_lower_email", :algorithm=>:concurrently})
-> 0.0132s
-- execute("RESET ALL")
-> 0.0003s
== 20201104111152 AddIndexOnUsersTableLoweredEmail: migrated (0.0278s) ========
== 20201104111152 AddIndexOnUsersTableLoweredEmail: reverting =================
-- transaction_open?()
-> 0.0000s
-- indexes(:users)
-> 0.0114s
-- execute("SET statement_timeout TO 0")
-> 0.0003s
-- remove_index(:users, {:algorithm=>:concurrently, :name=>"index_users_on_lower_email"})
-> 0.0057s
-- execute("RESET ALL")
-> 0.0002s
== 20201104111152 AddIndexOnUsersTableLoweredEmail: reverted (0.0182s) ========
Duration
- ~2 mins on #databse-lab:
exec CREATE UNIQUE INDEX CONCURRENTLY index_users_on_lower_email ON users USING btree (lower((email)::text));
Session: joe-buht62o350j13v0696og
The query has been executed. Duration: 1.706 min (edited)
Index Details
\di+ index_users_on_lower_email
Session: joe-buht62o350j13v0696og
Command output:
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+----------------------------+-------+--------+-------+--------+-------------
public | index_users_on_lower_email | index | gitlab | users | 303 MB |
(1 row)
re #214466 (closed) !33883 (comment 441509284)
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team