How would you optimize a query that involves multiple large joins and window functions for TikTok analytics?