How do you optimize a SQL SELECT statement for a large table?
Use the supplied PostgreSQL tables to return active records whose latest non-test event occurred during 2025. Preserve active records even when no matching label exists, and avoid applying functions to the timestamp predicate.
Output
- One row per qualifying active record with
record_id, record_name, label_name, latest_event_type, and latest_event_at.
- Include records with no label, order by
latest_event_at descending, then record_id ascending.