Fix YA incremental sort bug.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 5 Feb 2021 00:12:09 +0000 (19:12 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 5 Feb 2021 00:12:09 +0000 (19:12 -0500)
commit10fcb83da6a7c5328f61ca7fb60f78c57db1bd58
treed21c9b67782c3a03efc446604dc8cb1dabfb031f
parent57868d957eb8320f924bc8453372cf9954e9a338
Fix YA incremental sort bug.

switchToPresortedPrefixMode() did the wrong thing if it detected
a batch boundary just at the last tuple of a fullsort group.

The initially-reported symptom was a "retrieved too many tuples in a
bounded sort" error, but the test case added here just silently gives
the wrong answer without this patch.

I (tgl) am not really happy about committing this patch without review
from the incremental-sort authors, but they seem AWOL and we are hard
against a release deadline.  This does demonstrably make some cases
better, anyway.

Per bug #16846 from Yoran Heling.  Back-patch to v13 where incremental
sort was introduced.

Neil Chen

Discussion: https://postgr.es/m/16846-ae49f51ac379a4cb@postgresql.org
src/backend/executor/nodeIncrementalSort.c
src/test/regress/expected/incremental_sort.out
src/test/regress/sql/incremental_sort.sql