
Slow SQL is a common bottleneck in analytics workflows, especially when large fact tables are joined to dimensions and filtered by date ranges or status fields. Interviewers want to hear how you diagnose the issue, not just a list of generic tuning tips.
You are asked to explain how you would optimize a slow-running PostgreSQL query used in a Tesla analytics workflow. Describe how you would investigate the problem, what you would look for in the execution plan, when you would add or change indexes, and how you would decide whether the issue is caused by joins, filters, aggregations, or poor query structure.
Keep the answer practical and medium-depth. You should cover a clear debugging sequence, mention EXPLAIN / EXPLAIN ANALYZE, discuss index selectivity and join behavior, and give examples of query rewrites that reduce scanned data or unnecessary work.