Describe a scenario where you used SQL to join multiple highly complex tables. How did you optimize the query performance?