Describe how you would optimize a slow-running query that processes millions of rows in a cloud data warehouse like Snowflake.