Skip to content

[Issue #1069] Improve performance of dashboard queries via new analytics db indexes and views - #11819

Open
DavidDudas-Intuitial wants to merge 3 commits into
mainfrom
daviddudas-intuitial/analytics-burndown-query-fixes
Open

[Issue #1069] Improve performance of dashboard queries via new analytics db indexes and views#11819
DavidDudas-Intuitial wants to merge 3 commits into
mainfrom
daviddudas-intuitial/analytics-burndown-query-fixes

Conversation

@DavidDudas-Intuitial

@DavidDudas-Intuitial DavidDudas-Intuitial commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1069

Changes proposed

This PR:

1. Add indexes to improve performance of deliverable burndown/burnup queries

The deliverable burndown/burnup queries recursively walk the epic->issue tree via gh_issue.parent_issue_ghid, and look up the latest deliverable/epic mapping via gh_deliverable_quad_map/gh_epic_deliverable_map -- none of these had a supporting index, so each fell back to a full table scan or sort on every query execution.

To solve this, we add migration 0014_add_burndown_query_indexes.sql, creating indexes on gh_issue(parent_issue_ghid), gh_deliverable_quad_map(deliverable_id, d_effective), and gh_epic_deliverable_map(epic_id, d_effective).

2. Add materialized views to improve performance of deliverable burndown/burnup queries

The deliverable burndown/burnup queries each independently recompute a per-quad deliverable ranking and a latest epic-to-deliverable mapping, then walk a recursive epic/issue tree joined against gh_issue_history on every single query execution -- this is very expensive, and duplicated across 24 burndown/burnup-adjacent queries.

To solve this, we create three materialized views in 0015_add_deliverable_epic_materialized_views.sql:

  • mv_deliverables_per_quad -- per-quad deliverable ranking
  • mv_latest_epic_deliverable_map -- latest epic-to-deliverable mapping
  • mv_deliverable_daily_burndown -- deliverable-to-issue membership (epic tree walk + direct children) pre-joined against gh_issue_history and pre-aggregated by (deliverable_id, day)

sync_data() in etldb/main.py now refreshes all three via a new refresh_materialized_views(db) function after every sync, so they're never more than one sync-cycle stale.

3. Fix calculation bug in burnup queries

Due to a copy/paste bug, 155-Sprint_Burnup_by_points.sql, 156-Sprint_Burnup_by_issues.sql, 212-Deliverable_Burnup_Issue_Count.sql, and 213-Deliverable_Burnup_Points.sql all computed results wrongly (using burndown formula instead of burnup formula). Fixed the queries to use correct calculations.

Context for reviewers

mv_deliverable_daily_burndown depends on mv_latest_epic_deliverable_map, so refresh_materialized_views refreshes them in a fixed order to avoid recomputing against a stale epic-to-deliverable mapping.

Validation steps

  • Verified via EXPLAIN ANALYZE that the three affected joins/window functions switch from Seq Scan+Sort to Index Scan after adding the equivalent indexes.
  • Ran analytics etl db_migrate against a fresh local Postgres instance -- migration 0015 applies cleanly on top of 0014, all three views created.
  • Ran a full analytics etl extract_transform_and_load against the real HHS/simpler-grants-gov GitHub Project boards (3 projects, 69 deliverables, 62 sprints, 324 epics, 3603 issues) and confirmed all three views populate with correct, sensible data via refresh_materialized_views.

…exes

The four burnup questions (Sprint_Burnup_by_issues/points,
Deliverable_Burnup_Issue_Count/Points) were exact copies of their burndown
counterparts, computing a single declining total_remaining series instead
of exposing scope/completed as two independent series that both climb
toward total scope. Renames the underlying CTEs (opened/closed ->
scope/completed) and drops the subtraction.

Also adds migration 0014, creating indexes on gh_issue(parent_issue_ghid)
and the "latest row per deliverable/epic" lookups on
gh_deliverable_quad_map/gh_epic_deliverable_map -- all three previously
fell back to a full table scan or sort on every Deliverable_Burndowns/
Deliverable_Burnup/Deliverable_Data query. Verified via EXPLAIN ANALYZE
against a copy of this schema that this switches those plans to index
scans.

This repo doesn't yet have seed/backup tooling for its analytics pipeline,
so these are raw SQL/migration file changes only -- applying the updated
question text to the live Metabase instance and running the migration
still needs to happen manually.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@DavidDudas-Intuitial DavidDudas-Intuitial changed the title Fix burnup queries copied from burndown, add missing burndown query indexes Fix bug in burnup queries and add db indexes to improve query performance Aug 5, 2026
@DavidDudas-Intuitial DavidDudas-Intuitial changed the title Fix bug in burnup queries and add db indexes to improve query performance [Issue #11818] Improve performance of dashboard queries via new analytics db indexes and views Aug 6, 2026
@DavidDudas-Intuitial DavidDudas-Intuitial changed the title [Issue #11818] Improve performance of dashboard queries via new analytics db indexes and views [Issue #1069] Improve performance of dashboard queries via new analytics db indexes and views Aug 6, 2026
DavidDudas-Intuitial and others added 2 commits August 5, 2026 19:08
Mirrors the optimization applied in delivery-intelligence (its proto-
implementation lives here): the deliverable/epic burndown queries
recompute a per-quad deliverable ranking and a latest epic-to-deliverable
mapping via window functions/anti-joins and a DISTINCT ON over full
history tables, plus a recursive epic/issue tree walk joined against
gh_issue_history, all on every query.

Migration 0015 adds mv_deliverables_per_quad, mv_latest_epic_deliverable_map,
and mv_deliverable_daily_burndown to precompute these once. main.py's
sync_data() refreshes them via a new refresh_materialized_views(db)
function -- a plain function taking db as a parameter, matching the
existing sync_projects/sync_quads/etc. pattern rather than living as a
method on EtlDb.

This does not update any of the 24 burndown/burnup/percent-done queries
that could read from these views -- that's follow-up work once this repo
has seed/backup tooling to manage the card SQL safely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@DavidDudas-Intuitial
DavidDudas-Intuitial marked this pull request as ready for review August 6, 2026 02:49
@DavidDudas-Intuitial DavidDudas-Intuitial self-assigned this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dashboards] Improve performance of burndown/burnup queries

1 participant