Vinay | Fix performance issues in query