summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-03-06 18:02:28 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2018-03-21 13:39:49 +0100
commit272a5a07b3a07a49714775a0f1bca2f0ef440451 (patch)
tree43db647cf7fd8eec1cbb0fbb448218405c174a1f
parentce6edaf03082e4c11bf148f2eb47bb0bf31ce6d8 (diff)
downloadgitlab-ce-272a5a07b3a07a49714775a0f1bca2f0ef440451.tar.gz
Add index on lower path to redirect routes
This will speed up the LIKE query in RedirectRoute.matching_path_and_descendants
-rw-r--r--db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb b/db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb
new file mode 100644
index 00000000000..f8cac2f2b5e
--- /dev/null
+++ b/db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb
@@ -0,0 +1,34 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddPathIndexToRedirectRoutes < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_redirect_routes_on_path_unique_text_pattern_ops'
+
+ # Indexing on LOWER(path) varchar_pattern_ops speeds up the LIKE query in
+ # RedirectRoute.matching_path_and_descendants
+ #
+ def up
+ return unless Gitlab::Database.postgresql?
+
+ disable_statement_timeout
+
+ if_not_exists = Gitlab::Database.version.to_f >= 9.5 ? "IF NOT EXISTS" : ""
+
+ # Unique index on lower(path) across both types of redirect_routes:
+ execute("CREATE UNIQUE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME} ON redirect_routes (lower(path) varchar_pattern_ops);")
+ end
+
+ def down
+ return unless Gitlab::Database.postgresql?
+
+ disable_statement_timeout
+
+ execute("DROP INDEX IF EXISTS #{INDEX_NAME};")
+ end
+end