Use default_branch for code coverage
Ref: #231386 (closed)
Following up !45702 (merged) where we started to persist the default_branch
associated to a code coverage record.
What does this MR do?
This MR updates our SQL query
to fetch our code coverage data only for the default_branch
.
Why are we doing this?
For the development of our feature, we only want to display the coverage for the default_branch
. This MR takes care of it.
Query Plan
- cold cache:
33.547 ms
- warm cache:
0.611 ms
Query:
WITH "latest_by_project" AS (
SELECT
"ci_daily_build_group_report_results"."project_id",
MAX(date) AS date
FROM
"ci_daily_build_group_report_results"
WHERE
"ci_daily_build_group_report_results"."project_id" = 278964
AND ((DATA -> 'coverage') IS NOT NULL)
AND "ci_daily_build_group_report_results"."default_branch" = TRUE
GROUP BY
"ci_daily_build_group_report_results"."project_id"
)
SELECT
"ci_daily_build_group_report_results"."project_id",
AVG(cast(DATA ->> 'coverage' AS float)),
COUNT(*),
latest_by_project.date
FROM
"ci_daily_build_group_report_results"
JOIN latest_by_project ON ci_daily_build_group_report_results.date = latest_by_project.date
AND ci_daily_build_group_report_results.project_id = latest_by_project.project_id
WHERE
"ci_daily_build_group_report_results"."project_id" = 278964
AND ((DATA -> 'coverage') IS NOT NULL)
AND "ci_daily_build_group_report_results"."default_branch" = TRUE
GROUP BY
"ci_daily_build_group_report_results"."project_id",
latest_by_project.date
https://explain.depesz.com/s/qAVe
Query plan:Aggregate (cost=9.07..9.11 rows=1 width=28) (actual time=2.871..2.873 rows=1 loops=1)
Group Key: ci_daily_build_group_report_results.project_id, latest_by_project.date
Buffers: shared hit=18 read=9 dirtied=7
I/O Timings: read=0.734
CTE latest_by_project
-> Aggregate (cost=0.28..4.74 rows=45 width=12) (actual time=2.727..2.728 rows=1 loops=1)
Group Key: ci_daily_build_group_report_results_1.project_id
Buffers: shared hit=10 read=9 dirtied=7
I/O Timings: read=0.734
-> Index Only Scan using index_ci_daily_build_group_report_results_on_project_and_date on public.ci_daily_build_group_report_results ci_daily_build_group_report_results_1 (cost=0.28..4.07 rows=45 width=12) (actual time=0.645..2.715 rows=3 loops=1)
Index Cond: (ci_daily_build_group_report_results_1.project_id = 278964)
Heap Fetches: 37
Buffers: shared hit=10 read=9 dirtied=7
I/O Timings: read=0.734
-> Sort (cost=4.33..4.34 rows=1 width=42) (actual time=2.843..2.845 rows=3 loops=1)
Sort Key: latest_by_project.date
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=18 read=9 dirtied=7
I/O Timings: read=0.734
-> Nested Loop (cost=0.28..4.32 rows=1 width=42) (actual time=2.757..2.763 rows=3 loops=1)
Buffers: shared hit=15 read=9 dirtied=7
I/O Timings: read=0.734
-> CTE Scan on latest_by_project (cost=0.00..1.01 rows=1 width=12) (actual time=2.738..2.739 rows=1 loops=1)
Filter: (latest_by_project.project_id = 278964)
Rows Removed by Filter: 0
Buffers: shared hit=10 read=9 dirtied=7
I/O Timings: read=0.734
-> Index Scan using index_ci_daily_build_group_report_results_on_project_and_date on public.ci_daily_build_group_report_results (cost=0.28..3.30 rows=1 width=42) (actual time=0.014..0.018 rows=3 loops=1)
Index Cond: ((ci_daily_build_group_report_results.project_id = 278964) AND (ci_daily_build_group_report_results.date = latest_by_project.date))
Buffers: shared hit=5
Cold cache:
Time: 33.547 ms
- planning: 0.594 ms
- execution: 32.953 ms
- I/O read: 14.846 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 18 (~144.00 KiB) from the buffer pool
- reads: 9 (~72.00 KiB) from the OS file cache, including disk I/O
- dirtied: 7 (~56.00 KiB)
- writes: 0
Warm cache:
Time: 0.611 ms
- planning: 0.452 ms
- execution: 0.159 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 11 (~88.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
How the feature looks like?
You can visualize how this feature looks like on the mocks.
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] 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 Max Orefice