How do you optimize a slow-running SQL query when dealing with millions of rows of media consumption data?