Skip to content

Commit f613f31

Browse files
committed
prevent seq scan on workspace_builds for GetQuotaAllowanceForUser
1 parent ec8f799 commit f613f31

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

coderd/database/queries.sql.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/quotas.sql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ INNER JOIN groups ON
1818
WITH latest_builds AS (
1919
SELECT
2020
DISTINCT ON
21-
(workspace_id) id,
22-
workspace_id,
23-
daily_cost
21+
(wb.workspace_id) wb.id,
22+
wb.workspace_id,
23+
wb.daily_cost
2424
FROM
2525
workspace_builds wb
26+
-- This INNER JOIN prevents a
27+
INNER JOIN
28+
workspaces on wb.workspace_id = workspaces.id
29+
WHERE
30+
workspaces.owner_id = @owner_id
2631
ORDER BY
27-
workspace_id,
28-
created_at DESC
32+
wb.workspace_id,
33+
wb.created_at DESC
2934
)
3035
SELECT
3136
coalesce(SUM(daily_cost), 0)::BIGINT

0 commit comments

Comments
 (0)