Attempt to make the optimizations in query