Add index to ci_daily_build_group_report_result
Part of #231386 (closed)
Following up !45554 (closed) where we introduced a new boolean
column default_branch
to our ci_daily_build_group_report_result
table.
What does this MR do?
This MR adds a new index to our ci_daily_build_group_report_result
table.
Why are we doing this?
Today it's a pain to fetch our coverage
data per project and filter out our coverage
for the project's default branch.
To help postgres
figures out the most recent coverage
by project for the default branch, the team decided to add an index
which will make sure our SQL
performs well.
How the feature looks like?
You can visualize how this feature looks like on the mocks.
Database Review
-----Click here for supplemental database review materials------
Up migration output: Column creation
$ bin/rails db:migrate
== 20201019182129 AddIndexToCiDailyBuildGroupReportResults: migrating =========
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_daily_build_group_report_results, [:project_id, :date], {:order=>{:date=>:desc}, :where=>"default_branch AND (data -> 'coverage') IS NOT NULL", :name=>"index_ci_daily_build_group_report_results_on_project_and_date", :algorithm=>:concurrently})
-> 0.0024s
-- add_index(:ci_daily_build_group_report_results, [:project_id, :date], {:order=>{:date=>:desc}, :where=>"default_branch AND (data -> 'coverage') IS NOT NULL", :name=>"index_ci_daily_build_group_report_results_on_project_and_date", :algorithm=>:concurrently})
-> 0.0071s
== 20201019182129 AddIndexToCiDailyBuildGroupReportResults: migrated (0.0098s)
$ bin/rails dbconsole
psql (11.7)
Type "help" for help.
gitlabhq_development=# \d ci_pipeline_artifacts
Table "public.ci_daily_build_group_report_results"
Column | Type | Collation | Nullable | Default
------------------+---------+-----------+----------+-----------------------------------------------------------------
id | bigint | | not null | nextval('ci_daily_build_group_report_results_id_seq'::regclass)
date | date | | not null |
project_id | bigint | | not null |
last_pipeline_id | bigint | | not null |
ref_path | text | | not null |
group_name | text | | not null |
data | jsonb | | not null |
default_branch | boolean | | not null | false
Indexes:
"ci_daily_build_group_report_results_pkey" PRIMARY KEY, btree (id)
"index_daily_build_group_report_results_unique_columns" UNIQUE, btree (project_id, ref_path, date, group_name)
"index_ci_daily_build_group_report_results_on_last_pipeline_id" btree (last_pipeline_id)
"index_ci_daily_build_group_report_results_on_project_and_date" btree (project_id, date DESC) WHERE default_branch AND (data -> 'coverage'::text) IS NOT NULL
Foreign-key constraints:
"fk_rails_0667f7608c" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_rails_ee072d13b3" FOREIGN KEY (last_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE
Rollback column creation
$ bin/rails db:rollback
== 20201019182129 AddIndexToCiDailyBuildGroupReportResults: reverting =========
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_daily_build_group_report_results)
-> 0.0040s
-- remove_index(:ci_daily_build_group_report_results, {:algorithm=>:concurrently, :name=>"index_ci_daily_build_group_report_results_on_project_and_date"})
-> 0.0022s
== 20201019182129 AddIndexToCiDailyBuildGroupReportResults: reverted (0.0067s)
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry - Changelog to be included with feature flag removal.
- [-] Documentation (if required) - Documentation to be included with feature flag removal.
-
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