How would you optimize a slow-running SQL query containing multiple joins and aggregations over a table with millions of records?