Explain a time you had to optimize a slow-running query that was timing out in a production dashboard.