Skip to content

Commit 27916f3

Browse files
authored
Merge pull request #25 from topcoder-platform/develop
Optimization for better speed to fix issue noted by Topgear
2 parents 29ed6a9 + 9dfb561 commit 27916f3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

sql/reports/topgear/hourly.sql

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
WITH bill AS (
2-
SELECT
3-
cb."challengeId" AS challenge_id,
4-
MAX(cb."billingAccountId") FILTER (WHERE cb."billingAccountId" IS NOT NULL) AS billing_account_id
5-
FROM challenges."ChallengeBilling" cb
6-
WHERE cb."billingAccountId" = '80000062'
7-
GROUP BY cb."challengeId"
8-
),
9-
base_challenges AS (
1+
WITH base_challenges AS (
102
SELECT
113
c.*,
12-
b.billing_account_id
4+
ba.billing_account_id
135
FROM challenges."Challenge" c
14-
JOIN bill b
15-
ON b.challenge_id = c.id
6+
JOIN LATERAL (
7+
SELECT
8+
MAX(cb."billingAccountId") AS billing_account_id
9+
FROM challenges."ChallengeBilling" cb
10+
WHERE cb."challengeId" = c.id
11+
AND cb."billingAccountId" = '80000062'
12+
) ba ON TRUE
1613
WHERE c."createdAt" >= now() - interval '4 months'
14+
AND ba.billing_account_id IS NOT NULL
1715
),
1816
project_details AS (
1917
SELECT

0 commit comments

Comments
 (0)