From b1c0f842f46943de0035e4658e641a20522951fa Mon Sep 17 00:00:00 2001
From: James Coleman <jtc331@gmail.com>
Date: Mon, 6 Apr 2020 20:38:18 -0400
Subject: [PATCH v1 1/2] Don't show worker info for sort node if no work done

In d2d8a229bc58a2014dce1c7a4fcdb6c5ab9fb8da we modified the
TuplesortMethod enum to be a bitmask. As such,
SORT_TYPE_STILL_IN_PROGRESS is now set to one. It'd previously been
explicitly set to 0, but with no comment, so that seemed reasonable.
However it seems that explain.c's show_sort_info method was using that 0
as a sentinel that the worker hadn't done any work, and thus it
shouldn't be printed (the worker's DSM is initialized to all zeros, so
this worked properly). Instead it should explicitly check for NULL.
---
 src/backend/commands/explain.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index cad10662bb..b1a20eba27 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -2717,7 +2717,8 @@ show_sort_info(SortState *sortstate, ExplainState *es)
 			long		spaceUsed;
 
 			sinstrument = &sortstate->shared_info->sinstrument[n];
-			if (sinstrument->sortMethod == SORT_TYPE_STILL_IN_PROGRESS)
+			if (sinstrument->sortMethod == SORT_TYPE_STILL_IN_PROGRESS
+				|| sinstrument->sortMethod == NULL)
 				continue;		/* ignore any unfilled slots */
 			sortMethod = tuplesort_method_name(sinstrument->sortMethod);
 			spaceType = tuplesort_space_type_name(sinstrument->spaceType);
-- 
2.17.1

