How would you optimize a slow-running query that aggregates millions of rows of patient insurance claims data at Headway - Design & Development?