Improve the perfomance of finding cancelable pipelines for users
What does this MR do?
Improves the performance of the query used to identify cancelable pipelines for a given user.
Related to https://gitlab.com/gitlab-org/gitlab/-/issues/301222
Screenshots (strongly suggested)
- Query and execution plans before adding the index: https://console.postgres.ai/shared/33a94e3c-9ae4-4c95-a851-f99d5732dc53
- Adding the index: https://gitlab.slack.com/archives/CLJMDRD8C/p1615470333112700 -
The query has been executed. Duration: 2402.394 s (estimated* for prod: 200.456...2402.394 s)
- Query and execution plans after adding the index: https://console.postgres.ai/shared/4f651cd1-7348-43ac-bc21-d0bd8151bd90
Up
VERSION=20210311093723 bin/rails db:migrate:up
== 20210311093723 AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers: migrating
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_pipelines, [:user_id, :id], {:where=>"((status)::text = ANY (\n ARRAY[\n ('running'::character varying)::text,\n ('waiting_for_resource'::character varying)::text,\n ('preparing'::character varying)::text,\n ('pending'::character varying)::text,\n ('created'::character varying)::text,\n ('scheduled'::character varying)::text\n ]\n))\n", :name=>"index_ci_pipelines_on_user_id_and_id_and_cancelable_status", :algorithm=>:concurrently})
-> 0.0094s
-- execute("SET statement_timeout TO 0")
-> 0.0010s
-- add_index(:ci_pipelines, [:user_id, :id], {:where=>"((status)::text = ANY (\n ARRAY[\n ('running'::character varying)::text,\n ('waiting_for_resource'::character varying)::text,\n ('preparing'::character varying)::text,\n ('pending'::character varying)::text,\n ('created'::character varying)::text,\n ('scheduled'::character varying)::text\n ]\n))\n", :name=>"index_ci_pipelines_on_user_id_and_id_and_cancelable_status", :algorithm=>:concurrently})
-> 0.0094s
-- execute("RESET ALL")
-> 0.0009s
== 20210311093723 AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers: migrated (0.0224s)
Down
VERSION=20210311093723 bin/rails db:migrate:down
== 20210311093723 AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers: reverting
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_pipelines)
-> 0.0135s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- remove_index(:ci_pipelines, {:algorithm=>:concurrently, :name=>"index_ci_pipelines_on_user_id_and_id_and_cancelable_status"})
-> 0.0041s
-- execute("RESET ALL")
-> 0.0008s
== 20210311093723 AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers: reverted (0.0207s)
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. - [-] I have not included a changelog entry because _____.
-
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Mayra Cabrera