Slow SQL can delay reporting, dashboard refreshes, and analyst workflows. In a retail environment with large order and customer tables, you are expected to improve performance without changing the business meaning of the query.
You are given a slow PostgreSQL query that joins QVC order, customer, and item-level tables to produce a monthly customer summary. Explain how you would optimize it. Discuss how you would inspect joins, reduce unnecessary scans, evaluate whether a CTE or subquery is helping or hurting, and handle date-based filtering so indexes can still be used.
Focus on practical SQL-level optimization rather than infrastructure tuning. The interviewer expects you to describe how you would diagnose the bottleneck, rewrite the query when needed, and explain the trade-offs behind your choices.