Fixed potential bug where @next is not taken into account in the header join optimization