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.
Output details
- Use tasks created on or after
2025-01-01 and before 2025-04-01.
- Treat missing provider markets as
Unassigned.
- Calculate
completion_rate_pct as completed tasks divided by total tasks, multiplied by 100 and rounded to two decimal places.
- Use dense ranking by descending
completed_tasks, allowing all categories tied at rank 2.
- Calculate
previous_completed_tasks from the prior available month for the same market and category, leaving it NULL when unavailable.