How do you optimize a query that utilizes a window function on a massive, distributed dataset at Plaid?
Use the provided PostgreSQL tables and write the query for completed January transactions. The solution should reduce the data processed by the window calculation while producing deterministic results.
account_label, transaction_date, daily_net_amount, running_balance, and prior_running_balanceaccount_label, then transaction_date| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique Plaid account identifier |
| account_label | VARCHAR(100) | Display label for the account |
| region | VARCHAR(30) | Account region |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| account_id | INT | Referenced Plaid account |
| transaction_date | DATE | Posting date of the transaction |
| amount | NUMERIC(12,2) | Signed transaction amount |
| status | VARCHAR(20) | Transaction processing status |