diff --git a/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb b/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..26b91086a0c6eb97af5ae00e86f724d8650e3b3a --- /dev/null +++ b/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CreateIdxVulnerabilityOccurencesOnPrimIdenId < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '17.1' + + NEW_INDEX_NAME = 'index_vulnerability_occurrences_prim_iden_id_and_vuln_id' + TABLE_NAME = :vulnerability_occurrences + + # rubocop:disable Migration/PreventIndexCreation -- This index was created async previously, check https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131647 + def up + add_concurrent_index( + TABLE_NAME, [:primary_identifier_id, :vulnerability_id], + name: NEW_INDEX_NAME + ) + end + # rubocop:enable Migration/PreventIndexCreation + + def down + remove_concurrent_index_by_name TABLE_NAME, NEW_INDEX_NAME + end +end diff --git a/db/schema_migrations/20240610125054 b/db/schema_migrations/20240610125054 new file mode 100644 index 0000000000000000000000000000000000000000..588175dc4c97bf3bfd3ea4ba45d70b2287c439d6 --- /dev/null +++ b/db/schema_migrations/20240610125054 @@ -0,0 +1 @@ +56a9e10470493d009e66bbcc10f3ac2301ddcb76ecaa9ff5034f4faf5103491f \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 647d253f3fffdfa9ae80baf8736658f39b8e3b1d..5f13dbee15d78d5b489bb0582b3a1125d0d42c63 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -29010,6 +29010,8 @@ CREATE UNIQUE INDEX index_vulnerability_occurrences_on_uuid_1 ON vulnerability_o CREATE INDEX index_vulnerability_occurrences_on_vulnerability_id ON vulnerability_occurrences USING btree (vulnerability_id); +CREATE INDEX index_vulnerability_occurrences_prim_iden_id_and_vuln_id ON vulnerability_occurrences USING btree (primary_identifier_id, vulnerability_id); + CREATE INDEX index_vulnerability_reads_common_attrs_and_detection_for_groups ON vulnerability_reads USING btree (resolved_on_default_branch, state, report_type, severity, traversal_ids, vulnerability_id) WHERE (archived = false); CREATE INDEX index_vulnerability_reads_common_finder_query_2 ON vulnerability_reads USING btree (project_id, state, report_type, severity, vulnerability_id DESC, dismissal_reason); diff --git a/spec/support/helpers/database/duplicate_indexes.yml b/spec/support/helpers/database/duplicate_indexes.yml index cc1a7a8364299bae2fceba28587f82e7e58af061..10bee78641a1b149792ef916573db2b5b3f4783f 100644 --- a/spec/support/helpers/database/duplicate_indexes.yml +++ b/spec/support/helpers/database/duplicate_indexes.yml @@ -129,6 +129,9 @@ vulnerability_finding_signatures: vulnerability_flags: index_vulnerability_flags_on_unique_columns: - index_vulnerability_flags_on_vulnerability_occurrence_id +vulnerability_occurrences: + index_vulnerability_occurrences_prim_iden_id_and_vuln_id: + - index_vulnerability_occurrences_on_primary_identifier_id work_item_hierarchy_restrictions: index_work_item_hierarchy_restrictions_on_parent_and_child: - index_work_item_hierarchy_restrictions_on_parent_type_id