How would you optimize a slow-performing SQL query that aggregates millions of supply chain transactions for a Watershed analytics use case?