Add index to labels for type
and project_id`
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
This commit is contained in:
parent
8a333d4505
commit
1e97a6df24
2 changed files with 13 additions and 1 deletions
|
@ -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
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170130204620) do
|
||||
ActiveRecord::Schema.define(version: 20170204181513) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -576,6 +576,7 @@ ActiveRecord::Schema.define(version: 20170130204620) do
|
|||
end
|
||||
|
||||
add_index "labels", ["group_id", "project_id", "title"], name: "index_labels_on_group_id_and_project_id_and_title", unique: true, using: :btree
|
||||
add_index "labels", ["type", "project_id"], name: "index_labels_on_type_and_project_id", using: :btree
|
||||
|
||||
create_table "lfs_objects", force: :cascade do |t|
|
||||
t.string "oid", null: false
|
||||
|
|
Loading…
Reference in a new issue