Skip to content

Commit fb6d1cc

Browse files
committed
RHINENG-25871: optimize floorist hms query
moved rh_account_id -> org_id and template_id -> uuid, environment, name translation out of the group by old explain (cost=30975084.16..65065473.36 rows=112255200 width=99) new explain (cost=3348694.31..3348794.31 rows=40000 width=99)
1 parent 67b761b commit fb6d1cc

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

deploy/clowdapp.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,16 +595,17 @@ objects:
595595
- prefix: hms_analytics/content-sources/system-template-grouped
596596
chunksize: ${{FLOORIST_HMS_CHUNKSIZE}}
597597
query: >-
598-
SELECT a.org_id,
599-
count(si.inventory_id),
598+
SELECT a.org_id, tc.systems_count,
600599
t.uuid::text as template_uuid, t.environment_id, t.name as template_name,
601600
CURRENT_DATE as collected_at
602-
FROM system_inventory si
603-
JOIN system_patch spatch ON spatch.system_id = si.id AND spatch.rh_account_id = si.rh_account_id
604-
JOIN rh_account a ON a.id = si.rh_account_id
605-
LEFT JOIN template t ON t.id = spatch.template_id AND t.rh_account_id = spatch.rh_account_id
606-
WHERE si.last_upload >= date_trunc('month', CURRENT_DATE)
607-
group by a.org_id, template_uuid, t.environment_id, template_name
601+
FROM (SELECT spatch.rh_account_id, spatch.template_id, count(*) as systems_count
602+
FROM system_patch spatch
603+
JOIN system_inventory si ON spatch.system_id = si.id AND spatch.rh_account_id = si.rh_account_id
604+
WHERE si.last_upload >= date_trunc('month', CURRENT_DATE)
605+
group by spatch.rh_account_id, spatch.template_id
606+
) as tc
607+
JOIN rh_account a ON a.id = tc.rh_account_id
608+
LEFT JOIN template t ON t.id = tc.template_id AND t.rh_account_id = tc.rh_account_id
608609
ORDER BY a.org_id;
609610
610611

0 commit comments

Comments
 (0)