Simplify loop logic in nodeIncrementalSort.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 15 Feb 2021 15:17:58 +0000 (10:17 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 15 Feb 2021 15:17:58 +0000 (10:17 -0500)
commit0e5290312851557ee24e3d6103baf14d6066695c
tree2f1e7e245303a3bc4a7ff5f18d1f0dae3a4f6261
parent54e51dcde03e5c746e8de6243c69fafdc8d0ec7a
Simplify loop logic in nodeIncrementalSort.c.

The inner loop in switchToPresortedPrefixMode() can be implemented
as a conventional integer-counter for() loop, removing a couple of
redundant boolean state variables.  The old logic here was a remnant
of earlier development, but as things now stand there's no reason
for extra complexity.

Also, annotate the test case added by 82e0e2930 to explain why it
manages to hit the corner case fixed in that commit, and add an
EXPLAIN to verify that it's creating an incremental-sort plan.

Back-patch to v13, like the previous patch.

James Coleman and Tom Lane

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