How do you optimize a slow-running SQL query that involves multiple joins and aggregations on millions of rows?