How would you optimize a slow-running query that aggregates millions of rows from an enterprise transactional database used for Workday reporting?