How would you optimize a slow-running SQL query that aggregates millions of rows of flight delay data?