Slow SQL is a common issue in customer-facing analytics and cost reporting, especially when large Apptio datasets are joined and aggregated for dashboards or scheduled extracts.
You are given a PostgreSQL query used to power an Apptio cost reporting view. It joins several tables, filters by date, aggregates spend, and now runs too slowly as data volume grows. Explain how you would diagnose the bottleneck and optimize the query. Your answer should cover how you would inspect joins, aggregations, CTE usage, and date-based filtering, and how you would decide whether to change the SQL, indexing strategy, or data model.
The interviewer expects a practical optimization framework rather than a list of generic tips. You should discuss how to validate assumptions with execution plans, what common anti-patterns to look for, and how to balance readability with performance.