Skip to content

Commit 454e62a

Browse files
committed
perf(admin): count dashboard workflow runs on the existing ledger indexes
Drops the workflow-runs index and its migration: an extra write on every workflow ledger insert is not worth paying for a staff-only page. Spend stays index-only per entity; the separate run-count statement fetches the matched workflow rows from the heap on the existing period and created_at indexes.
1 parent 9d61bef commit 454e62a

5 files changed

Lines changed: 7 additions & 31643 deletions

File tree

‎apps/sim/lib/admin/dashboard-usage.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import type { BillingEntity } from '@/lib/billing/core/usage-log'
1111
* over its current usage period.
1212
*
1313
* Each read is one statement whose `UNION ALL` arms each cover one entity, so every arm
14-
* is a bounded index-only scan; one `BitmapOr` over all of them would fetch every matched
15-
* row from the heap instead:
14+
* is a scan bounded by one entity's period on `usage_log_billing_entity_period_cost_idx`
15+
* (stamped periods) or `usage_log_billing_entity_created_at_cost_idx` (reporting periods).
16+
* One `BitmapOr` over all of them would fetch every matched row from the heap instead.
1617
*
17-
* - spend reads `usage_log_billing_entity_period_cost_idx` (stamped periods) or
18-
* `usage_log_billing_entity_created_at_cost_idx` (reporting periods);
19-
* - workflow runs read `usage_log_billing_entity_workflow_runs_idx`, the only index
20-
* carrying `execution_id`, which is why they are a separate statement.
18+
* Spend is index-only. Workflow runs are a separate statement because no index carries
19+
* `execution_id`: they fetch each matched workflow row from the heap, and keeping them
20+
* apart leaves the spend scans index-only. An index for them would cost every workflow ledger
21+
* insert an extra write to speed up a staff-only page.
2122
*
2223
* They stay on the primary, where the hot billing sums keep those index pages cached. On
2324
* the replica the same scans read from disk, and a statement held past the standby's

‎packages/db/migrations/0446_usage_log_billing_entity_workflow_runs_idx.sql‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)