PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
execParallel.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
#include "utils/dsa.h"
Include dependency graph for execParallel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ParallelExecutorInfo
 

Typedefs

typedef struct
SharedExecutorInstrumentation 
SharedExecutorInstrumentation
 
typedef struct ParallelExecutorInfo ParallelExecutorInfo
 

Functions

ParallelExecutorInfoExecInitParallelPlan (PlanState *planstate, EState *estate, int nworkers, int64 tuples_needed)
 
void ExecParallelCreateReaders (ParallelExecutorInfo *pei)
 
void ExecParallelFinish (ParallelExecutorInfo *pei)
 
void ExecParallelCleanup (ParallelExecutorInfo *pei)
 
void ExecParallelReinitialize (PlanState *planstate, ParallelExecutorInfo *pei)
 
void ParallelQueryMain (dsm_segment *seg, shm_toc *toc)
 

Typedef Documentation

Function Documentation

ParallelExecutorInfo* ExecInitParallelPlan ( PlanState planstate,
EState estate,
int  nworkers,
int64  tuples_needed 
)

Definition at line 398 of file execParallel.c.

References ParallelExecutorInfo::area, ParallelExecutorInfo::buffer_usage, CreateParallelContext(), dsa_create_in_place(), dsa_minimum_size(), elog, ERROR, EState::es_instrument, EState::es_param_list_info, EState::es_query_dsa, EState::es_sourceText, EstimateParamListSpace(), ParallelContext::estimator, ExecParallelEstimate(), ExecParallelInitializeDSM(), ExecParallelSetupTupleQueues(), ExecSerializePlan(), ParallelExecutorInfo::finished, GetInstrumentationArray, i, InitializeParallelDSM(), InstrInit(), SharedExecutorInstrumentation::instrument_offset, SharedExecutorInstrumentation::instrument_options, ParallelExecutorInfo::instrumentation, ExecParallelInitializeDSMContext::instrumentation, LWTRANCHE_PARALLEL_QUERY_DSA, MAXALIGN, mul_size(), ExecParallelEstimateContext::nnodes, ExecParallelInitializeDSMContext::nnodes, SharedExecutorInstrumentation::num_plan_nodes, SharedExecutorInstrumentation::num_workers, ParallelContext::nworkers, offsetof, palloc0(), PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_DSA, PARALLEL_KEY_EXECUTOR_FIXED, PARALLEL_KEY_INSTRUMENTATION, PARALLEL_KEY_PARAMS, PARALLEL_KEY_PLANNEDSTMT, PARALLEL_KEY_QUERY_TEXT, PARALLEL_TUPLE_QUEUE_SIZE, ParallelExecutorInfo::pcxt, ExecParallelEstimateContext::pcxt, ExecParallelInitializeDSMContext::pcxt, PlanState::plan, ParallelExecutorInfo::planstate, ParallelExecutorInfo::reader, ParallelContext::seg, SerializeParamList(), shm_toc_allocate(), shm_toc_estimate_chunk, shm_toc_estimate_keys, shm_toc_insert(), ParallelContext::toc, ParallelExecutorInfo::tqueue, and FixedParallelExecutorState::tuples_needed.

