A query containing a Group By and an Order By clause was non-optimal. Different indexes were used to perform the Group By and Order By operations when the same index could have been used for both. Modifications in the logic address this issue and improve the performance.