Skip to content

Add back index_issues_on_work_item_type_id issues index

Mario Celi requested to merge 345830-create-index-sync into master

What does this MR do and why?

In !105285 (merged) we recreated the index_issues_on_work_item_type_id index asynchronously over the weekend. I have confirmed the index exists in .com

\d issues

Indexes:
    "issues_pkey" PRIMARY KEY, btree (id)
    "index_issues_on_project_id_and_external_key" UNIQUE, btree (project_id, external_key) WHERE external_key IS NOT NULL
    "index_issues_on_project_id_and_iid" UNIQUE, btree (project_id, iid)
    "idx_issues_on_health_status_not_null" btree (health_status) WHERE health_status IS NOT NULL
    "idx_issues_on_project_id_and_created_at_and_id_and_state_id" btree (project_id, created_at, id, state_id)
    "idx_issues_on_project_id_and_due_date_and_id_and_state_id" btree (project_id, due_date, id, state_id) WHERE due_date IS NOT NULL
    "idx_issues_on_project_id_and_rel_position_and_id_and_state_id" btree (project_id, relative_position, id, state_id)
    "idx_issues_on_project_id_and_updated_at_and_id_and_state_id" btree (project_id, updated_at, id, state_id)
    "idx_issues_on_state_id" btree (state_id)
    "idx_open_issues_on_project_and_confidential_and_author_and_id" btree (project_id, confidential, author_id, id) WHERE state_id = 1
    "index_issue_on_project_id_state_id_and_blocking_issues_count" btree (project_id, state_id, blocking_issues_count)
    "index_issues_on_author_id" btree (author_id)
    "index_issues_on_author_id_and_id_and_created_at" btree (author_id, id, created_at)
    "index_issues_on_closed_by_id" btree (closed_by_id)
    "index_issues_on_confidential" btree (confidential)
    "index_issues_on_description_trigram_non_latin" gin (description gin_trgm_ops) WHERE title::text !~ similar_escape('[\u0000-\u02FF\u1E00-\u1EFF\u2070-\u218F]*'::text, NULL::text) OR description !~ similar_escape('[\u0000-\u02FF\u1E00-\u1EFF\u2070->
    "index_issues_on_duplicated_to_id" btree (duplicated_to_id) WHERE duplicated_to_id IS NOT NULL
    "index_issues_on_id_and_weight" btree (id, weight)
    "index_issues_on_incident_issue_type" btree (issue_type) WHERE issue_type = 1
    "index_issues_on_last_edited_by_id" btree (last_edited_by_id)
    "index_issues_on_milestone_id" btree (milestone_id)
    "index_issues_on_moved_to_id" btree (moved_to_id) WHERE moved_to_id IS NOT NULL
    "index_issues_on_namespace_id" btree (namespace_id)
    "index_issues_on_project_id_and_created_at_issue_type_incident" btree (project_id, created_at) WHERE issue_type = 1
    "index_issues_on_project_id_and_state_id_and_created_at_and_id" btree (project_id, state_id, created_at, id)
    "index_issues_on_project_id_and_upvotes_count" btree (project_id, upvotes_count)
    "index_issues_on_project_id_closed_at_desc_state_id_and_id" btree (project_id, closed_at DESC NULLS LAST, state_id, id)
    "index_issues_on_project_id_closed_at_state_id_and_id" btree (project_id, closed_at, state_id, id)
    "index_issues_on_project_id_health_status_created_at_id" btree (project_id, health_status, created_at, id)
    "index_issues_on_promoted_to_epic_id" btree (promoted_to_epic_id) WHERE promoted_to_epic_id IS NOT NULL
    "index_issues_on_sprint_id" btree (sprint_id)
    "index_issues_on_title_trigram_non_latin" gin (title gin_trgm_ops) WHERE title::text !~ similar_escape('[\u0000-\u02FF\u1E00-\u1EFF\u2070-\u218F]*'::text, NULL::text) OR description !~ similar_escape('[\u0000-\u02FF\u1E00-\u1EFF\u2070-\u218F]*'::t>
    "index_issues_on_updated_at" btree (updated_at)
    "index_issues_on_updated_by_id" btree (updated_by_id) WHERE updated_by_id IS NOT NULL
    "index_issues_on_work_item_type_id" btree (work_item_type_id)
    "index_on_issues_closed_incidents_by_project_id_and_closed_at" btree (project_id, closed_at) WHERE issue_type = 1 AND state_id = 2
    "index_on_issues_health_status_asc_order" btree (project_id, health_status, id DESC, state_id, issue_type)
    "index_on_issues_health_status_desc_order" btree (project_id, health_status DESC NULLS LAST, id DESC, state_id, issue_type)

Now we need to introduce the index for other installs as described in https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#add-a-migration-to-create-the-index-synchronously

Migration Output

UP

bin/rails db:migrate
main: == 20221206173132 AddIssuesWorkItemTypeIdIndex: migrating =====================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0034s
main: -- index_exists?(:issues, :work_item_type_id, {:name=>"index_issues_on_work_item_type_id", :algorithm=>:concurrently})
main:    -> 0.0182s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- add_index(:issues, :work_item_type_id, {:name=>"index_issues_on_work_item_type_id", :algorithm=>:concurrently})
main:    -> 0.0046s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20221206173132 AddIssuesWorkItemTypeIdIndex: migrated (0.0402s) ============

ci: == 20221206173132 AddIssuesWorkItemTypeIdIndex: migrating =====================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0009s
ci: -- index_exists?(:issues, :work_item_type_id, {:name=>"index_issues_on_work_item_type_id", :algorithm=>:concurrently})
ci:    -> 0.0206s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0004s
ci: -- add_index(:issues, :work_item_type_id, {:name=>"index_issues_on_work_item_type_id", :algorithm=>:concurrently})
ci:    -> 0.0033s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0003s
ci: == 20221206173132 AddIssuesWorkItemTypeIdIndex: migrated (0.0422s) ============

DOWN

bin/rails db:migrate:down:main db:migrate:down:ci VERSION=20221206173132
main: == 20221206173132 AddIssuesWorkItemTypeIdIndex: reverting =====================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0041s
main: -- indexes(:issues)
main:    -> 0.0277s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0005s
main: -- remove_index(:issues, {:algorithm=>:concurrently, :name=>"index_issues_on_work_item_type_id"})
main:    -> 0.0043s
main: -- execute("RESET statement_timeout")
main:    -> 0.0005s
main: == 20221206173132 AddIssuesWorkItemTypeIdIndex: reverted (0.0558s) ============

ci: == 20221206173132 AddIssuesWorkItemTypeIdIndex: reverting =====================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0038s
ci: -- indexes(:issues)
ci:    -> 0.0544s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0010s
ci: -- remove_index(:issues, {:algorithm=>:concurrently, :name=>"index_issues_on_work_item_type_id"})
ci:    -> 0.0041s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0010s
ci: == 20221206173132 AddIssuesWorkItemTypeIdIndex: reverted (0.1016s) ============

## MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

* [x] I have evaluated the [MR acceptance checklist](https://docs.gitlab.com/ee/development/code_review.html#acceptance-checklist) for this MR.

<!-- template sourced from https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/merge_request_templates/Default.md -->

Related to #345830
Edited by Mario Celi

Merge request reports

Loading