Referenced by ExecGather(), and ExecGatherMerge().

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 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:511
ParallelContext * pcxt
Definition: execParallel.h:27
ParallelContext * CreateParallelContext(const char *library_name, const char *function_name, int nworkers)
Definition: parallel.c:140
dsm_segment * seg
Definition: parallel.h:42
shm_toc_estimator estimator
Definition: parallel.h:41
PlanState * planstate
Definition: execParallel.h:26
static char * ExecSerializePlan(Plan *plan, EState *estate)
Definition: execParallel.c:134
static shm_mq_handle ** ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize)
Definition: execParallel.c:346
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Size EstimateParamListSpace(ParamListInfo paramLI)
Definition: params.c:95
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.c:110
ParallelContext * pcxt
Definition: execParallel.c:102
#define PARALLEL_KEY_INSTRUMENTATION
Definition: execParallel.c:56
const char * es_sourceText
Definition: execnodes.h:433
static bool ExecParallelInitializeDSM(PlanState *node, ExecParallelInitializeDSMContext *d)
Definition: execParallel.c:274
#define ERROR
Definition: elog.h:43
BufferUsage * buffer_usage
Definition: execParallel.h:28
#define PARALLEL_KEY_PLANNEDSTMT
Definition: execParallel.c:52
struct TupleQueueReader ** reader
Definition: execParallel.h:34
#define PARALLEL_TUPLE_QUEUE_SIZE
Definition: execParallel.c:60
int es_instrument
Definition: execnodes.h:481
#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
#define PARALLEL_KEY_BUFFER_USAGE
Definition: execParallel.c:54
#define PARALLEL_KEY_PARAMS
Definition: execParallel.c:53
void InitializeParallelDSM(ParallelContext *pcxt)
Definition: parallel.c:192
void InstrInit(Instrumentation *instr, int instrument_options)
Definition: instrument.c:54
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
void * palloc0(Size size)
Definition: mcxt.c:877
Plan * plan
Definition: execnodes.h:847
Size dsa_minimum_size(void)
Definition: dsa.c:1160
void SerializeParamList(ParamListInfo paramLI, char **start_address)
Definition: params.c:158
size_t Size
Definition: c.h:350
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
#define MAXALIGN(LEN)
Definition: c.h:576
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
#define PARALLEL_KEY_DSA
Definition: execParallel.c:57
e
Definition: preproc-init.c:82
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
int i
#define PARALLEL_KEY_QUERY_TEXT
Definition: execParallel.c:58
ParamListInfo es_param_list_info
Definition: execnodes.h:465
shm_mq_handle ** tqueue
Definition: execParallel.h:33
#define elog
Definition: elog.h:219
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.h:29
#define offsetof(type, field)
Definition: c.h:549
#define GetInstrumentationArray(sei)
Definition: execParallel.c:95
shm_toc * toc
Definition: parallel.h:44
void ExecParallelCleanup ( ParallelExecutorInfo pei)

Definition at line 832 of file execParallel.c.

References ParallelExecutorInfo::area, DestroyParallelContext(), dsa_detach(), ParallelExecutorInfo::pcxt, and pfree().

Referenced by ExecShutdownGather(), and ExecShutdownGatherMerge().

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 }
ParallelContext * pcxt
Definition: execParallel.h:27
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:624
void pfree(void *pointer)
Definition: mcxt.c:949
void dsa_detach(dsa_area *area)
Definition: dsa.c:1884
void ExecParallelCreateReaders ( ParallelExecutorInfo pei)

Definition at line 616 of file execParallel.c.

References Assert, ParallelWorkerInfo::bgwhandle, CreateTupleQueueReader(), i, ParallelContext::nworkers_launched, palloc(), ParallelExecutorInfo::pcxt, ParallelExecutorInfo::reader, shm_mq_set_handle(), ParallelExecutorInfo::tqueue, and ParallelContext::worker.

Referenced by ExecGather(), and ExecGatherMerge().

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 }
ParallelContext * pcxt
Definition: execParallel.h:27
ParallelWorkerInfo * worker
Definition: parallel.h:45
struct TupleQueueReader ** reader
Definition: execParallel.h:34
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
int nworkers_launched
Definition: parallel.h:37
TupleQueueReader * CreateTupleQueueReader(shm_mq_handle *handle)
Definition: tqueue.c:135
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:315
#define Assert(condition)
Definition: c.h:681
void * palloc(Size size)
Definition: mcxt.c:848
int i
shm_mq_handle ** tqueue
Definition: execParallel.h:33
void ExecParallelFinish ( ParallelExecutorInfo pei)

Definition at line 774 of file execParallel.c.

References ParallelExecutorInfo::buffer_usage, DestroyTupleQueueReader(), ExecParallelRetrieveInstrumentation(), ParallelExecutorInfo::finished, i, InstrAccumParallelQuery(), ParallelExecutorInfo::instrumentation, ParallelContext::nworkers_launched, ParallelExecutorInfo::pcxt, pfree(), ParallelExecutorInfo::planstate, ParallelExecutorInfo::reader, shm_mq_detach(), ParallelExecutorInfo::tqueue, and WaitForParallelWorkersToFinish().

