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-2016, 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"
28 #include "executor/nodeCustom.h"
30 #include "executor/nodeSeqscan.h"
31 #include "executor/tqueue.h"
32 #include "nodes/nodeFuncs.h"
33 #include "optimizer/planmain.h"
34 #include "optimizer/planner.h"
35 #include "storage/spin.h"
36 #include "tcop/tcopprot.h"
37 #include "utils/memutils.h"
38 #include "utils/snapmgr.h"
39 
40 /*
41  * Magic numbers for parallel executor communication. We use constants
42  * greater than any 32-bit integer here so that values < 2^32 can be used
43  * by individual parallel nodes to store their own state.
44  */
45 #define PARALLEL_KEY_PLANNEDSTMT UINT64CONST(0xE000000000000001)
46 #define PARALLEL_KEY_PARAMS UINT64CONST(0xE000000000000002)
47 #define PARALLEL_KEY_BUFFER_USAGE UINT64CONST(0xE000000000000003)
48 #define PARALLEL_KEY_TUPLE_QUEUE UINT64CONST(0xE000000000000004)
49 #define PARALLEL_KEY_INSTRUMENTATION UINT64CONST(0xE000000000000005)
50 
51 #define PARALLEL_TUPLE_QUEUE_SIZE 65536
52 
53 /* DSM structure for accumulating per-PlanState instrumentation. */
55 {
57  int instrument_offset; /* offset of first Instrumentation struct */
58  int num_workers; /* # of workers */
59  int num_plan_nodes; /* # of plan nodes */
60  int plan_node_id[FLEXIBLE_ARRAY_MEMBER]; /* array of plan node IDs */
61  /* array of num_plan_nodes * num_workers Instrumentation objects follows */
62 };
63 #define GetInstrumentationArray(sei) \
64  (AssertVariableIsOfTypeMacro(sei, SharedExecutorInstrumentation *), \
65  (Instrumentation *) (((char *) sei) + sei->instrument_offset))
66 
67 /* Context object for ExecParallelEstimate. */
69 {
71  int nnodes;
73 
74 /* Context object for ExecParallelEstimate. */
76 {
79  int nnodes;
81 
82 /* Helper functions that run in the parallel leader. */
83 static char *ExecSerializePlan(Plan *plan, EState *estate);
84 static bool ExecParallelEstimate(PlanState *node,
86 static bool ExecParallelInitializeDSM(PlanState *node,
89  bool reinitialize);
90 static bool ExecParallelRetrieveInstrumentation(PlanState *planstate,
91  SharedExecutorInstrumentation *instrumentation);
92 
93 /* Helper functions that run in the parallel worker. */
94 static void ParallelQueryMain(dsm_segment *seg, shm_toc *toc);
96 
97 /*
98  * Create a serialized representation of the plan to be sent to each worker.
99  */
100 static char *
102 {
103  PlannedStmt *pstmt;
104  ListCell *tlist;
105 
106  /* We can't scribble on the original plan, so make a copy. */
107  plan = copyObject(plan);
108 
109  /*
110  * The worker will start its own copy of the executor, and that copy will
111  * insert a junk filter if the toplevel node has any resjunk entries. We
112  * don't want that to happen, because while resjunk columns shouldn't be
113  * sent back to the user, here the tuples are coming back to another
114  * backend which may very well need them. So mutate the target list
115  * accordingly. This is sort of a hack; there might be better ways to do
116  * this...
117  */
118  foreach(tlist, plan->targetlist)
119  {
120  TargetEntry *tle = (TargetEntry *) lfirst(tlist);
121 
122  tle->resjunk = false;
123  }
124 
125  /*
126  * Create a dummy PlannedStmt. Most of the fields don't need to be valid
127  * for our purposes, but the worker will need at least a minimal
128  * PlannedStmt to start the executor.
129  */
130  pstmt = makeNode(PlannedStmt);
131  pstmt->commandType = CMD_SELECT;
132  pstmt->queryId = 0;
133  pstmt->hasReturning = 0;
134  pstmt->hasModifyingCTE = 0;
135  pstmt->canSetTag = 1;
136  pstmt->transientPlan = 0;
137  pstmt->planTree = plan;
138  pstmt->rtable = estate->es_range_table;
139  pstmt->resultRelations = NIL;
140  pstmt->utilityStmt = NULL;
141  pstmt->subplans = NIL;
142  pstmt->rewindPlanIDs = NULL;
143  pstmt->rowMarks = NIL;
144  pstmt->nParamExec = estate->es_plannedstmt->nParamExec;
145  pstmt->relationOids = NIL;
146  pstmt->invalItems = NIL; /* workers can't replan anyway... */
147  pstmt->hasRowSecurity = false;
148  pstmt->hasForeignJoin = false;
149 
150  /* Return serialized copy of our dummy PlannedStmt. */
151  return nodeToString(pstmt);
152 }
153 
154 /*
155  * Ordinary plan nodes won't do anything here, but parallel-aware plan nodes
156  * may need some state which is shared across all parallel workers. Before
157  * we size the DSM, give them a chance to call shm_toc_estimate_chunk or
158  * shm_toc_estimate_keys on &pcxt->estimator.
159  *
160  * While we're at it, count the number of PlanState nodes in the tree, so
161  * we know how many SharedPlanStateInstrumentation structures we need.
162  */
163 static bool
165 {
166  if (planstate == NULL)
167  return false;
168 
169  /* Count this node. */
170  e->nnodes++;
171 
172  /* Call estimators for parallel-aware nodes. */
173  if (planstate->plan->parallel_aware)
174  {
175  switch (nodeTag(planstate))
176  {
177  case T_SeqScanState:
178  ExecSeqScanEstimate((SeqScanState *) planstate,
179  e->pcxt);
180  break;
181  case T_ForeignScanState:
183  e->pcxt);
184  break;
185  case T_CustomScanState:
187  e->pcxt);
188  break;
189  default:
190  break;
191  }
192  }
193 
194  return planstate_tree_walker(planstate, ExecParallelEstimate, e);
195 }
196 
197 /*
198  * Initialize the dynamic shared memory segment that will be used to control
199  * parallel execution.
200  */
201 static bool
204 {
205  if (planstate == NULL)
206  return false;
207 
208  /* If instrumentation is enabled, initialize slot for this node. */
209  if (d->instrumentation != NULL)
211  planstate->plan->plan_node_id;
212 
213  /* Count this node. */
214  d->nnodes++;
215 
216  /*
217  * Call initializers for parallel-aware plan nodes.
218  *
219  * Ordinary plan nodes won't do anything here, but parallel-aware plan
220  * nodes may need to initialize shared state in the DSM before parallel
221  * workers are available. They can allocate the space they previously
222  * estimated using shm_toc_allocate, and add the keys they previously
223  * estimated using shm_toc_insert, in each case targeting pcxt->toc.
224  */
225  if (planstate->plan->parallel_aware)
226  {
227  switch (nodeTag(planstate))
228  {
229  case T_SeqScanState:
231  d->pcxt);
232  break;
233  case T_ForeignScanState:
235  d->pcxt);
236  break;
237  case T_CustomScanState:
239  d->pcxt);
240  break;
241  default:
242  break;
243  }
244  }
245 
246  return planstate_tree_walker(planstate, ExecParallelInitializeDSM, d);
247 }
248 
249 /*
250  * It sets up the response queues for backend workers to return tuples
251  * to the main backend and start the workers.
252  */
253 static shm_mq_handle **
255 {
256  shm_mq_handle **responseq;
257  char *tqueuespace;
258  int i;
259 
260  /* Skip this if no workers. */
261  if (pcxt->nworkers == 0)
262  return NULL;
263 
264  /* Allocate memory for shared memory queue handles. */
265  responseq = (shm_mq_handle **)
266  palloc(pcxt->nworkers * sizeof(shm_mq_handle *));
267 
268  /*
269  * If not reinitializing, allocate space from the DSM for the queues;
270  * otherwise, find the already allocated space.
271  */
272  if (!reinitialize)
273  tqueuespace =
274  shm_toc_allocate(pcxt->toc,
276  else
277  tqueuespace = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE);
278 
279  /* Create the queues, and become the receiver for each. */
280  for (i = 0; i < pcxt->nworkers; ++i)
281  {
282  shm_mq *mq;
283 
284  mq = shm_mq_create(tqueuespace + i * PARALLEL_TUPLE_QUEUE_SIZE,
285  (Size) PARALLEL_TUPLE_QUEUE_SIZE);
286 
288  responseq[i] = shm_mq_attach(mq, pcxt->seg, NULL);
289  }
290 
291  /* Add array of queues to shm_toc, so others can find it. */
292  if (!reinitialize)
293  shm_toc_insert(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, tqueuespace);
294 
295  /* Return array of handles. */
296  return responseq;
297 }
298 
299 /*
300  * Re-initialize the parallel executor info such that it can be reused by
301  * workers.
302  */
303 void
305 {
307  pei->tqueue = ExecParallelSetupTupleQueues(pei->pcxt, true);
308  pei->finished = false;
309 }
310 
311 /*
312  * Sets up the required infrastructure for backend workers to perform
313  * execution and return results to the main backend.
314  */
316 ExecInitParallelPlan(PlanState *planstate, EState *estate, int nworkers)
317 {
319  ParallelContext *pcxt;
322  char *pstmt_data;
323  char *pstmt_space;
324  char *param_space;
325  BufferUsage *bufusage_space;
326  SharedExecutorInstrumentation *instrumentation = NULL;
327  int pstmt_len;
328  int param_len;
329  int instrumentation_len = 0;
330  int instrument_offset = 0;
331 
332  /* Allocate object for return value. */
333  pei = palloc0(sizeof(ParallelExecutorInfo));
334  pei->finished = false;
335  pei->planstate = planstate;
336 
337  /* Fix up and serialize plan to be sent to workers. */
338  pstmt_data = ExecSerializePlan(planstate->plan, estate);
339 
340  /* Create a parallel context. */
341  pcxt = CreateParallelContext(ParallelQueryMain, nworkers);
342  pei->pcxt = pcxt;
343 
344  /*
345  * Before telling the parallel context to create a dynamic shared memory
346  * segment, we need to figure out how big it should be. Estimate space
347  * for the various things we need to store.
348  */
349 
350  /* Estimate space for serialized PlannedStmt. */
351  pstmt_len = strlen(pstmt_data) + 1;
352  shm_toc_estimate_chunk(&pcxt->estimator, pstmt_len);
353  shm_toc_estimate_keys(&pcxt->estimator, 1);
354 
355  /* Estimate space for serialized ParamListInfo. */
356  param_len = EstimateParamListSpace(estate->es_param_list_info);
357  shm_toc_estimate_chunk(&pcxt->estimator, param_len);
358  shm_toc_estimate_keys(&pcxt->estimator, 1);
359 
360  /*
361  * Estimate space for BufferUsage.
362  *
363  * If EXPLAIN is not in use and there are no extensions loaded that care,
364  * we could skip this. But we have no way of knowing whether anyone's
365  * looking at pgBufferUsage, so do it unconditionally.
366  */
368  sizeof(BufferUsage) * pcxt->nworkers);
369  shm_toc_estimate_keys(&pcxt->estimator, 1);
370 
371  /* Estimate space for tuple queues. */
374  shm_toc_estimate_keys(&pcxt->estimator, 1);
375 
376  /*
377  * Give parallel-aware nodes a chance to add to the estimates, and get
378  * a count of how many PlanState nodes there are.
379  */
380  e.pcxt = pcxt;
381  e.nnodes = 0;
382  ExecParallelEstimate(planstate, &e);
383 
384  /* Estimate space for instrumentation, if required. */
385  if (estate->es_instrument)
386  {
387  instrumentation_len =
389  + sizeof(int) * e.nnodes;
390  instrumentation_len = MAXALIGN(instrumentation_len);
391  instrument_offset = instrumentation_len;
392  instrumentation_len += sizeof(Instrumentation) * e.nnodes * nworkers;
393  shm_toc_estimate_chunk(&pcxt->estimator, instrumentation_len);
394  shm_toc_estimate_keys(&pcxt->estimator, 1);
395  }
396 
397  /* Everyone's had a chance to ask for space, so now create the DSM. */
398  InitializeParallelDSM(pcxt);
399 
400  /*
401  * OK, now we have a dynamic shared memory segment, and it should be big
402  * enough to store all of the data we estimated we would want to put into
403  * it, plus whatever general stuff (not specifically executor-related) the
404  * ParallelContext itself needs to store there. None of the space we
405  * asked for has been allocated or initialized yet, though, so do that.
406  */
407 
408  /* Store serialized PlannedStmt. */
409  pstmt_space = shm_toc_allocate(pcxt->toc, pstmt_len);
410  memcpy(pstmt_space, pstmt_data, pstmt_len);
411  shm_toc_insert(pcxt->toc, PARALLEL_KEY_PLANNEDSTMT, pstmt_space);
412 
413  /* Store serialized ParamListInfo. */
414  param_space = shm_toc_allocate(pcxt->toc, param_len);
415  shm_toc_insert(pcxt->toc, PARALLEL_KEY_PARAMS, param_space);
416  SerializeParamList(estate->es_param_list_info, &param_space);
417 
418  /* Allocate space for each worker's BufferUsage; no need to initialize. */
419  bufusage_space = shm_toc_allocate(pcxt->toc,
420  sizeof(BufferUsage) * pcxt->nworkers);
421  shm_toc_insert(pcxt->toc, PARALLEL_KEY_BUFFER_USAGE, bufusage_space);
422  pei->buffer_usage = bufusage_space;
423 
424  /* Set up tuple queues. */
425  pei->tqueue = ExecParallelSetupTupleQueues(pcxt, false);
426 
427  /*
428  * If instrumentation options were supplied, allocate space for the
429  * data. It only gets partially initialized here; the rest happens
430  * during ExecParallelInitializeDSM.
431  */
432  if (estate->es_instrument)
433  {
434  Instrumentation *instrument;
435  int i;
436 
437  instrumentation = shm_toc_allocate(pcxt->toc, instrumentation_len);
438  instrumentation->instrument_options = estate->es_instrument;
439  instrumentation->instrument_offset = instrument_offset;
440  instrumentation->num_workers = nworkers;
441  instrumentation->num_plan_nodes = e.nnodes;
442  instrument = GetInstrumentationArray(instrumentation);
443  for (i = 0; i < nworkers * e.nnodes; ++i)
444  InstrInit(&instrument[i], estate->es_instrument);
446  instrumentation);
447  pei->instrumentation = instrumentation;
448  }
449 
450  /*
451  * Give parallel-aware nodes a chance to initialize their shared data.
452  * This also initializes the elements of instrumentation->ps_instrument,
453  * if it exists.
454  */
455  d.pcxt = pcxt;
456  d.instrumentation = instrumentation;
457  d.nnodes = 0;
458  ExecParallelInitializeDSM(planstate, &d);
459 
460  /*
461  * Make sure that the world hasn't shifted under our feat. This could
462  * probably just be an Assert(), but let's be conservative for now.
463  */
464  if (e.nnodes != d.nnodes)
465  elog(ERROR, "inconsistent count of PlanState nodes");
466 
467  /* OK, we're ready to rock and roll. */
468  return pei;
469 }
470 
471 /*
472  * Copy instrumentation information about this node and its descendents from
473  * dynamic shared memory.
474  */
475 static bool
477  SharedExecutorInstrumentation *instrumentation)
478 {
479  Instrumentation *instrument;
480  int i;
481  int n;
482  int ibytes;
483  int plan_node_id = planstate->plan->plan_node_id;
484 
485  /* Find the instumentation for this node. */
486  for (i = 0; i < instrumentation->num_plan_nodes; ++i)
487  if (instrumentation->plan_node_id[i] == plan_node_id)
488  break;
489  if (i >= instrumentation->num_plan_nodes)
490  elog(ERROR, "plan node %d not found", plan_node_id);
491 
492  /* Accumulate the statistics from all workers. */
493  instrument = GetInstrumentationArray(instrumentation);
494  instrument += i * instrumentation->num_workers;
495  for (n = 0; n < instrumentation->num_workers; ++n)
496  InstrAggNode(planstate->instrument, &instrument[n]);
497 
498  /* Also store the per-worker detail. */
499  ibytes = instrumentation->num_workers * sizeof(Instrumentation);
500  planstate->worker_instrument =
501  palloc(offsetof(WorkerInstrumentation, instrument) + ibytes);
502  planstate->worker_instrument->num_workers = instrumentation->num_workers;
503  memcpy(&planstate->worker_instrument->instrument, instrument, ibytes);
504 
506  instrumentation);
507 }
508 
509 /*
510  * Finish parallel execution. We wait for parallel workers to finish, and
511  * accumulate their buffer usage and instrumentation.
512  */
513 void
515 {
516  int i;
517 
518  if (pei->finished)
519  return;
520 
521  /* First, wait for the workers to finish. */
523 
524  /* Next, accumulate buffer usage. */
525  for (i = 0; i < pei->pcxt->nworkers_launched; ++i)
527 
528  /* Finally, accumulate instrumentation, if any. */
529  if (pei->instrumentation)
531  pei->instrumentation);
532 
533  pei->finished = true;
534 }
535 
536 /*
537  * Clean up whatever ParallelExecutreInfo resources still exist after
538  * ExecParallelFinish. We separate these routines because someone might
539  * want to examine the contents of the DSM after ExecParallelFinish and
540  * before calling this routine.
541  */
542 void
544 {
545  if (pei->pcxt != NULL)
546  {
548  pei->pcxt = NULL;
549  }
550  pfree(pei);
551 }
552 
553 /*
554  * Create a DestReceiver to write tuples we produce to the shm_mq designated
555  * for that purpose.
556  */
557 static DestReceiver *
559 {
560  char *mqspace;
561  shm_mq *mq;
562 
565  mq = (shm_mq *) mqspace;
568 }
569 
570 /*
571  * Create a QueryDesc for the PlannedStmt we are to execute, and return it.
572  */
573 static QueryDesc *
575  int instrument_options)
576 {
577  char *pstmtspace;
578  char *paramspace;
579  PlannedStmt *pstmt;
580  ParamListInfo paramLI;
581 
582  /* Reconstruct leader-supplied PlannedStmt. */
583  pstmtspace = shm_toc_lookup(toc, PARALLEL_KEY_PLANNEDSTMT);
584  pstmt = (PlannedStmt *) stringToNode(pstmtspace);
585 
586  /* Reconstruct ParamListInfo. */
587  paramspace = shm_toc_lookup(toc, PARALLEL_KEY_PARAMS);
588  paramLI = RestoreParamList(&paramspace);
589 
590  /*
591  * Create a QueryDesc for the query.
592  *
593  * It's not obvious how to obtain the query string from here; and even if
594  * we could copying it would take more cycles than not copying it. But
595  * it's a bit unsatisfying to just use a dummy string here, so consider
596  * revising this someday.
597  */
598  return CreateQueryDesc(pstmt,
599  "<parallel query>",
601  receiver, paramLI, instrument_options);
602 }
603 
604 /*
605  * Copy instrumentation information from this node and its descendents into
606  * dynamic shared memory, so that the parallel leader can retrieve it.
607  */
608 static bool
610  SharedExecutorInstrumentation *instrumentation)
611 {
612  int i;
613  int plan_node_id = planstate->plan->plan_node_id;
614  Instrumentation *instrument;
615 
616  InstrEndLoop(planstate->instrument);
617 
618  /*
619  * If we shuffled the plan_node_id values in ps_instrument into sorted
620  * order, we could use binary search here. This might matter someday
621  * if we're pushing down sufficiently large plan trees. For now, do it
622  * the slow, dumb way.
623  */
624  for (i = 0; i < instrumentation->num_plan_nodes; ++i)
625  if (instrumentation->plan_node_id[i] == plan_node_id)
626  break;
627  if (i >= instrumentation->num_plan_nodes)
628  elog(ERROR, "plan node %d not found", plan_node_id);
629 
630  /*
631  * Add our statistics to the per-node, per-worker totals. It's possible
632  * that this could happen more than once if we relaunched workers.
633  */
634  instrument = GetInstrumentationArray(instrumentation);
635  instrument += i * instrumentation->num_workers;
637  Assert(ParallelWorkerNumber < instrumentation->num_workers);
638  InstrAggNode(&instrument[ParallelWorkerNumber], planstate->instrument);
639 
641  instrumentation);
642 }
643 
644 /*
645  * Initialize the PlanState and its descendents with the information
646  * retrieved from shared memory. This has to be done once the PlanState
647  * is allocated and initialized by executor; that is, after ExecutorStart().
648  */
649 static bool
651 {
652  if (planstate == NULL)
653  return false;
654 
655  /* Call initializers for parallel-aware plan nodes. */
656  if (planstate->plan->parallel_aware)
657  {
658  switch (nodeTag(planstate))
659  {
660  case T_SeqScanState:
661  ExecSeqScanInitializeWorker((SeqScanState *) planstate, toc);
662  break;
663  case T_ForeignScanState:
665  toc);
666  break;
667  case T_CustomScanState:
669  toc);
670  break;
671  default:
672  break;
673  }
674  }
675 
676  return planstate_tree_walker(planstate, ExecParallelInitializeWorker, toc);
677 }
678 
679 /*
680  * Main entrypoint for parallel query worker processes.
681  *
682  * We reach this function from ParallelMain, so the setup necessary to create
683  * a sensible parallel environment has already been done; ParallelMain worries
684  * about stuff like the transaction state, combo CID mappings, and GUC values,
685  * so we don't need to deal with any of that here.
686  *
687  * Our job is to deal with concerns specific to the executor. The parallel
688  * group leader will have stored a serialized PlannedStmt, and it's our job
689  * to execute that plan and write the resulting tuples to the appropriate
690  * tuple queue. Various bits of supporting information that we need in order
691  * to do this are also stored in the dsm_segment and can be accessed through
692  * the shm_toc.
693  */
694 static void
696 {
697  BufferUsage *buffer_usage;
698  DestReceiver *receiver;
699  QueryDesc *queryDesc;
700  SharedExecutorInstrumentation *instrumentation;
701  int instrument_options = 0;
702 
703  /* Set up DestReceiver, SharedExecutorInstrumentation, and QueryDesc. */
704  receiver = ExecParallelGetReceiver(seg, toc);
705  instrumentation = shm_toc_lookup(toc, PARALLEL_KEY_INSTRUMENTATION);
706  if (instrumentation != NULL)
707  instrument_options = instrumentation->instrument_options;
708  queryDesc = ExecParallelGetQueryDesc(toc, receiver, instrument_options);
709 
710  /* Prepare to track buffer usage during query execution. */
712 
713  /* Start up the executor, have it run the plan, and then shut it down. */
714  ExecutorStart(queryDesc, 0);
715  ExecParallelInitializeWorker(queryDesc->planstate, toc);
716  ExecutorRun(queryDesc, ForwardScanDirection, 0L);
717  ExecutorFinish(queryDesc);
718 
719  /* Report buffer usage during parallel execution. */
720  buffer_usage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE);
722 
723  /* Report instrumentation data if any instrumentation options are set. */
724  if (instrumentation != NULL)
726  instrumentation);
727 
728  /* Must do this after capturing instrumentation. */
729  ExecutorEnd(queryDesc);
730 
731  /* Cleanup. */
732  FreeQueryDesc(queryDesc);
733  (*receiver->rDestroy) (receiver);
734 }
void ExecSeqScanInitializeWorker(SeqScanState *node, shm_toc *toc)
Definition: nodeSeqscan.c:337
#define NIL
Definition: pg_list.h:69
void * stringToNode(char *str)
Definition: read.c:38
void(* rDestroy)(DestReceiver *self)
Definition: dest.h:123
ParallelContext * pcxt
Definition: execParallel.h:26
uint32 queryId
Definition: plannodes.h:42
WorkerInstrumentation * worker_instrument
Definition: execnodes.h:1034
struct ExecParallelEstimateContext ExecParallelEstimateContext
int plan_node_id[FLEXIBLE_ARRAY_MEMBER]
Definition: execParallel.c:60
Instrumentation * instrument
Definition: execnodes.h:1033
void ExecParallelFinish(ParallelExecutorInfo *pei)
Definition: execParallel.c:514
#define PARALLEL_KEY_TUPLE_QUEUE
Definition: execParallel.c:48
bool hasForeignJoin
Definition: plannodes.h:76
void FreeQueryDesc(QueryDesc *qdesc)
Definition: pquery.c:128
static void ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
Definition: execParallel.c:695
PGPROC * MyProc
Definition: proc.c:65
Definition: plannodes.h:96
void InstrAggNode(Instrumentation *dst, Instrumentation *add)
Definition: instrument.c:143
dsm_segment * seg
Definition: parallel.h:44
static bool ExecParallelReportInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
Definition: execParallel.c:609
void ExecCustomScanInitializeWorker(CustomScanState *node, shm_toc *toc)
Definition: nodeCustom.c:194
List * relationOids
Definition: plannodes.h:67
shm_toc_estimator estimator
Definition: parallel.h:43
void ExecutorStart(QueryDesc *queryDesc, int eflags)
Definition: execMain.c:135
int plan_node_id
Definition: plannodes.h:120
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:644
PlannedStmt * es_plannedstmt
Definition: execnodes.h:363
PlanState * planstate
Definition: execParallel.h:25
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
Definition: execMain.c:280
void InstrEndParallelQuery(BufferUsage *result)
Definition: instrument.c:177
static char * ExecSerializePlan(Plan *plan, EState *estate)
Definition: execParallel.c:101
ParallelExecutorInfo * ExecInitParallelPlan(PlanState *planstate, EState *estate, int nworkers)
Definition: execParallel.c:316
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, int instrument_options)
Definition: pquery.c:62
static shm_mq_handle ** ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize)
Definition: execParallel.c:254
List * es_range_table
Definition: execnodes.h:362
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:49
bool transientPlan
Definition: plannodes.h:50
Size EstimateParamListSpace(ParamListInfo paramLI)
Definition: params.c:95
struct Plan * planTree
Definition: plannodes.h:52
List * invalItems
Definition: plannodes.h:69
void * copyObject(const void *from)
Definition: copyfuncs.c:4245
void InstrEndLoop(Instrumentation *instr)
Definition: instrument.c:114
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.c:78
void ExecutorEnd(QueryDesc *queryDesc)
Definition: execMain.c:434
ParallelContext * pcxt
Definition: execParallel.c:70
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition: parallel.c:509
#define PARALLEL_KEY_INSTRUMENTATION
Definition: execParallel.c:49
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:598
int nParamExec
Definition: plannodes.h:71
void pfree(void *pointer)
Definition: mcxt.c:995
void ExecSeqScanInitializeDSM(SeqScanState *node, ParallelContext *pcxt)
Definition: nodeSeqscan.c:315
static bool ExecParallelInitializeDSM(PlanState *node, ExecParallelInitializeDSMContext *d)
Definition: execParallel.c:202
bool resjunk
Definition: primnodes.h:1285
#define ERROR
Definition: elog.h:41
PlanState * planstate
Definition: execdesc.h:49
BufferUsage * buffer_usage
Definition: execParallel.h:27
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:166
#define PARALLEL_KEY_PLANNEDSTMT
Definition: execParallel.c:45
ParamListInfo RestoreParamList(char **start_address)
Definition: params.c:224
void * shm_toc_lookup(shm_toc *toc, uint64 key)
Definition: shm_toc.c:218
static bool ExecParallelRetrieveInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
Definition: execParallel.c:476
bool hasReturning
Definition: plannodes.h:44
struct ExecParallelInitializeDSMContext ExecParallelInitializeDSMContext
void ExecForeignScanInitializeWorker(ForeignScanState *node, shm_toc *toc)
Node * utilityStmt
Definition: plannodes.h:59
int ParallelWorkerNumber
Definition: parallel.c:91
static bool ExecParallelInitializeWorker(PlanState *planstate, shm_toc *toc)
Definition: execParallel.c:650
bool parallel_aware
Definition: plannodes.h:115
#define PARALLEL_TUPLE_QUEUE_SIZE
Definition: execParallel.c:51
void InstrAccumParallelQuery(BufferUsage *result)
Definition: instrument.c:185
int es_instrument
Definition: execnodes.h:396
int nworkers_launched
Definition: parallel.h:38
static bool ExecParallelEstimate(PlanState *node, ExecParallelEstimateContext *e)
Definition: execParallel.c:164
void shm_mq_set_sender(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:214
#define PARALLEL_KEY_BUFFER_USAGE
Definition: execParallel.c:47
#define IsParallelWorker()
Definition: parallel.h:54
void ExecutorFinish(QueryDesc *queryDesc)
Definition: execMain.c:374
#define PARALLEL_KEY_PARAMS
Definition: execParallel.c:46
void InitializeParallelDSM(ParallelContext *pcxt)
Definition: parallel.c:195
#define InvalidSnapshot
Definition: snapshot.h:23
void InstrStartParallelQuery(void)
Definition: instrument.c:170
void InstrInit(Instrumentation *instr, int instrument_options)
Definition: instrument.c:54
bool canSetTag
Definition: plannodes.h:48
Instrumentation instrument[FLEXIBLE_ARRAY_MEMBER]
Definition: instrument.h:69
void * palloc0(Size size)
Definition: mcxt.c:923
CmdType commandType
Definition: plannodes.h:40
void ExecForeignScanInitializeDSM(ForeignScanState *node, ParallelContext *pcxt)
void ReinitializeParallelDSM(ParallelContext *pcxt)
Definition: parallel.c:387
List * rowMarks
Definition: plannodes.h:65
Plan * plan
Definition: execnodes.h:1027
void ExecParallelReinitialize(ParallelExecutorInfo *pei)
Definition: execParallel.c:304
void ExecCustomScanInitializeDSM(CustomScanState *node, ParallelContext *pcxt)
Definition: nodeCustom.c:178
#define makeNode(_type_)
Definition: nodes.h:537
void ExecParallelCleanup(ParallelExecutorInfo *pei)
Definition: execParallel.c:543
List * subplans
Definition: plannodes.h:61
#define NULL
Definition: c.h:215
void SerializeParamList(ParamListInfo paramLI, char **start_address)
Definition: params.c:158
#define Assert(condition)
Definition: c.h:656
#define lfirst(lc)
Definition: pg_list.h:106
Bitmapset * rewindPlanIDs
Definition: plannodes.h:63
bool hasModifyingCTE
Definition: plannodes.h:46
void ExecForeignScanEstimate(ForeignScanState *node, ParallelContext *pcxt)
size_t Size
Definition: c.h:341
void ExecSeqScanEstimate(SeqScanState *node, ParallelContext *pcxt)
Definition: nodeSeqscan.c:298
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:52
#define MAXALIGN(LEN)
Definition: c.h:569
List * rtable
Definition: plannodes.h:54
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:83
#define nodeTag(nodeptr)
Definition: nodes.h:494
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:283
List * targetlist
Definition: plannodes.h:121
struct Instrumentation Instrumentation
e
Definition: preproc-init.c:82
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:161
void * palloc(Size size)
Definition: mcxt.c:894
List * resultRelations
Definition: plannodes.h:57
int i
Definition: shm_mq.c:68
char * nodeToString(const void *obj)
Definition: outfuncs.c:3806
void ExecCustomScanEstimate(CustomScanState *node, ParallelContext *pcxt)
Definition: nodeCustom.c:165
ParamListInfo es_param_list_info
Definition: execnodes.h:382
bool hasRowSecurity
Definition: plannodes.h:73
shm_mq_handle ** tqueue
Definition: execParallel.h:29
static DestReceiver * ExecParallelGetReceiver(dsm_segment *seg, shm_toc *toc)
Definition: execParallel.c:558
void shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:195
ParallelContext * CreateParallelContext(parallel_worker_main_type entrypoint, int nworkers)
Definition: parallel.c:118
#define elog
Definition: elog.h:228
DestReceiver * CreateTupleQueueDestReceiver(shm_mq_handle *handle)
Definition: tqueue.c:465
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.h:28
bool planstate_tree_walker(PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3428
static QueryDesc * ExecParallelGetQueryDesc(shm_toc *toc, DestReceiver *receiver, int instrument_options)
Definition: execParallel.c:574
#define offsetof(type, field)
Definition: c.h:536
#define GetInstrumentationArray(sei)
Definition: execParallel.c:63
shm_toc * toc
Definition: parallel.h:46