How do you optimize a query that is scanning millions of rows?
Using the provided PostgreSQL schema, return the latest qualifying event for each active account. The query must restrict events to the first quarter of 2026, include only open events with severity at least 4, and preserve accounts whose event type is unknown.
Output
- One row per active account with a qualifying event.
- Columns:
account_id, account_name, event_id, event_type_name, occurred_at, and severity.
- Sort by
account_id ascending, then occurred_at descending, and event_id descending.