Commit f2342c48 authored by Andreas Brandl's avatar Andreas Brandl

Add index for projects API default param

This if the default query for the unauthenticated user:

```sql
SELECT
    "projects".*
FROM
    "projects"
WHERE
    "projects"."visibility_level" = 20
    AND "projects"."pending_delete" = FALSE
ORDER BY
    "projects"."created_at" DESC,
    "projects"."id" DESC
LIMIT 20 OFFSET 0
```

We also remove the existing, now redundant index.

Relates to https://gitlab.com/gitlab-org/gitlab/issues/36135
parent a658e852
---
title: Add index for unauthenticated requests to projects API default endpoint
merge_request: 19989
author:
type: performance
# frozen_string_literal: true
class AddIndexesForProjectsApiDefaultParams < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :projects, %i(visibility_level created_at id)
remove_concurrent_index_by_name :projects, 'index_projects_on_visibility_level'
end
def down
add_concurrent_index :projects, :visibility_level
remove_concurrent_index :projects, %i(visibility_level created_at id)
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_11_12_115317) do
ActiveRecord::Schema.define(version: 2019_11_12_214305) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
......@@ -3145,7 +3145,7 @@ ActiveRecord::Schema.define(version: 2019_11_12_115317) do
t.index ["runners_token"], name: "index_projects_on_runners_token"
t.index ["runners_token_encrypted"], name: "index_projects_on_runners_token_encrypted"
t.index ["star_count"], name: "index_projects_on_star_count"
t.index ["visibility_level"], name: "index_projects_on_visibility_level"
t.index ["visibility_level", "created_at", "id"], name: "index_projects_on_visibility_level_and_created_at_and_id"
end
create_table "prometheus_alert_events", force: :cascade do |t|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment