PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
execParallel.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * execParallel.c
4  * Support routines for parallel execution.
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * This file contains routines that are intended to support setting up,
10  * using, and tearing down a ParallelContext from within the PostgreSQL
11  * executor. The ParallelContext machinery will handle starting the
12  * workers and ensuring that their state generally matches that of the
13  * leader; see src/backend/access/transam/README.parallel for details.
14  * However, we must save and restore relevant executor state, such as
15  * any ParamListInfo associated with the query, buffer usage info, and
16  * the actual plan to be passed down to the worker.
17  *
18  * IDENTIFICATION
19  * src/backend/executor/execParallel.c
20  *
21  *-------------------------------------------------------------------------
22  */
23 
24 #include "postgres.h"
25 
26 #include "executor/execParallel.h"
27 #include "executor/executor.h"
29 #include "executor/nodeCustom.h"
31 #include "executor/nodeIndexscan.h"
33 #include "executor/nodeSeqscan.h"
34 #include "executor/nodeSort.h"
35 #include "executor/tqueue.h"
36 #include "nodes/nodeFuncs.h"
37 #include "optimizer/planmain.h"
38 #include "optimizer/planner.h"
39 #include "storage/spin.h"
40 #include "tcop/tcopprot.h"
41 #include "utils/dsa.h"
42 #include "utils/memutils.h"
43 #include "utils/snapmgr.h"
44 #include "pgstat.h"
45 
46 /*
47  * Magic numbers for parallel executor communication. We use constants
48  * greater than any 32-bit integer here so that values < 2^32 can be used
49  * by individual parallel nodes to store their own state.
50  */
51 #define PARALLEL_KEY_EXECUTOR_FIXED UINT64CONST(0xE000000000000001)
52 #define PARALLEL_KEY_PLANNEDSTMT UINT64CONST(0xE000000000000002)
53 #define PARALLEL_KEY_PARAMS UINT64CONST(0xE000000000000003)
54 #define PARALLEL_KEY_BUFFER_USAGE UINT64CONST(0xE000000000000004)
55 #define PARALLEL_KEY_TUPLE_QUEUE UINT64CONST(0xE000000000000005)
56 #define PARALLEL_KEY_INSTRUMENTATION UINT64CONST(0xE000000000000006)
57 #define PARALLEL_KEY_DSA UINT64CONST(0xE000000000000007)
58 #define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xE000000000000008)
59 
60 #define PARALLEL_TUPLE_QUEUE_SIZE 65536
61 
62 /*
63  * Fixed-size random stuff that we need to pass to parallel workers.
64  */
66 {
67  int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */
69 
70 /*
71  * DSM structure for accumulating per-PlanState instrumentation.
72  *
73  * instrument_options: Same meaning here as in instrument.c.
74  *
75  * instrument_offset: Offset, relative to the start of this structure,
76  * of the first Instrumentation object. This will depend on the length of
77  * the plan_node_id array.
78  *
79  * num_workers: Number of workers.
80  *
81  * num_plan_nodes: Number of plan nodes.
82  *
83  * plan_node_id: Array of plan nodes for which we are gathering instrumentation
84  * from parallel workers. The length of this array is given by num_plan_nodes.
85  */
87 {
92  int plan_node_id[FLEXIBLE_ARRAY_MEMBER];
93  /* array of num_plan_nodes * num_workers Instrumentation objects follows */
94 };
95 #define GetInstrumentationArray(sei) \
96  (AssertVariableIsOfTypeMacro(sei, SharedExecutorInstrumentation *), \
97  (Instrumentation *) (((char *) sei) + sei->instrument_offset))
98 
99 /* Context object for ExecParallelEstimate. */
101 {
103  int nnodes;
105 
106 /* Context object for ExecParallelInitializeDSM. */
108 {
111  int nnodes;
113 
114 /* Helper functions that run in the parallel leader. */
115 static char *ExecSerializePlan(Plan *plan, EState *estate);
116 static bool ExecParallelEstimate(PlanState *node,
118 static bool ExecParallelInitializeDSM(PlanState *node,
121  bool reinitialize);
122 static bool ExecParallelReInitializeDSM(PlanState *planstate,
123  ParallelContext *pcxt);
124 static bool ExecParallelRetrieveInstrumentation(PlanState *planstate,
125  SharedExecutorInstrumentation *instrumentation);
126 
127 /* Helper function that runs in the parallel worker. */
129 
130 /*
131  * Create a serialized representation of the plan to be sent to each worker.
132  */
133 static char *
135 {
136  PlannedStmt *pstmt;
137  ListCell *lc;
138 
139  /* We can't scribble on the original plan, so make a copy. */
140  plan = copyObject(plan);
141 
142  /*
143  * The worker will start its own copy of the executor, and that copy will
144  * insert a junk filter if the toplevel node has any resjunk entries. We
145  * don't want that to happen, because while resjunk columns shouldn't be
146  * sent back to the user, here the tuples are coming back to another
147  * backend which may very well need them. So mutate the target list
148  * accordingly. This is sort of a hack; there might be better ways to do
149  * this...
150  */
151  foreach(lc, plan->targetlist)
152  {
153  TargetEntry *tle = lfirst_node(TargetEntry, lc);
154 
155  tle->resjunk = false;
156  }
157 
158  /*
159  * Create a dummy PlannedStmt. Most of the fields don't need to be valid
160  * for our purposes, but the worker will need at least a minimal
161  * PlannedStmt to start the executor.
162  */
163  pstmt = makeNode(PlannedStmt);
164  pstmt->commandType = CMD_SELECT;
165  pstmt->queryId = 0;
166  pstmt->hasReturning = false;
167  pstmt->hasModifyingCTE = false;
168  pstmt->canSetTag = true;
169  pstmt->transientPlan = false;
170  pstmt->dependsOnRole = false;
171  pstmt->parallelModeNeeded = false;
172  pstmt->planTree = plan;
173  pstmt->rtable = estate->es_range_table;
174  pstmt->resultRelations = NIL;
175  pstmt->nonleafResultRelations = NIL;
176 
177  /*
178  * Transfer only parallel-safe subplans, leaving a NULL "hole" in the list
179  * for unsafe ones (so that the list indexes of the safe ones are
180  * preserved). This positively ensures that the worker won't try to run,
181  * or even do ExecInitNode on, an unsafe subplan. That's important to
182  * protect, eg, non-parallel-aware FDWs from getting into trouble.
183  */
184  pstmt->subplans = NIL;
185  foreach(lc, estate->es_plannedstmt->subplans)
186  {
187  Plan *subplan = (Plan *) lfirst(lc);
188 
189  if (subplan && !subplan->parallel_safe)
190  subplan = NULL;
191  pstmt->subplans = lappend(pstmt->subplans, subplan);
192  }
193 
194  pstmt->rewindPlanIDs = NULL;
195  pstmt->rowMarks = NIL;
196  pstmt->relationOids = NIL;
197  pstmt->invalItems = NIL; /* workers can't replan anyway... */
198  pstmt->nParamExec = estate->es_plannedstmt->nParamExec;
199  pstmt->utilityStmt = NULL;
200  pstmt->stmt_location = -1;
201  pstmt->stmt_len = -1;
202 
203  /* Return serialized copy of our dummy PlannedStmt. */
204  return nodeToString(pstmt);
205 }
206 
207 /*
208  * Parallel-aware plan nodes (and occasionally others) may need some state
209  * which is shared across all parallel workers. Before we size the DSM, give
210  * them a chance to call shm_toc_estimate_chunk or shm_toc_estimate_keys on
211  * &pcxt->estimator.
212  *
213  * While we're at it, count the number of PlanState nodes in the tree, so
214  * we know how many SharedPlanStateInstrumentation structures we need.
215  */
216 static bool
218 {
219  if (planstate == NULL)
220  return false;
221 
222  /* Count this node. */
223  e->nnodes++;
224 
225  switch (nodeTag(planstate))
226  {
227  case T_SeqScanState:
228  if (planstate->plan->parallel_aware)
229  ExecSeqScanEstimate((SeqScanState *) planstate,
230  e->pcxt);
231  break;
232  case T_IndexScanState:
233  if (planstate->plan->parallel_aware)
235  e->pcxt);
236  break;
238  if (planstate->plan->parallel_aware)
240  e->pcxt);
241  break;
242  case T_ForeignScanState:
243  if (planstate->plan->parallel_aware)
245  e->pcxt);
246  break;
247  case T_CustomScanState:
248  if (planstate->plan->parallel_aware)
250  e->pcxt);
251  break;
253  if (planstate->plan->parallel_aware)
255  e->pcxt);
256  break;
257  case T_SortState:
258  /* even when not parallel-aware */
259  ExecSortEstimate((SortState *) planstate, e->pcxt);
260  break;
261 
262  default:
263  break;
264  }
265 
266  return planstate_tree_walker(planstate, ExecParallelEstimate, e);
267 }
268 
269 /*
270  * Initialize the dynamic shared memory segment that will be used to control
271  * parallel execution.
272  */
273 static bool
276 {
277  if (planstate == NULL)
278  return false;
279 
280  /* If instrumentation is enabled, initialize slot for this node. */
281  if (d->instrumentation != NULL)
283  planstate->plan->plan_node_id;
284 
285  /* Count this node. */
286  d->nnodes++;
287 
288  /*
289  * Call initializers for DSM-using plan nodes.
290  *
291  * Most plan nodes won't do anything here, but plan nodes that allocated
292  * DSM may need to initialize shared state in the DSM before parallel
293  * workers are launched. They can allocate the space they previously
294  * estimated using shm_toc_allocate, and add the keys they previously
295  * estimated using shm_toc_insert, in each case targeting pcxt->toc.
296  */
297  switch (nodeTag(planstate))
298  {
299  case T_SeqScanState:
300  if (planstate->plan->parallel_aware)
302  d->pcxt);
303  break;
304  case T_IndexScanState:
305  if (planstate->plan->parallel_aware)
307  d->pcxt);
308  break;
310  if (planstate->plan->parallel_aware)
312  d->pcxt);
313  break;
314  case T_ForeignScanState:
315  if (planstate->plan->parallel_aware)
317  d->pcxt);
318  break;
319  case T_CustomScanState:
320  if (planstate->plan->parallel_aware)
322  d->pcxt);
323  break;
325  if (planstate->plan->parallel_aware)
327  d->pcxt);
328  break;
329  case T_SortState:
330  /* even when not parallel-aware */
331  ExecSortInitializeDSM((SortState *) planstate, d->pcxt);
332  break;
333 
334  default:
335  break;
336  }
337 
338  return planstate_tree_walker(planstate, ExecParallelInitializeDSM, d);
339 }
340 
341 /*
342  * It sets up the response queues for backend workers to return tuples
343  * to the main backend and start the workers.
344  */
345 static shm_mq_handle **
347 {
348  shm_mq_handle **responseq;
349  char *tqueuespace;
350  int i;
351 
352  /* Skip this if no workers. */
353  if (pcxt->nworkers == 0)
354  return NULL;
355 
356  /* Allocate memory for shared memory queue handles. */
357  responseq = (shm_mq_handle **)
358  palloc(pcxt->nworkers * sizeof(shm_mq_handle *));
359 
360  /*
361  * If not reinitializing, allocate space from the DSM for the queues;
362  * otherwise, find the already allocated space.
363  */
364  if (!reinitialize)
365  tqueuespace =
366  shm_toc_allocate(pcxt->toc,
368  pcxt->nworkers));
369  else
370  tqueuespace = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, false);
371 
372  /* Create the queues, and become the receiver for each. */
373  for (i = 0; i < pcxt->nworkers; ++i)
374  {
375  shm_mq *mq;
376 
377  mq = shm_mq_create(tqueuespace +
379  (Size) PARALLEL_TUPLE_QUEUE_SIZE);
380 
382  responseq[i] = shm_mq_attach(mq, pcxt->seg, NULL);
383  }
384 
385  /* Add array of queues to shm_toc, so others can find it. */
386  if (!reinitialize)
387  shm_toc_insert(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, tqueuespace);
388 
389  /* Return array of handles. */
390  return responseq;
391 }
392 
393 /*
394  * Sets up the required infrastructure for backend workers to perform
395  * execution and return results to the main backend.
396  */
398 ExecInitParallelPlan(PlanState *planstate, EState *estate, int nworkers,
399  int64 tuples_needed)
400 {
402  ParallelContext *pcxt;
406  char *pstmt_data;
407  char *pstmt_space;
408  char *param_space;
409  BufferUsage *bufusage_space;
410  SharedExecutorInstrumentation *instrumentation = NULL;
411  int pstmt_len;
412  int param_len;
413  int instrumentation_len = 0;
414  int instrument_offset = 0;
415  Size dsa_minsize = dsa_minimum_size();
416  char *query_string;
417  int query_len;
418 
419  /* Allocate object for return value. */
420  pei = palloc0(sizeof(ParallelExecutorInfo));
421  pei->finished = false;
422  pei->planstate = planstate;
423 
424  /* Fix up and serialize plan to be sent to workers. */
425  pstmt_data = ExecSerializePlan(planstate->plan, estate);
426 
427  /* Create a parallel context. */
428  pcxt = CreateParallelContext("postgres", "ParallelQueryMain", nworkers);
429  pei->pcxt = pcxt;
430 
431  /*
432  * Before telling the parallel context to create a dynamic shared memory
433  * segment, we need to figure out how big it should be. Estimate space
434  * for the various things we need to store.
435  */
436 
437  /* Estimate space for fixed-size state. */
440  shm_toc_estimate_keys(&pcxt->estimator, 1);
441 
442  /* Estimate space for query text. */
443  query_len = strlen(estate->es_sourceText);
444  shm_toc_estimate_chunk(&pcxt->estimator, query_len);
445  shm_toc_estimate_keys(&pcxt->estimator, 1);
446 
447  /* Estimate space for serialized PlannedStmt. */
448  pstmt_len = strlen(pstmt_data) + 1;
449  shm_toc_estimate_chunk(&pcxt->estimator, pstmt_len);
450  shm_toc_estimate_keys(&pcxt->estimator, 1);
451 
452  /* Estimate space for serialized ParamListInfo. */
453  param_len = EstimateParamListSpace(estate->es_param_list_info);
454  shm_toc_estimate_chunk(&pcxt->estimator, param_len);
455  shm_toc_estimate_keys(&pcxt->estimator, 1);
456 
457  /*
458  * Estimate space for BufferUsage.
459  *
460  * If EXPLAIN is not in use and there are no extensions loaded that care,
461  * we could skip this. But we have no way of knowing whether anyone's
462  * looking at pgBufferUsage, so do it unconditionally.
463  */
465  mul_size(sizeof(BufferUsage), pcxt->nworkers));
466  shm_toc_estimate_keys(&pcxt->estimator, 1);
467 
468  /* Estimate space for tuple queues. */
471  shm_toc_estimate_keys(&pcxt->estimator, 1);
472 
473  /*
474  * Give parallel-aware nodes a chance to add to the estimates, and get a
475  * count of how many PlanState nodes there are.
476  */
477  e.pcxt = pcxt;
478  e.nnodes = 0;
479  ExecParallelEstimate(planstate, &e);
480 
481  /* Estimate space for instrumentation, if required. */
482  if (estate->es_instrument)
483  {
484  instrumentation_len =
485  offsetof(SharedExecutorInstrumentation, plan_node_id) +
486  sizeof(int) * e.nnodes;
487  instrumentation_len = MAXALIGN(instrumentation_len);
488  instrument_offset = instrumentation_len;
489  instrumentation_len +=
490  mul_size(sizeof(Instrumentation),
491  mul_size(e.nnodes, nworkers));
492  shm_toc_estimate_chunk(&pcxt->estimator, instrumentation_len);
493  shm_toc_estimate_keys(&pcxt->estimator, 1);
494  }
495 
496  /* Estimate space for DSA area. */
497  shm_toc_estimate_chunk(&pcxt->estimator, dsa_minsize);
498  shm_toc_estimate_keys(&pcxt->estimator, 1);
499 
500  /* Everyone's had a chance to ask for space, so now create the DSM. */
501  InitializeParallelDSM(pcxt);
502 
503  /*
504  * OK, now we have a dynamic shared memory segment, and it should be big
505  * enough to store all of the data we estimated we would want to put into
506  * it, plus whatever general stuff (not specifically executor-related) the
507  * ParallelContext itself needs to store there. None of the space we
508  * asked for has been allocated or initialized yet, though, so do that.
509  */
510 
511  /* Store fixed-size state. */
512  fpes = shm_toc_allocate(pcxt->toc, sizeof(FixedParallelExecutorState));
513  fpes->tuples_needed = tuples_needed;
515 
516  /* Store query string */
517  query_string = shm_toc_allocate(pcxt->toc, query_len);
518  memcpy(query_string, estate->es_sourceText, query_len);
519  shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, query_string);
520 
521  /* Store serialized PlannedStmt. */
522  pstmt_space = shm_toc_allocate(pcxt->toc, pstmt_len);
523  memcpy(pstmt_space, pstmt_data, pstmt_len);
524  shm_toc_insert(pcxt->toc, PARALLEL_KEY_PLANNEDSTMT, pstmt_space);
525 
526  /* Store serialized ParamListInfo. */
527  param_space = shm_toc_allocate(pcxt->toc, param_len);
528  shm_toc_insert(pcxt->toc, PARALLEL_KEY_PARAMS, param_space);
529  SerializeParamList(estate->es_param_list_info, &param_space);
530 
531  /* Allocate space for each worker's BufferUsage; no need to initialize. */
532  bufusage_space = shm_toc_allocate(pcxt->toc,
533  mul_size(sizeof(BufferUsage), pcxt->nworkers));
534  shm_toc_insert(pcxt->toc, PARALLEL_KEY_BUFFER_USAGE, bufusage_space);
535  pei->buffer_usage = bufusage_space;
536 
537  /* Set up the tuple queues that the workers will write into. */
538  pei->tqueue = ExecParallelSetupTupleQueues(pcxt, false);
539 
540  /* We don't need the TupleQueueReaders yet, though. */
541  pei->reader = NULL;
542 
543  /*
544  * If instrumentation options were supplied, allocate space for the data.
545  * It only gets partially initialized here; the rest happens during
546  * ExecParallelInitializeDSM.
547  */
548  if (estate->es_instrument)
549  {
550  Instrumentation *instrument;
551  int i;
552 
553  instrumentation = shm_toc_allocate(pcxt->toc, instrumentation_len);
554  instrumentation->instrument_options = estate->es_instrument;
555  instrumentation->instrument_offset = instrument_offset;
556  instrumentation->num_workers = nworkers;
557  instrumentation->num_plan_nodes = e.nnodes;
558  instrument = GetInstrumentationArray(instrumentation);
559  for (i = 0; i < nworkers * e.nnodes; ++i)
560  InstrInit(&instrument[i], estate->es_instrument);
562  instrumentation);
563  pei->instrumentation = instrumentation;
564  }
565 
566  /*
567  * Create a DSA area that can be used by the leader and all workers.
568  * (However, if we failed to create a DSM and are using private memory
569  * instead, then skip this.)
570  */
571  if (pcxt->seg != NULL)
572  {
573  char *area_space;
574 
575  area_space = shm_toc_allocate(pcxt->toc, dsa_minsize);
576  shm_toc_insert(pcxt->toc, PARALLEL_KEY_DSA, area_space);
577  pei->area = dsa_create_in_place(area_space, dsa_minsize,
579  pcxt->seg);
580  }
581 
582  /*
583  * Make the area available to executor nodes running in the leader. See
584  * also ParallelQueryMain which makes it available to workers.
585  */
586  estate->es_query_dsa = pei->area;
587 
588  /*
589  * Give parallel-aware nodes a chance to initialize their shared data.
590  * This also initializes the elements of instrumentation->ps_instrument,
591  * if it exists.
592  */
593  d.pcxt = pcxt;
594  d.instrumentation = instrumentation;
595  d.nnodes = 0;
596  ExecParallelInitializeDSM(planstate, &d);
597 
598  /*
599  * Make sure that the world hasn't shifted under our feet. This could
600  * probably just be an Assert(), but let's be conservative for now.
601  */
602  if (e.nnodes != d.nnodes)
603  elog(ERROR, "inconsistent count of PlanState nodes");
604 
605  /* OK, we're ready to rock and roll. */
606  return pei;
607 }
608 
609 /*
610  * Set up tuple queue readers to read the results of a parallel subplan.
611  *
612  * This is separate from ExecInitParallelPlan() because we can launch the
613  * worker processes and let them start doing something before we do this.
614  */
615 void
617 {
618  int nworkers = pei->pcxt->nworkers_launched;
619  int i;
620 
621  Assert(pei->reader == NULL);
622 
623  if (nworkers > 0)
624  {
625  pei->reader = (TupleQueueReader **)
626  palloc(nworkers * sizeof(TupleQueueReader *));
627 
628  for (i = 0; i < nworkers; i++)
629  {
630  shm_mq_set_handle(pei->tqueue[i],
631  pei->pcxt->worker[i].bgwhandle);
632  pei->reader[i] = CreateTupleQueueReader(pei->tqueue[i]);
633  }
634  }
635 }
636 
637 /*
638  * Re-initialize the parallel executor shared memory state before launching
639  * a fresh batch of workers.
640  */
641 void
644 {
645  /* Old workers must already be shut down */
646  Assert(pei->finished);
647 
649  pei->tqueue = ExecParallelSetupTupleQueues(pei->pcxt, true);
650  pei->reader = NULL;
651  pei->finished = false;
652 
653  /* Traverse plan tree and let each child node reset associated state. */
654  ExecParallelReInitializeDSM(planstate, pei->pcxt);
655 }
656 
657 /*
658  * Traverse plan tree to reinitialize per-node dynamic shared memory state
659  */
660 static bool
662  ParallelContext *pcxt)
663 {
664  if (planstate == NULL)
665  return false;
666 
667  /*
668  * Call reinitializers for DSM-using plan nodes.
669  */
670  switch (nodeTag(planstate))
671  {
672  case T_SeqScanState:
673  if (planstate->plan->parallel_aware)
675  pcxt);
676  break;
677  case T_IndexScanState:
678  if (planstate->plan->parallel_aware)
680  pcxt);
681  break;
683  if (planstate->plan->parallel_aware)
685  pcxt);
686  break;
687  case T_ForeignScanState:
688  if (planstate->plan->parallel_aware)
690  pcxt);
691  break;
692  case T_CustomScanState:
693  if (planstate->plan->parallel_aware)
695  pcxt);
696  break;
698  if (planstate->plan->parallel_aware)
700  pcxt);
701  break;
702  case T_SortState:
703  /* even when not parallel-aware */
704  ExecSortReInitializeDSM((SortState *) planstate, pcxt);
705  break;
706 
707  default:
708  break;
709  }
710 
711  return planstate_tree_walker(planstate, ExecParallelReInitializeDSM, pcxt);
712 }
713 
714 /*
715  * Copy instrumentation information about this node and its descendants from
716  * dynamic shared memory.
717  */
718 static bool
720  SharedExecutorInstrumentation *instrumentation)
721 {
722  Instrumentation *instrument;
723  int i;
724  int n;
725  int ibytes;
726  int plan_node_id = planstate->plan->plan_node_id;
727  MemoryContext oldcontext;
728 
729  /* Find the instrumentation for this node. */
730  for (i = 0; i < instrumentation->num_plan_nodes; ++i)
731  if (instrumentation->plan_node_id[i] == plan_node_id)
732  break;
733  if (i >= instrumentation->num_plan_nodes)
734  elog(ERROR, "plan node %d not found", plan_node_id);
735 
736  /* Accumulate the statistics from all workers. */
737  instrument = GetInstrumentationArray(instrumentation);
738  instrument += i * instrumentation->num_workers;
739  for (n = 0; n < instrumentation->num_workers; ++n)
740  InstrAggNode(planstate->instrument, &instrument[n]);
741 
742  /*
743  * Also store the per-worker detail.
744  *
745  * Worker instrumentation should be allocated in the same context as the
746  * regular instrumentation information, which is the per-query context.
747  * Switch into per-query memory context.
748  */
749  oldcontext = MemoryContextSwitchTo(planstate->state->es_query_cxt);
750  ibytes = mul_size(instrumentation->num_workers, sizeof(Instrumentation));
751  planstate->worker_instrument =
752  palloc(ibytes + offsetof(WorkerInstrumentation, instrument));
753  MemoryContextSwitchTo(oldcontext);
754 
755  planstate->worker_instrument->num_workers = instrumentation->num_workers;
756  memcpy(&planstate->worker_instrument->instrument, instrument, ibytes);
757 
758  /*
759  * Perform any node-type-specific work that needs to be done. Currently,
760  * only Sort nodes need to do anything here.
761  */
762  if (IsA(planstate, SortState))
764 
766  instrumentation);
767 }
768 
769 /*
770  * Finish parallel execution. We wait for parallel workers to finish, and
771  * accumulate their buffer usage and instrumentation.
772  */
773 void
775 {
776  int nworkers = pei->pcxt->nworkers_launched;
777  int i;
778 
779  /* Make this be a no-op if called twice in a row. */
780  if (pei->finished)
781  return;
782 
783  /*
784  * Detach from tuple queues ASAP, so that any still-active workers will
785  * notice that no further results are wanted.
786  */
787  if (pei->tqueue != NULL)
788  {
789  for (i = 0; i < nworkers; i++)
790  shm_mq_detach(pei->tqueue[i]);
791  pfree(pei->tqueue);
792  pei->tqueue = NULL;
793  }
794 
795  /*
796  * While we're waiting for the workers to finish, let's get rid of the
797  * tuple queue readers. (Any other local cleanup could be done here too.)
798  */
799  if (pei->reader != NULL)
800  {
801  for (i = 0; i < nworkers; i++)
803  pfree(pei->reader);
804  pei->reader = NULL;
805  }
806 
807  /* Now wait for the workers to finish. */
809 
810  /*
811  * Next, accumulate buffer usage. (This must wait for the workers to
812  * finish, or we might get incomplete data.)
813  */
814  for (i = 0; i < nworkers; i++)
816 
817  /* Finally, accumulate instrumentation, if any. */
818  if (pei->instrumentation)
820  pei->instrumentation);
821 
822  pei->finished = true;
823 }
824 
825 /*
826  * Clean up whatever ParallelExecutorInfo resources still exist after
827  * ExecParallelFinish. We separate these routines because someone might
828  * want to examine the contents of the DSM after ExecParallelFinish and
829  * before calling this routine.
830  */
831 void
833 {
834  if (pei->area != NULL)
835  {
836  dsa_detach(pei->area);
837  pei->area = NULL;
838  }
839  if (pei->pcxt != NULL)
840  {
842  pei->pcxt = NULL;
843  }
844  pfree(pei);
845 }
846 
847 /*
848  * Create a DestReceiver to write tuples we produce to the shm_mq designated
849  * for that purpose.
850  */
851 static DestReceiver *
853 {
854  char *mqspace;
855  shm_mq *mq;
856 
857  mqspace = shm_toc_lookup(toc, PARALLEL_KEY_TUPLE_QUEUE, false);
859  mq = (shm_mq *) mqspace;
861  return CreateTupleQueueDestReceiver(shm_mq_attach(mq, seg, NULL));
862 }
863 
864 /*
865  * Create a QueryDesc for the PlannedStmt we are to execute, and return it.
866  */
867 static QueryDesc *
869  int instrument_options)
870 {
871  char *pstmtspace;
872  char *paramspace;
873  PlannedStmt *pstmt;
874  ParamListInfo paramLI;
875  char *queryString;
876 
877  /* Get the query string from shared memory */
878  queryString = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, false);
879 
880  /* Reconstruct leader-supplied PlannedStmt. */
881  pstmtspace = shm_toc_lookup(toc, PARALLEL_KEY_PLANNEDSTMT, false);
882  pstmt = (PlannedStmt *) stringToNode(pstmtspace);
883 
884  /* Reconstruct ParamListInfo. */
885  paramspace = shm_toc_lookup(toc, PARALLEL_KEY_PARAMS, false);
886  paramLI = RestoreParamList(&paramspace);
887 
888  /*
889  * Create a QueryDesc for the query.
890  *
891  * It's not obvious how to obtain the query string from here; and even if
892  * we could copying it would take more cycles than not copying it. But
893  * it's a bit unsatisfying to just use a dummy string here, so consider
894  * revising this someday.
895  */
896  return CreateQueryDesc(pstmt,
897  queryString,
899  receiver, paramLI, NULL, instrument_options);
900 }
901 
902 /*
903  * Copy instrumentation information from this node and its descendants into
904  * dynamic shared memory, so that the parallel leader can retrieve it.
905  */
906 static bool
908  SharedExecutorInstrumentation *instrumentation)
909 {
910  int i;
911  int plan_node_id = planstate->plan->plan_node_id;
912  Instrumentation *instrument;
913 
914  InstrEndLoop(planstate->instrument);
915 
916  /*
917  * If we shuffled the plan_node_id values in ps_instrument into sorted
918  * order, we could use binary search here. This might matter someday if
919  * we're pushing down sufficiently large plan trees. For now, do it the
920  * slow, dumb way.
921  */
922  for (i = 0; i < instrumentation->num_plan_nodes; ++i)
923  if (instrumentation->plan_node_id[i] == plan_node_id)
924  break;
925  if (i >= instrumentation->num_plan_nodes)
926  elog(ERROR, "plan node %d not found", plan_node_id);
927 
928  /*
929  * Add our statistics to the per-node, per-worker totals. It's possible
930  * that this could happen more than once if we relaunched workers.
931  */
932  instrument = GetInstrumentationArray(instrumentation);
933  instrument += i * instrumentation->num_workers;
935  Assert(ParallelWorkerNumber < instrumentation->num_workers);
936  InstrAggNode(&instrument[ParallelWorkerNumber], planstate->instrument);
937 
939  instrumentation);
940 }
941 
942 /*
943  * Initialize the PlanState and its descendants with the information
944  * retrieved from shared memory. This has to be done once the PlanState
945  * is allocated and initialized by executor; that is, after ExecutorStart().
946  */
947 static bool
949 {
950  if (planstate == NULL)
951  return false;
952 
953  switch (nodeTag(planstate))
954  {
955  case T_SeqScanState:
956  if (planstate->plan->parallel_aware)
957  ExecSeqScanInitializeWorker((SeqScanState *) planstate, toc);
958  break;
959  case T_IndexScanState:
960  if (planstate->plan->parallel_aware)
961  ExecIndexScanInitializeWorker((IndexScanState *) planstate, toc);
962  break;
964  if (planstate->plan->parallel_aware)
966  break;
967  case T_ForeignScanState:
968  if (planstate->plan->parallel_aware)
970  toc);
971  break;
972  case T_CustomScanState:
973  if (planstate->plan->parallel_aware)
975  toc);
976  break;
978  if (planstate->plan->parallel_aware)
980  break;
981  case T_SortState:
982  /* even when not parallel-aware */
983  ExecSortInitializeWorker((SortState *) planstate, toc);
984  break;
985 
986  default:
987  break;
988  }
989 
990  return planstate_tree_walker(planstate, ExecParallelInitializeWorker, toc);
991 }
992 
993 /*
994  * Main entrypoint for parallel query worker processes.
995  *
996  * We reach this function from ParallelWorkerMain, so the setup necessary to
997  * create a sensible parallel environment has already been done;
998  * ParallelWorkerMain worries about stuff like the transaction state, combo
999  * CID mappings, and GUC values, so we don't need to deal with any of that
1000  * here.
1001  *
1002  * Our job is to deal with concerns specific to the executor. The parallel
1003  * group leader will have stored a serialized PlannedStmt, and it's our job
1004  * to execute that plan and write the resulting tuples to the appropriate
1005  * tuple queue. Various bits of supporting information that we need in order
1006  * to do this are also stored in the dsm_segment and can be accessed through
1007  * the shm_toc.
1008  */
1009 void
1011 {
1013  BufferUsage *buffer_usage;
1014  DestReceiver *receiver;
1015  QueryDesc *queryDesc;
1016  SharedExecutorInstrumentation *instrumentation;
1017  int instrument_options = 0;
1018  void *area_space;
1019  dsa_area *area;
1020 
1021  /* Get fixed-size state. */
1022  fpes = shm_toc_lookup(toc, PARALLEL_KEY_EXECUTOR_FIXED, false);
1023 
1024  /* Set up DestReceiver, SharedExecutorInstrumentation, and QueryDesc. */
1025  receiver = ExecParallelGetReceiver(seg, toc);
1026  instrumentation = shm_toc_lookup(toc, PARALLEL_KEY_INSTRUMENTATION, true);
1027  if (instrumentation != NULL)
1028  instrument_options = instrumentation->instrument_options;
1029  queryDesc = ExecParallelGetQueryDesc(toc, receiver, instrument_options);
1030 
1031  /* Setting debug_query_string for individual workers */
1032  debug_query_string = queryDesc->sourceText;
1033 
1034  /* Report workers' query for monitoring purposes */
1036 
1037  /* Prepare to track buffer usage during query execution. */
1039 
1040  /* Attach to the dynamic shared memory area. */
1041  area_space = shm_toc_lookup(toc, PARALLEL_KEY_DSA, false);
1042  area = dsa_attach_in_place(area_space, seg);
1043 
1044  /* Start up the executor */
1045  ExecutorStart(queryDesc, 0);
1046 
1047  /* Special executor initialization steps for parallel workers */
1048  queryDesc->planstate->state->es_query_dsa = area;
1049  ExecParallelInitializeWorker(queryDesc->planstate, toc);
1050 
1051  /* Pass down any tuple bound */
1052  ExecSetTupleBound(fpes->tuples_needed, queryDesc->planstate);
1053 
1054  /*
1055  * Run the plan. If we specified a tuple bound, be careful not to demand
1056  * more tuples than that.
1057  */
1058  ExecutorRun(queryDesc,
1060  fpes->tuples_needed < 0 ? (int64) 0 : fpes->tuples_needed,
1061  true);
1062 
1063  /* Shut down the executor */
1064  ExecutorFinish(queryDesc);
1065 
1066  /* Report buffer usage during parallel execution. */
1067  buffer_usage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
1069 
1070  /* Report instrumentation data if any instrumentation options are set. */
1071  if (instrumentation != NULL)
1073  instrumentation);
1074 
1075  /* Must do this after capturing instrumentation. */
1076  ExecutorEnd(queryDesc);
1077 
1078  /* Cleanup. */
1079  dsa_detach(area);
1080  FreeQueryDesc(queryDesc);
1081  receiver->rDestroy(receiver);
1082 }
void ExecIndexScanInitializeWorker(IndexScanState *node, shm_toc *toc)
bool dependsOnRole
Definition: plannodes.h:57
void ExecSeqScanInitializeWorker(SeqScanState *node, shm_toc *toc)
Definition: nodeSeqscan.c:350
#define NIL
Definition: pg_list.h:69
void ExecIndexScanInitializeDSM(IndexScanState *node, ParallelContext *pcxt)
struct dsa_area * es_query_dsa
Definition: execnodes.h:511
void * stringToNode(char *str)
Definition: read.c:38
void(* rDestroy)(DestReceiver *self)
Definition: dest.h:126
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
ParallelContext * pcxt
Definition: execParallel.h:27
void DestroyTupleQueueReader(TupleQueueReader *reader)
Definition: tqueue.c:151
void ExecParallelReinitialize(PlanState *planstate, ParallelExecutorInfo *pei)
Definition: execParallel.c:642
uint32 queryId
Definition: plannodes.h:47
WorkerInstrumentation * worker_instrument
Definition: execnodes.h:858
struct ExecParallelEstimateContext ExecParallelEstimateContext
int plan_node_id[FLEXIBLE_ARRAY_MEMBER]
Definition: execParallel.c:92
Instrumentation * instrument
Definition: execnodes.h:857
void ExecSortInitializeWorker(SortState *node, shm_toc *toc)
Definition: nodeSort.c:423
void ExecIndexOnlyScanInitializeWorker(IndexOnlyScanState *node, shm_toc *toc)
ParallelContext * CreateParallelContext(const char *library_name, const char *function_name, int nworkers)
Definition: parallel.c:140
void ExecSortEstimate(SortState *node, ParallelContext *pcxt)
Definition: nodeSort.c:360
void ExecParallelFinish(ParallelExecutorInfo *pei)
Definition: execParallel.c:774
#define PARALLEL_KEY_TUPLE_QUEUE
Definition: execParallel.c:55
void ExecCustomScanReInitializeDSM(CustomScanState *node, ParallelContext *pcxt)
Definition: nodeCustom.c:198
List * nonleafResultRelations
Definition: plannodes.h:72
void FreeQueryDesc(QueryDesc *qdesc)
Definition: pquery.c:105
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:2994
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:775
PGPROC * MyProc
Definition: proc.c:67
void InstrAggNode(Instrumentation *dst, Instrumentation *add)
Definition: instrument.c:143
dsm_segment * seg
Definition: parallel.h:42
static bool ExecParallelReportInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
Definition: execParallel.c:907
void ExecCustomScanInitializeWorker(CustomScanState *node, shm_toc *toc)
Definition: nodeCustom.c:213
List * relationOids
Definition: plannodes.h:88
shm_toc_estimator estimator
Definition: parallel.h:41
void ExecutorStart(QueryDesc *queryDesc, int eflags)
Definition: execMain.c:147
dsa_area * dsa_attach_in_place(void *place, dsm_segment *segment)
Definition: dsa.c:540
int plan_node_id
Definition: plannodes.h:143
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:839
PlannedStmt * es_plannedstmt
Definition: execnodes.h:432
PlanState * planstate
Definition: execParallel.h:26
void InstrEndParallelQuery(BufferUsage *result)
Definition: instrument.c:177
static char * ExecSerializePlan(Plan *plan, EState *estate)
Definition: execParallel.c:134
void ExecIndexScanReInitializeDSM(IndexScanState *node, ParallelContext *pcxt)
static shm_mq_handle ** ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize)
Definition: execParallel.c:346
EState * state
Definition: execnodes.h:849
List * es_range_table
Definition: execnodes.h:431
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
bool transientPlan
Definition: plannodes.h:55
Size EstimateParamListSpace(ParamListInfo paramLI)
Definition: params.c:95
int stmt_len
Definition: plannodes.h:98
static bool ExecParallelReInitializeDSM(PlanState *planstate, ParallelContext *pcxt)
Definition: execParallel.c:661
void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node)
Definition: execProcnode.c:778
struct Plan * planTree
Definition: plannodes.h:61
List * invalItems
Definition: plannodes.h:90
void ExecForeignScanReInitializeDSM(ForeignScanState *node, ParallelContext *pcxt)
void InstrEndLoop(Instrumentation *instr)
Definition: instrument.c:114
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.c:110
void ExecutorEnd(QueryDesc *queryDesc)
Definition: execMain.c:461
ParallelContext * pcxt
Definition: execParallel.c:102
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition: parallel.c:533
#define PARALLEL_KEY_INSTRUMENTATION
Definition: execParallel.c:56
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:623
const char * es_sourceText
Definition: execnodes.h:433
void ExecSortInitializeDSM(SortState *node, ParallelContext *pcxt)
Definition: nodeSort.c:381
ParallelWorkerInfo * worker
Definition: parallel.h:45
int nParamExec
Definition: plannodes.h:92
void pfree(void *pointer)
Definition: mcxt.c:949
MemoryContext es_query_cxt
Definition: execnodes.h:471
void ExecSeqScanInitializeDSM(SeqScanState *node, ParallelContext *pcxt)
Definition: nodeSeqscan.c:313
static bool ExecParallelInitializeDSM(PlanState *node, ExecParallelInitializeDSMContext *d)
Definition: execParallel.c:274
bool resjunk
Definition: primnodes.h:1375
#define ERROR
Definition: elog.h:43
PlanState * planstate
Definition: execdesc.h:49
void ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
void ExecBitmapHeapInitializeDSM(BitmapHeapScanState *node, ParallelContext *pcxt)
BufferUsage * buffer_usage
Definition: execParallel.h:28
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
Definition: execMain.c:299
void ExecIndexOnlyScanEstimate(IndexOnlyScanState *node, ParallelContext *pcxt)
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options)
Definition: pquery.c:67
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:170
#define lfirst_node(type, lc)
Definition: pg_list.h:109
void ExecParallelCreateReaders(ParallelExecutorInfo *pei)
Definition: execParallel.c:616
#define PARALLEL_KEY_PLANNEDSTMT
Definition: execParallel.c:52
ParamListInfo RestoreParamList(char **start_address)
Definition: params.c:224
int stmt_location
Definition: plannodes.h:97
static bool ExecParallelRetrieveInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
Definition: execParallel.c:719
bool hasReturning
Definition: plannodes.h:49
struct TupleQueueReader ** reader
Definition: execParallel.h:34
struct ExecParallelInitializeDSMContext ExecParallelInitializeDSMContext
void dsa_detach(dsa_area *area)
Definition: dsa.c:1884
void ExecForeignScanInitializeWorker(ForeignScanState *node, shm_toc *toc)
Node * utilityStmt
Definition: plannodes.h:94
void ExecSortReInitializeDSM(SortState *node, ParallelContext *pcxt)
Definition: nodeSort.c:406
int ParallelWorkerNumber
Definition: parallel.c:98
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
static bool ExecParallelInitializeWorker(PlanState *planstate, shm_toc *toc)
Definition: execParallel.c:948
bool parallel_aware
Definition: plannodes.h:137
#define PARALLEL_TUPLE_QUEUE_SIZE
Definition: execParallel.c:60
void InstrAccumParallelQuery(BufferUsage *result)
Definition: instrument.c:185
int es_instrument
Definition: execnodes.h:481
int nworkers_launched
Definition: parallel.h:37
#define PARALLEL_KEY_EXECUTOR_FIXED
Definition: execParallel.c:51
static bool ExecParallelEstimate(PlanState *node, ExecParallelEstimateContext *e)
Definition: execParallel.c:217
dsa_area * dsa_create_in_place(void *place, size_t size, int tranche_id, dsm_segment *segment)
Definition: dsa.c:468
void shm_mq_set_sender(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:218
#define PARALLEL_KEY_BUFFER_USAGE
Definition: execParallel.c:54
#define IsParallelWorker()
Definition: parallel.h:52
void ExecutorFinish(QueryDesc *queryDesc)
Definition: execMain.c:401
void ExecBitmapHeapReInitializeDSM(BitmapHeapScanState *node, ParallelContext *pcxt)
#define PARALLEL_KEY_PARAMS
Definition: execParallel.c:53
List * lappend(List *list, void *datum)
Definition: list.c:128
const char * debug_query_string
Definition: postgres.c:85
void InitializeParallelDSM(ParallelContext *pcxt)
Definition: parallel.c:192
#define InvalidSnapshot
Definition: snapshot.h:25
TupleQueueReader * CreateTupleQueueReader(shm_mq_handle *handle)
Definition: tqueue.c:135
void InstrStartParallelQuery(void)
Definition: instrument.c:170
void InstrInit(Instrumentation *instr, int instrument_options)
Definition: instrument.c:54
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
bool canSetTag
Definition: plannodes.h:53
Instrumentation instrument[FLEXIBLE_ARRAY_MEMBER]
Definition: instrument.h:69
void * palloc0(Size size)
Definition: mcxt.c:877
CmdType commandType
Definition: plannodes.h:45
void ExecForeignScanInitializeDSM(ForeignScanState *node, ParallelContext *pcxt)
void ReinitializeParallelDSM(ParallelContext *pcxt)
Definition: parallel.c:409
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:315
List * rowMarks
Definition: plannodes.h:86
Plan * plan
Definition: execnodes.h:847
void ExecCustomScanInitializeDSM(CustomScanState *node, ParallelContext *pcxt)
Definition: nodeCustom.c:182
Size dsa_minimum_size(void)
Definition: dsa.c:1160
#define makeNode(_type_)
Definition: nodes.h:557
void ExecParallelCleanup(ParallelExecutorInfo *pei)
Definition: execParallel.c:832
List * subplans
Definition: plannodes.h:81
void SerializeParamList(ParamListInfo paramLI, char **start_address)
Definition: params.c:158
#define Assert(condition)
Definition: c.h:664
#define lfirst(lc)
Definition: pg_list.h:106
Bitmapset * rewindPlanIDs
Definition: plannodes.h:84
bool hasModifyingCTE
Definition: plannodes.h:51
void ExecBitmapHeapInitializeWorker(BitmapHeapScanState *node, shm_toc *toc)
struct FixedParallelExecutorState FixedParallelExecutorState
void ExecForeignScanEstimate(ForeignScanState *node, ParallelContext *pcxt)
size_t Size
Definition: c.h:350
void ExecSeqScanEstimate(SeqScanState *node, ParallelContext *pcxt)
Definition: nodeSeqscan.c:296
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
#define MAXALIGN(LEN)
Definition: c.h:576
List * rtable
Definition: plannodes.h:63
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void ExecIndexOnlyScanReInitializeDSM(IndexOnlyScanState *node, ParallelContext *pcxt)
#define nodeTag(nodeptr)
Definition: nodes.h:514
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:287
List * targetlist
Definition: plannodes.h:144
const char * sourceText
Definition: execdesc.h:38
#define PARALLEL_KEY_DSA
Definition: execParallel.c:57
void ExecSeqScanReInitializeDSM(SeqScanState *node, ParallelContext *pcxt)
Definition: nodeSeqscan.c:335
e
Definition: preproc-init.c:82
Definition: dsa.c:354
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * palloc(Size size)
Definition: mcxt.c:848
List * resultRelations
Definition: plannodes.h:66
bool parallelModeNeeded
Definition: plannodes.h:59
ParallelExecutorInfo * ExecInitParallelPlan(PlanState *planstate, EState *estate, int nworkers, int64 tuples_needed)
Definition: execParallel.c:398
void ExecBitmapHeapEstimate(BitmapHeapScanState *node, ParallelContext *pcxt)
int i
#define PARALLEL_KEY_QUERY_TEXT
Definition: execParallel.c:58
Definition: shm_mq.c:69
char * nodeToString(const void *obj)
Definition: outfuncs.c:4255
void ExecCustomScanEstimate(CustomScanState *node, ParallelContext *pcxt)
Definition: nodeCustom.c:169
ParamListInfo es_param_list_info
Definition: execnodes.h:465
void ExecIndexOnlyScanInitializeDSM(IndexOnlyScanState *node, ParallelContext *pcxt)
bool parallel_safe
Definition: plannodes.h:138
shm_mq_handle ** tqueue
Definition: execParallel.h:33
static DestReceiver * ExecParallelGetReceiver(dsm_segment *seg, shm_toc *toc)
Definition: execParallel.c:852
void shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:199
#define elog
Definition: elog.h:219
void ExecSortRetrieveInstrumentation(SortState *node)
Definition: nodeSort.c:437
DestReceiver * CreateTupleQueueDestReceiver(shm_mq_handle *handle)
Definition: tqueue.c:115
#define copyObject(obj)
Definition: nodes.h:622
void ExecIndexScanEstimate(IndexScanState *node, ParallelContext *pcxt)
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.h:29
bool planstate_tree_walker(PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3697
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
static QueryDesc * ExecParallelGetQueryDesc(shm_toc *toc, DestReceiver *receiver, int instrument_options)
Definition: execParallel.c:868
#define offsetof(type, field)
Definition: c.h:549
#define GetInstrumentationArray(sei)
Definition: execParallel.c:95
shm_toc * toc
Definition: parallel.h:44