How do you optimize a slow-running SQL query that involves multiple large table joins and complex aggregations?