Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Perf improvement
  • Loading branch information
mtojek committed Jul 24, 2023
commit a759b38ff313185d9d11f5501a6844c096fc3d52
16 changes: 6 additions & 10 deletions coderd/database/queries/insights.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@ WITH d AS (
), template_ids AS (
SELECT
template_usage_by_day.from_,
array_agg(DISTINCT id) AS ids
array_agg(template_id) AS ids
FROM (
SELECT template_usage_by_day_unnested.from_, unnest(ids) AS id
FROM (
SELECT DISTINCT
from_,
array_agg(DISTINCT template_id) AS ids
FROM usage_by_day, unnest(template_ids) template_id
WHERE template_id IS NOT NULL
GROUP BY from_, template_ids
) AS template_usage_by_day_unnested
SELECT DISTINCT
from_,
template_id
FROM usage_by_day, unnest(template_ids) template_id
WHERE template_id IS NOT NULL
) AS template_usage_by_day
GROUP BY template_usage_by_day.from_
)
Expand Down