Sort, using primary key if available, use memory sort without primary key.