At Acme Retail, a simple reporting query has become slow as the sales table has grown. Interviewers use this kind of question to test whether you understand practical SQL performance tuning, not just syntax.
Explain how you would optimize a slow SQL query in PostgreSQL to improve performance. Your answer should cover:
You may reference common patterns such as unnecessary SELECT *, filtering late instead of early, functions on indexed columns, avoidable sorting, and inefficient aggregations.
Keep the discussion at an easy interview level: focus on a clear, structured optimization process, practical examples, and the most common performance mistakes candidates should recognize in PostgreSQL.