perf: switch analytics gas reads to the denormalized column#1434
Merged
Conversation
6cdde89 to
03d2376
Compare
Base automatically changed from
feature/KEEP-683-denormalize-workflow-gas
to
staging
June 2, 2026 04:27
…spend-cap Switch getWorkflowGasTotal (summary current + previous period) and the workflow portion of getSpendCapData to SUM workflow_executions.gas_used_wei instead of re-extracting and summing the per-step logs JSONB. Removes the logs join, the JSONB parse, and the TOAST detoast - the org+window slice is aggregated straight off workflow_executions with the date filter pushed into idx_workflow_executions_workflow_started. Staging proxy EXPLAIN (heaviest org, 30d): 2140ms / 5.1GB -> 397ms / 162MB. Gas is now windowed by run start (workflow_executions.started_at) rather than per-step time, consistent with the other summary metrics. Depends on the denormalized columns and backfill from the previous PR.
03d2376 to
29e2070
Compare
🧹 PR Environment Cleaned UpThe PR environment has been successfully deleted. Deleted Resources:
All resources have been cleaned up and will no longer incur costs. |
ℹ️ No PR Environment to Clean UpNo PR environment was found for this PR. This is expected if:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1433 (base branch is
feature/KEEP-683-denormalize-workflow-gas, notstaging). Draft until #1433 merges and the backfill has run - retarget tostagingthen.What
Switches the two heaviest
/analyticsgas reads off the per-step logs JSONB scan and onto the denormalizedworkflow_executions.gas_used_weicolumn added in #1433:getWorkflowGasTotal- powers the summary KPI for both the current and previous periodgetSpendCapData- today's gas against the daily capBoth now
SUM(workflow_executions.gas_used_wei)over the org+window via theworkflowsjoin only. No logs table, no JSONB parse, no TOAST detoast.Why / impact
This is the cold-scan that caching could not fix and that drove the 2026-05-29 RDS saturation. With the value as a first-class numeric column on a table already in the query, the org+window slice aggregates directly and the date filter pushes into an index.
Staging EXPLAIN, heaviest org, 30-day window
The new column is not on staging yet (#1433 not deployed there), so this is a shape-identical proxy:
SUM(duration)(an existing numeric column) over the exact sameworkflow_executions JOIN workflows WHERE org + started_atthe gas query now uses.Filter, not index-boundidx_workflow_executions_workflow_startedThe date filter is now index-pushed - the exact thing that was structurally impossible on the old log-keyed path. Staging has no TOAST pressure; on prod the win is larger because the old path's blob detoast is eliminated entirely.
Behavioral note
Gas is now windowed by run start (
workflow_executions.started_at) rather than per-step time, because the column is a run-level rollup. This makes gas consistent with every other summary metric (all already keyed to run start). Only boundary-straddling runs reattribute, by the gap between run start and a late gas-bearing step - immaterial at dashboard granularity. The full per-network breakdown, which genuinely needs step-level time/network, is unchanged and tracked as a separate follow-up.Not changed
getNetworkBreakdownand the runs-table aggregation still read the logs (network breakdown needs step granularity; the runs path is already paged and cheap).Merge prerequisites
SUM(gas_used_wei)equals the old JSON sum over that org's logs.Only then does switching the read keep totals stable.