Skip to content

Improve the perfomance of finding cancelable pipelines for users

Marius Bobin requested to merge ci-improve-users-cancelable-pipelines-query into master

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)

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

Availability and Testing

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

Merge request reports