I wrote:
> Hmm. Actually, given that sort_bounded_heap() is only conditionally
> invoked, *both* of the state updates it makes are bogus.
Er, make that three state updates: its REVERSEDIRECTION() operation is
being skipped as well. That's not critical now, but might be someday.
Rather than moving all that up to tuplesort_performsort, it seems better
to leave it where it is, and instead remove the premature optimization
of trying to skip sort_bounded_heap. The number of cycles saved that
way is tiny anyway...
regards, tom lane