Fix environments query for pipeline
What does this MR do and why?
This is a follow-up for the previous fix.
Previously, we fixed that empty environments were returned in the environments_in_self_and_descendants
query, however, it turns out there are some edge cases that it returns non-empty environments but corresponding deployment doesn't exist. This MR fixes the point with SHA filtering.
This is still behind avoid_cross_joins_environments_in_self_and_descendants
feature flag.
Query Example
SELECT
"environments".*
FROM
"environments"
WHERE
"environments"."project_id" = 7764
AND "environments"."name" IN ('review/vv-update-vamsivempati-details-on-team-page-dec-6', 'review/nickbp-mission-merge-conflict', 'review/conducting-an-interview-embed-video')
AND (
EXISTS (
SELECT
1
FROM
"deployments"
WHERE
(deployments.environment_id = environments.id)
AND "deployments"."sha" = '03e049b38ca152db18a014e564bac1fd41c127e3'
)
)
Query Plan
Nested Loop Semi Join (cost=1.25..61.63 rows=1 width=162) (actual time=17.876..17.877 rows=0 loops=1)
Buffers: shared hit=23 read=13 dirtied=2
I/O Timings: read=15.658 write=0.000
-> Index Scan using index_environments_on_project_id_and_name on public.environments (cost=0.56..7.71 rows=1 width=162) (actual time=3.459..10.211 rows=3 loops=1)
Index Cond: ((environments.project_id = 7764) AND ((environments.name)::text = ANY ('{review/vv-update-vamsivempati-details-on-team-page-dec-6,review/nickbp-mission-merge-conflict,review/conducting-an-interview-embed-video}'::text[])))
Buffers: shared hit=12 read=7 dirtied=2
I/O Timings: read=8.120 write=0.000
-> Index Only Scan using index_deployments_on_environment_status_sha on public.deployments (cost=0.70..27.31 rows=1 width=4) (actual time=2.549..2.549 rows=0 loops=3)
Index Cond: ((deployments.environment_id = environments.id) AND (deployments.sha = '03e049b38ca152db18a014e564bac1fd41c127e3'::text))
Heap Fetches: 0
Buffers: shared hit=11 read=6
I/O Timings: read=7.539 write=0.000
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Shinya Maeda