Referenced by ExecShutdownGatherMergeWorkers(), and ExecShutdownGatherWorkers().

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 }
ParallelContext * pcxt
Definition: execParallel.h:27
void DestroyTupleQueueReader(TupleQueueReader *reader)
Definition: tqueue.c:151
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:775
PlanState * planstate
Definition: execParallel.h:26
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition: parallel.c:534
void pfree(void *pointer)
Definition: mcxt.c:949
BufferUsage * buffer_usage
Definition: execParallel.h:28
static bool ExecParallelRetrieveInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
Definition: execParallel.c:719
struct TupleQueueReader ** reader
Definition: execParallel.h:34
void InstrAccumParallelQuery(BufferUsage *result)
Definition: instrument.c:185
int nworkers_launched
Definition: parallel.h:37
int i
shm_mq_handle ** tqueue
Definition: execParallel.h:33
SharedExecutorInstrumentation * instrumentation
Definition: execParallel.h:29
void ExecParallelReinitialize ( PlanState planstate,
ParallelExecutorInfo pei 
)

Definition at line 642 of file execParallel.c.

References Assert, ExecParallelReInitializeDSM(), ExecParallelSetupTupleQueues(), ParallelExecutorInfo::finished, ParallelExecutorInfo::pcxt, ParallelExecutorInfo::reader, ReinitializeParallelDSM(), and ParallelExecutorInfo::tqueue.

Referenced by ExecGather(), and ExecGatherMerge().

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 }
ParallelContext * pcxt
Definition: execParallel.h:27
static shm_mq_handle ** ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize)
Definition: execParallel.c:346
static bool ExecParallelReInitializeDSM(PlanState *planstate, ParallelContext *pcxt)
Definition: execParallel.c:661
struct TupleQueueReader ** reader
Definition: execParallel.h:34
void ReinitializeParallelDSM(ParallelContext *pcxt)
Definition: parallel.c:409
#define Assert(condition)
Definition: c.h:681
shm_mq_handle ** tqueue
Definition: execParallel.h:33
void ParallelQueryMain ( dsm_segment seg,
shm_toc toc 
)

Definition at line 1010 of file execParallel.c.

References debug_query_string, dsa_attach_in_place(), dsa_detach(), EState::es_query_dsa, ExecParallelGetQueryDesc(), ExecParallelGetReceiver(), ExecParallelInitializeWorker(), ExecParallelReportInstrumentation(), ExecSetTupleBound(), ExecutorEnd(), ExecutorFinish(), ExecutorRun(), ExecutorStart(), ForwardScanDirection, FreeQueryDesc(), InstrEndParallelQuery(), InstrStartParallelQuery(), SharedExecutorInstrumentation::instrument_options, PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_DSA, PARALLEL_KEY_EXECUTOR_FIXED, PARALLEL_KEY_INSTRUMENTATION, ParallelWorkerNumber, pgstat_report_activity(), QueryDesc::planstate, _DestReceiver::rDestroy, shm_toc_lookup(), QueryDesc::sourceText, PlanState::state, STATE_RUNNING, and FixedParallelExecutorState::tuples_needed.

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 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:511
void(* rDestroy)(DestReceiver *self)
Definition: dest.h:126
void FreeQueryDesc(QueryDesc *qdesc)
Definition: pquery.c:105
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:2994
static bool ExecParallelReportInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
Definition: execParallel.c:907
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
void InstrEndParallelQuery(BufferUsage *result)
Definition: instrument.c:177
EState * state
Definition: execnodes.h:849
void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node)
Definition: execProcnode.c:778
void ExecutorEnd(QueryDesc *queryDesc)
Definition: execMain.c:461
#define PARALLEL_KEY_INSTRUMENTATION
Definition: execParallel.c:56
PlanState * planstate
Definition: execdesc.h:49
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
Definition: execMain.c:299
void dsa_detach(dsa_area *area)
Definition: dsa.c:1884
int ParallelWorkerNumber
Definition: parallel.c:98
static bool ExecParallelInitializeWorker(PlanState *planstate, shm_toc *toc)
Definition: execParallel.c:948
#define PARALLEL_KEY_EXECUTOR_FIXED
Definition: execParallel.c:51
#define PARALLEL_KEY_BUFFER_USAGE
Definition: execParallel.c:54
void ExecutorFinish(QueryDesc *queryDesc)
Definition: execMain.c:401
const char * debug_query_string
Definition: postgres.c:85
void InstrStartParallelQuery(void)
Definition: instrument.c:170
const char * sourceText
Definition: execdesc.h:38
#define PARALLEL_KEY_DSA
Definition: execParallel.c:57
Definition: dsa.c:354
static DestReceiver * ExecParallelGetReceiver(dsm_segment *seg, shm_toc *toc)
Definition: execParallel.c:852
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