Ranier Vilela <ranier...@gmail.com> writes: > It seems to me that [reversing the loop direction] is more optimized.
That's far from clear: you're ignoring the possibility that memory access logic is better optimized for forward scanning than reverse scanning. I'd stick with the forward scan without some extremely detailed testing. regards, tom lane