How would you approach optimizing a slow-running SQL query in a distributed environment?
Use PostgreSQL SQL to produce an optimized version that limits scanned data, avoids unnecessary row multiplication, and preserves the required results. The query should summarize qualifying user activity by region and month.
Output
- One row per region and activity month, with
region, month_start, active_users, total_events, and top_3_event_total.
- Include only active users and
view or click events from January and February 2025.
- Sort by
region, then month_start, both ascending.