How do you optimize a slow-running MySQL query that involves multiple joins on tables containing millions of rows?