Add index on namespaces lower(name) for UsersController#exists
This commit is contained in:
parent
82e31ee467
commit
680ebf449b
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add index on namespaces lower(name) for UsersController#exists
|
||||
merge_request:
|
||||
author:
|
||||
type: performance
|
|
@ -0,0 +1,30 @@
|
|||
class AddIndexOnNamespacesLowerName < ActiveRecord::Migration
|
||||
include Gitlab::Database::MigrationHelpers
|
||||
DOWNTIME = false
|
||||
INDEX_NAME = 'index_on_namespaces_lower_name'
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
return unless Gitlab::Database.postgresql?
|
||||
|
||||
disable_statement_timeout
|
||||
if Gitlab::Database.version.to_f >= 9.5
|
||||
# Allow us to hot-patch the index manually ahead of the migration
|
||||
execute "CREATE INDEX CONCURRENTLY IF NOT EXISTS #{INDEX_NAME} ON namespaces (lower(name));"
|
||||
else
|
||||
execute "CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON namespaces (lower(name));"
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
return unless Gitlab::Database.postgresql?
|
||||
|
||||
disable_statement_timeout
|
||||
if Gitlab::Database.version.to_f >= 9.2
|
||||
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME};"
|
||||
else
|
||||
execute "DROP INDEX IF EXISTS #{INDEX_NAME};"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20171219121201) do
|
||||
ActiveRecord::Schema.define(version: 20171220191323) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
|
@ -6,6 +6,7 @@ require Rails.root.join('db/migrate/20161212142807_add_lower_path_index_to_route
|
|||
require Rails.root.join('db/migrate/20170317203554_index_routes_path_for_like')
|
||||
require Rails.root.join('db/migrate/20170724214302_add_lower_path_index_to_redirect_routes')
|
||||
require Rails.root.join('db/migrate/20170503185032_index_redirect_routes_path_for_like')
|
||||
require Rails.root.join('db/migrate/20171220191323_add_index_on_namespaces_lower_name.rb')
|
||||
|
||||
desc 'GitLab | Sets up PostgreSQL'
|
||||
task setup_postgresql: :environment do
|
||||
|
@ -15,4 +16,5 @@ task setup_postgresql: :environment do
|
|||
IndexRoutesPathForLike.new.up
|
||||
AddLowerPathIndexToRedirectRoutes.new.up
|
||||
IndexRedirectRoutesPathForLike.new.up
|
||||
AddIndexOnNamespacesLowerName.new.up
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue