aboutsummaryrefslogtreecommitdiff
path: root/src/include/nodes/execnodes.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-03-09 07:40:36 -0500
committerRobert Haas <rhaas@postgresql.org>2017-03-09 07:49:29 -0500
commit355d3993c53ed62c5b53d020648e4fbcfbf5f155 (patch)
tree9a439084995c6553dd035fe218d9864011192b36 /src/include/nodes/execnodes.h
parenta72f0365db4168e7d720608fe3ac0ca3fe9355df (diff)
downloadpostgresql-355d3993c53ed62c5b53d020648e4fbcfbf5f155.tar.gz
postgresql-355d3993c53ed62c5b53d020648e4fbcfbf5f155.zip
Add a Gather Merge executor node.
Like Gather, we spawn multiple workers and run the same plan in each one; however, Gather Merge is used when each worker produces the same output ordering and we want to preserve that output ordering while merging together the streams of tuples from various workers. (In a way, Gather Merge is like a hybrid of Gather and MergeAppend.) This works out to a win if it saves us from having to perform an expensive Sort. In cases where only a small amount of data would need to be sorted, it may actually be faster to use a regular Gather node and then sort the results afterward, because Gather Merge sometimes needs to wait synchronously for tuples whereas a pure Gather generally doesn't. But if this avoids an expensive sort then it's a win. Rushabh Lathia, reviewed and tested by Amit Kapila, Thomas Munro, and Neha Sharma, and reviewed and revised by me. Discussion: http://postgr.es/m/CAGPqQf09oPX-cQRpBKS0Gq49Z+m6KBxgxd_p9gX8CKk_d75HoQ@mail.gmail.com
Diffstat (limited to 'src/include/nodes/execnodes.h')
-rw-r--r--src/include/nodes/execnodes.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 6a0d590ef29..f856f6036f6 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -2095,6 +2095,35 @@ typedef struct GatherState
} GatherState;
/* ----------------
+ * GatherMergeState information
+ *
+ * Gather merge nodes launch 1 or more parallel workers, run a
+ * subplan which produces sorted output in each worker, and then
+ * merge the results into a single sorted stream.
+ * ----------------
+ */
+struct GMReaderTuple;
+
+typedef struct GatherMergeState
+{
+ PlanState ps; /* its first field is NodeTag */
+ bool initialized;
+ struct ParallelExecutorInfo *pei;
+ int nreaders;
+ int nworkers_launched;
+ struct TupleQueueReader **reader;
+ TupleDesc tupDesc;
+ TupleTableSlot **gm_slots;
+ struct binaryheap *gm_heap; /* binary heap of slot indices */
+ bool gm_initialized; /* gather merge initilized ? */
+ bool need_to_scan_locally;
+ int gm_nkeys;
+ SortSupport gm_sortkeys; /* array of length ms_nkeys */
+ struct GMReaderTupleBuffer *gm_tuple_buffers; /* tuple buffer per
+ * reader */
+} GatherMergeState;
+
+/* ----------------
* HashState information
* ----------------
*/