How would you optimize a slow-running SQL query that aggregates millions of customer interaction rows?