Explain how you would optimize a slow-running query that joins multiple high-volume tables, such as TikTok user views and ad impressions.
Use the provided tables to produce campaign-level daily metrics for active users during the specified date range. The result must avoid double-counting caused by joining multiple event rows for the same user and campaign.
Output
- One row per campaign and event date with activity.
- Columns:
campaign_id, campaign_name, report_date, view_count, unique_viewers, impression_count, unique_impression_users, and overlap_users.
- Include campaigns with views or impressions, order by
report_date, then campaign_id.