From 0404936af5b9f2cc420863f505dae6f9085440ad Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Thu, 12 Mar 2020 18:32:53 -0300
Subject: [PATCH 7/8] Test trivial condition before more complex one

---
 src/backend/executor/nodeIncrementalSort.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/backend/executor/nodeIncrementalSort.c b/src/backend/executor/nodeIncrementalSort.c
index be1afbb169..909d2df53f 100644
--- a/src/backend/executor/nodeIncrementalSort.c
+++ b/src/backend/executor/nodeIncrementalSort.c
@@ -499,9 +499,9 @@ ExecIncrementalSort(PlanState *pstate)
 		read_sortstate = node->execution_status == INCSORT_READFULLSORT ?
 			fullsort_state : node->prefixsort_state;
 		slot = node->ss.ps.ps_ResultTupleSlot;
-		if (tuplesort_gettupleslot(read_sortstate, ScanDirectionIsForward(dir),
-								   false, slot, NULL) || node->finished)
-
+		if (node->finished ||
+			tuplesort_gettupleslot(read_sortstate, ScanDirectionIsForward(dir),
+								   false, slot, NULL))
 			/*
 			 * TODO: there isn't a good test case for the node->finished case
 			 * directly, but lots of other stuff fails if it's not there. If
-- 
2.20.1

