Query taking a lot of time