Optimizing inmemory sort phase