mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Optimize searching for users on Postgres (#9782)
The searches on Postgres using LIKE with prefix matching will only use an index if it has the text_pattern_ops flag (forcing C collation). This drops the old indexes and adds properly optimized ones.
This commit is contained in:
committed by
Jesse Hallam
parent
0c5f60f89b
commit
7a758eae72
@@ -521,6 +521,14 @@ func UpgradeDatabaseToVersion56(sqlStore SqlStore) {
|
||||
|
||||
// migrating user's accepted terms of service data into the new table
|
||||
sqlStore.GetMaster().Exec("INSERT INTO UserTermsOfService SELECT Id, AcceptedTermsOfServiceId as TermsOfServiceId, :CreateAt FROM Users WHERE AcceptedTermsOfServiceId != \"\" AND AcceptedTermsOfServiceId IS NOT NULL", map[string]interface{}{"CreateAt": model.GetMillis()})
|
||||
|
||||
if sqlStore.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
sqlStore.RemoveIndexIfExists("idx_users_email_lower", "lower(Email)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_username_lower", "lower(Username)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_nickname_lower", "lower(Nickname)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_firstname_lower", "lower(FirstName)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_lastname_lower", "lower(LastName)")
|
||||
}
|
||||
//saveSchemaVersion(sqlStore, VERSION_5_6_0)
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -94,11 +94,11 @@ func (us SqlUserStore) CreateIndexesIfNotExists() {
|
||||
us.CreateIndexIfNotExists("idx_users_delete_at", "Users", "DeleteAt")
|
||||
|
||||
if us.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
us.CreateIndexIfNotExists("idx_users_email_lower", "Users", "lower(Email)")
|
||||
us.CreateIndexIfNotExists("idx_users_username_lower", "Users", "lower(Username)")
|
||||
us.CreateIndexIfNotExists("idx_users_nickname_lower", "Users", "lower(Nickname)")
|
||||
us.CreateIndexIfNotExists("idx_users_firstname_lower", "Users", "lower(FirstName)")
|
||||
us.CreateIndexIfNotExists("idx_users_lastname_lower", "Users", "lower(LastName)")
|
||||
us.CreateIndexIfNotExists("idx_users_email_lower_textpattern", "Users", "lower(Email) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_username_lower_textpattern", "Users", "lower(Username) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_nickname_lower_textpattern", "Users", "lower(Nickname) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_firstname_lower_textpattern", "Users", "lower(FirstName) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_lastname_lower_textpattern", "Users", "lower(LastName) text_pattern_ops")
|
||||
}
|
||||
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_txt", "Users", strings.Join(USER_SEARCH_TYPE_ALL, ", "))
|
||||
|
||||
Reference in New Issue
Block a user