Explain how you would optimize a slow-running SQL query that pulls millions of rows of telemetry data.