How would you optimize a query that is running slowly due to multiple joins on large student activity tables?