diff options
author | Stan Hu <stanhu@gmail.com> | 2017-02-16 01:21:19 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-02-16 01:25:27 -0800 |
commit | 1df24eaf409d2d760b554c484bd72bf4f32826a8 (patch) | |
tree | 0f8779ed885e52b7dc8e9cffab0534e69253126c | |
parent | 58cc360a45cb03049745668a0134cea1b14b2d9e (diff) | |
download | gitlab-ce-sh-add-ci-build-indexes.tar.gz |
Add index for slow queries in BuildsController#indexsh-add-ci-build-indexes
The worst queries in loading this page looked like this:
```
SELECT COUNT("ci_builds"."id") FROM "ci_builds" WHERE "ci_builds"."type" IN ('Ci::Build') AND "ci_builds"."gl_project_id" = $1 AND ("ci_builds"."status" != $2) [["gl_project_id", 10], ["status", "created"]]
```
This lead to a bitmap heap scan that took 6-7 seconds in production.
Closes #27389
-rw-r--r-- | changelogs/unreleased/sh-add-ci-build-indexes.yml | 4 | ||||
-rw-r--r-- | db/migrate/20170216091009_add_index_to_ci_builds_for_project_status_and_type.rb | 11 | ||||
-rw-r--r-- | db/schema.rb | 3 |
3 files changed, 17 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-add-ci-build-indexes.yml b/changelogs/unreleased/sh-add-ci-build-indexes.yml new file mode 100644 index 00000000000..d498c978f4d --- /dev/null +++ b/changelogs/unreleased/sh-add-ci-build-indexes.yml @@ -0,0 +1,4 @@ +--- +title: Add index for slow queries in BuildsController#index +merge_request: +author: diff --git a/db/migrate/20170216091009_add_index_to_ci_builds_for_project_status_and_type.rb b/db/migrate/20170216091009_add_index_to_ci_builds_for_project_status_and_type.rb new file mode 100644 index 00000000000..1a074b596a9 --- /dev/null +++ b/db/migrate/20170216091009_add_index_to_ci_builds_for_project_status_and_type.rb @@ -0,0 +1,11 @@ +class AddIndexToCiBuildsForProjectStatusAndType < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def change + add_concurrent_index :ci_builds, [:project_id, :status, :type] + end +end diff --git a/db/schema.rb b/db/schema.rb index 52672406ec6..604cfe2f90f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170214111112) do +ActiveRecord::Schema.define(version: 20170216091009) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -225,6 +225,7 @@ ActiveRecord::Schema.define(version: 20170214111112) do add_index "ci_builds", ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree add_index "ci_builds", ["commit_id", "type", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_ref", using: :btree add_index "ci_builds", ["gl_project_id"], name: "index_ci_builds_on_gl_project_id", using: :btree + add_index "ci_builds", ["project_id", "status", "type"], name: "index_ci_builds_on_project_id_and_status_and_type", using: :btree add_index "ci_builds", ["project_id"], name: "index_ci_builds_on_project_id", using: :btree add_index "ci_builds", ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree add_index "ci_builds", ["status", "type", "runner_id"], name: "index_ci_builds_on_status_and_type_and_runner_id", using: :btree |