Unless there's an add-on involved, there should never be a situation where XF takes over 2 minutes to run a query. It's certainly not going to be the query that needs to be optimised. You are going to likely need to be looking at optimising the server/db platform itself. For this, you should contact your provider.