Given a query that is taking too long to execute on a massive table, walk me through the steps you would take to optimize it.