diff options
author | Sean McGivern <sean@gitlab.com> | 2017-11-24 13:11:37 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-11-28 19:13:57 +0300 |
commit | 484ae2ee2db58a641d3c3fff36f46b431ce450df (patch) | |
tree | c5124b9b841b0d0a649a1d6bc1c82d2bc9d200db /db | |
parent | 4ebbfe5d3e0dbe06346ee0c64a8f62ec11f9b6e8 (diff) |
Improve indexes on merge_request_diffs
For getting the SHAs from an MR to find pipelines, we get the last 100 MR diffs
for the MR, and find commits from those. This was un-indexed before, because the
index was not a composite index on merge_request_diff_id, id. Changing that
means that this scope can exclusively use indexes.
Diffstat (limited to 'db')
3 files changed, 35 insertions, 1 deletions
diff --git a/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb b/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb new file mode 100644 index 00000000000..698df712c11 --- /dev/null +++ b/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb @@ -0,0 +1,17 @@ +class AddIndexOnMergeRequestDiffsMergeRequestIdAndId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index(:merge_request_diffs, [:merge_request_id, :id]) + end + + def down + if index_exists?(:merge_request_diffs, [:merge_request_id, :id]) + remove_concurrent_index(:merge_request_diffs, [:merge_request_id, :id]) + end + end +end diff --git a/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb b/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb new file mode 100644 index 00000000000..038e4807000 --- /dev/null +++ b/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb @@ -0,0 +1,17 @@ +class RemoveIndexOnMergeRequestDiffsMergeRequestDiffId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + if index_exists?(:merge_request_diffs, :merge_request_id) + remove_concurrent_index(:merge_request_diffs, :merge_request_id) + end + end + + def down + add_concurrent_index(:merge_request_diffs, :merge_request_id) + end +end diff --git a/db/schema.rb b/db/schema.rb index 292163ee9bf..339c98d7798 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1020,7 +1020,7 @@ ActiveRecord::Schema.define(version: 20171124132536) do t.string "start_commit_sha" end - add_index "merge_request_diffs", ["merge_request_id"], name: "index_merge_request_diffs_on_merge_request_id", using: :btree + add_index "merge_request_diffs", ["merge_request_id", "id"], name: "index_merge_request_diffs_on_merge_request_id_and_id", using: :btree create_table "merge_request_metrics", force: :cascade do |t| t.integer "merge_request_id", null: false |