How would you optimize a slow-running query that pulls data from a massive electronic health record (EHR) database?