How do you optimize a query that is running slowly due to large table sizes and multiple complex joins?