Track epic issues count on usage data
What does this MR do?
Track epic issues with usage ping.
related to #233156 (closed)
Queries with plans
Gitlab::UsageData.count(EpicIssue)
(2.6ms) SELECT MIN("epic_issues"."id") FROM "epic_issues"
(0.6ms) SELECT MAX("epic_issues"."id") FROM "epic_issues"
(0.3ms) SELECT COUNT("epic_issues"."id") FROM "epic_issues" WHERE "epic_issues"."id" >= $1 AND "epic_issues"."id" < $2 [["id", 2], ["id", 342996]]
EXPLAIN ANALYZE SELECT MIN("epic_issues"."id") FROM "epic_issues" \g
QUERY PLAN
---------------------------------------------------------------------------------------------------------
------------------------------------------------
Result (cost=0.45..0.46 rows=1 width=4) (actual time=1.806..1.806 rows=1 loops=1)
InitPlan 1 (returns $0)
-> Limit (cost=0.42..0.45 rows=1 width=4) (actual time=1.803..1.803 rows=1 loops=1)
-> Index Only Scan using epic_issues_pkey on epic_issues (cost=0.42..6780.40 rows=254733 wid
th=4) (actual time=1.802..1.802 rows=1 loops=1)
Index Cond: (id IS NOT NULL)
Heap Fetches: 0
Planning Time: 1.390 ms
Execution Time: 1.980 ms
(8 rows)
EXPLAIN ANALYZE SELECT MAX("epic_issues"."id") FROM "epic_issues" \g
QUERY PLAN
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------
Result (cost=0.45..0.46 rows=1 width=4) (actual time=0.887..0.887 rows=1 loops=1)
InitPlan 1 (returns $0)
-> Limit (cost=0.42..0.45 rows=1 width=4) (actual time=0.882..0.882 rows=1 loops=1)
-> Index Only Scan Backward using epic_issues_pkey on epic_issues (cost=0.42..6780.40 rows=2
54733 width=4) (actual time=0.881..0.881 rows=1 loops=1)
Index Cond: (id IS NOT NULL)
Heap Fetches: 1
Planning Time: 0.105 ms
Execution Time: 0.907 ms
(8 rows)
EXPLAIN ANALYZE SELECT COUNT("epic_issues"."id") FROM "epic_issues" WHERE "epic_issues"."id" >= 2 AND "epic_issues"."id" < 342996
---------------------------------------------------------------------------------------------------------
------------------------------------------------------------------
Finalize Aggregate (cost=7196.82..7196.83 rows=1 width=8) (actual time=96.077..96.077 rows=1 loops=1)
-> Gather (cost=7196.61..7196.82 rows=2 width=8) (actual time=91.537..106.051 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Partial Aggregate (cost=6196.61..6196.62 rows=1 width=8) (actual time=88.347..88.348 rows=1
loops=3)
-> Parallel Index Only Scan using epic_issues_pkey on epic_issues (cost=0.42..5931.26 ro
ws=106138 width=4) (actual time=0.749..82.218 rows=85048 loops=3)
Index Cond: ((id >= 2) AND (id < 342996))
Heap Fetches: 50870
Planning Time: 0.220 ms
Execution Time: 106.171 ms
(10 rows)
Detailed explain
https://explain.depesz.com/s/Oesv
https://explain.depesz.com/s/QkTR
https://explain.depesz.com/s/44Rb
Edited by Felipe Cardozo