Tell me about how you optimize query performance for large-scale TaskRabbit data workloads.
Write an optimized PostgreSQL query against the supplied TaskRabbit tables that summarizes task workload by provider market, creation month, and task category. Include all tasks in the date range, including tasks without an assignment, and calculate completion metrics and month-over-month completed-task changes.
Output
- One row per market, month, and category whose category rank is at most 2 within that market and month.
- Columns:
market, month_start, category, total_tasks, completed_tasks, completion_rate_pct, previous_completed_tasks, and category_rank.
- Sort by
market, month_start, category_rank, and category ascending.