diff options
author | Stan Hu <stanhu@gmail.com> | 2017-02-04 10:20:39 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-02-04 10:22:32 -0800 |
commit | 1e97a6df24f66f70811fdd4b1412432e40ab8ebe (patch) | |
tree | 94dbb71bf6e0c8c8ec5a2a2adeefd4a5787c7329 /db/migrate | |
parent | 8a333d45059688bfd5245eb91f206bbbcf7d18eb (diff) | |
download | gitlab-ce-1e97a6df24f66f70811fdd4b1412432e40ab8ebe.tar.gz |
Add index to labels for `type` and project_id`sh-add-index-for-label-count
When loading pages that display the number of open issues,
the backend runs a query such as:
```sql
SELECT "labels"."id" FROM "labels" WHERE "labels"."type" IN ('ProjectLabel') AND "labels"."project_id" = 1000
```
This results in an entire scan of the `labels` table. To optimize performance,
add the appropriate index to the table.
Closes #27676
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20170204181513_add_index_to_labels_for_type_and_project.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/db/migrate/20170204181513_add_index_to_labels_for_type_and_project.rb b/db/migrate/20170204181513_add_index_to_labels_for_type_and_project.rb new file mode 100644 index 00000000000..8f944930807 --- /dev/null +++ b/db/migrate/20170204181513_add_index_to_labels_for_type_and_project.rb @@ -0,0 +1,11 @@ +class AddIndexToLabelsForTypeAndProject < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def change + add_concurrent_index :labels, [:type, :project_id] + end +end |