Describe a scenario where a database query within an interface is running slowly. How would you troubleshoot and optimize it?