PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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, Bitmapset *sendParams, int nworkers, int64 tuples_needed)
 
void ExecParallelCreateReaders (ParallelExecutorInfo *pei)
 
void ExecParallelFinish (ParallelExecutorInfo *pei)
 
void ExecParallelCleanup (ParallelExecutorInfo *pei)
 
void ExecParallelReinitialize (PlanState *planstate, ParallelExecutorInfo *pei, Bitmapset *sendParams)
 
void ParallelQueryMain (dsm_segment *seg, shm_toc *toc)
 

Typedef Documentation

◆ ParallelExecutorInfo

◆ SharedExecutorInstrumentation

Function Documentation

◆ ExecInitParallelPlan()

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

Definition at line 611 of file execParallel.c.

614{
616 ParallelContext *pcxt;
620 char *pstmt_data;
621 char *pstmt_space;
625 SharedExecutorInstrumentation *instrumentation = NULL;
626 SharedJitInstrumentation *jit_instrumentation = NULL;
627 int pstmt_len;
629 int instrumentation_len = 0;
631 int instrument_offset = 0;
633 char *query_string;
634 int query_len;
635
636 /*
637 * Force any initplan outputs that we're going to pass to workers to be
638 * evaluated, if they weren't already.
639 *
640 * For simplicity, we use the EState's per-output-tuple ExprContext here.
641 * That risks intra-query memory leakage, since we might pass through here
642 * many times before that ExprContext gets reset; but ExecSetParamPlan
643 * doesn't normally leak any memory in the context (see its comments), so
644 * it doesn't seem worth complicating this function's API to pass it a
645 * shorter-lived ExprContext. This might need to change someday.
646 */
648
649 /* Allocate object for return value. */
651 pei->finished = false;
652 pei->planstate = planstate;
653
654 /* Fix up and serialize plan to be sent to workers. */
655 pstmt_data = ExecSerializePlan(planstate->plan, estate);
656
657 /* Create a parallel context. */
658 pcxt = CreateParallelContext("postgres", "ParallelQueryMain", nworkers);
659 pei->pcxt = pcxt;
660
661 /*
662 * Before telling the parallel context to create a dynamic shared memory
663 * segment, we need to figure out how big it should be. Estimate space
664 * for the various things we need to store.
665 */
666
667 /* Estimate space for fixed-size state. */
671
672 /* Estimate space for query text. */
673 query_len = strlen(estate->es_sourceText);
674 shm_toc_estimate_chunk(&pcxt->estimator, query_len + 1);
676
677 /* Estimate space for serialized PlannedStmt. */
681
682 /* Estimate space for serialized ParamListInfo. */
686
687 /*
688 * Estimate space for BufferUsage.
689 *
690 * If EXPLAIN is not in use and there are no extensions loaded that care,
691 * we could skip this. But we have no way of knowing whether anyone's
692 * looking at pgBufferUsage, so do it unconditionally.
693 */
695 mul_size(sizeof(BufferUsage), pcxt->nworkers));
697
698 /*
699 * Same thing for WalUsage.
700 */
702 mul_size(sizeof(WalUsage), pcxt->nworkers));
704
705 /* Estimate space for tuple queues. */
709
710 /*
711 * Give parallel-aware nodes a chance to add to the estimates, and get a
712 * count of how many PlanState nodes there are.
713 */
714 e.pcxt = pcxt;
715 e.nnodes = 0;
716 ExecParallelEstimate(planstate, &e);
717
718 /* Estimate space for instrumentation, if required. */
719 if (estate->es_instrument)
720 {
723 sizeof(int) * e.nnodes;
725 instrument_offset = instrumentation_len;
728 mul_size(e.nnodes, nworkers));
731
732 /* Estimate space for JIT instrumentation, if required. */
733 if (estate->es_jit_flags != PGJIT_NONE)
734 {
737 sizeof(JitInstrumentation) * nworkers;
740 }
741 }
742
743 /* Estimate space for DSA area. */
746
747 /*
748 * InitializeParallelDSM() passes the active snapshot to the parallel
749 * worker, which uses it to set es_snapshot. Make sure we don't set
750 * es_snapshot differently in the child.
751 */
753
754 /* Everyone's had a chance to ask for space, so now create the DSM. */
756
757 /*
758 * OK, now we have a dynamic shared memory segment, and it should be big
759 * enough to store all of the data we estimated we would want to put into
760 * it, plus whatever general stuff (not specifically executor-related) the
761 * ParallelContext itself needs to store there. None of the space we
762 * asked for has been allocated or initialized yet, though, so do that.
763 */
764
765 /* Store fixed-size state. */
767 fpes->tuples_needed = tuples_needed;
768 fpes->param_exec = InvalidDsaPointer;
769 fpes->eflags = estate->es_top_eflags;
770 fpes->jit_flags = estate->es_jit_flags;
772
773 /* Store query string */
774 query_string = shm_toc_allocate(pcxt->toc, query_len + 1);
775 memcpy(query_string, estate->es_sourceText, query_len + 1);
776 shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, query_string);
777
778 /* Store serialized PlannedStmt. */
782
783 /* Store serialized ParamListInfo. */
787
788 /* Allocate space for each worker's BufferUsage; no need to initialize. */
790 mul_size(sizeof(BufferUsage), pcxt->nworkers));
793
794 /* Same for WalUsage. */
796 mul_size(sizeof(WalUsage), pcxt->nworkers));
799
800 /* Set up the tuple queues that the workers will write into. */
801 pei->tqueue = ExecParallelSetupTupleQueues(pcxt, false);
802
803 /* We don't need the TupleQueueReaders yet, though. */
804 pei->reader = NULL;
805
806 /*
807 * If instrumentation options were supplied, allocate space for the data.
808 * It only gets partially initialized here; the rest happens during
809 * ExecParallelInitializeDSM.
810 */
811 if (estate->es_instrument)
812 {
813 Instrumentation *instrument;
814 int i;
815
816 instrumentation = shm_toc_allocate(pcxt->toc, instrumentation_len);
817 instrumentation->instrument_options = estate->es_instrument;
818 instrumentation->instrument_offset = instrument_offset;
819 instrumentation->num_workers = nworkers;
820 instrumentation->num_plan_nodes = e.nnodes;
821 instrument = GetInstrumentationArray(instrumentation);
822 for (i = 0; i < nworkers * e.nnodes; ++i)
823 InstrInit(&instrument[i], estate->es_instrument);
825 instrumentation);
826 pei->instrumentation = instrumentation;
827
828 if (estate->es_jit_flags != PGJIT_NONE)
829 {
830 jit_instrumentation = shm_toc_allocate(pcxt->toc,
832 jit_instrumentation->num_workers = nworkers;
833 memset(jit_instrumentation->jit_instr, 0,
834 sizeof(JitInstrumentation) * nworkers);
836 jit_instrumentation);
837 pei->jit_instrumentation = jit_instrumentation;
838 }
839 }
840
841 /*
842 * Create a DSA area that can be used by the leader and all workers.
843 * (However, if we failed to create a DSM and are using private memory
844 * instead, then skip this.)
845 */
846 if (pcxt->seg != NULL)
847 {
848 char *area_space;
849
854 pcxt->seg);
855
856 /*
857 * Serialize parameters, if any, using DSA storage. We don't dare use
858 * the main parallel query DSM for this because we might relaunch
859 * workers after the values have changed (and thus the amount of
860 * storage required has changed).
861 */
863 {
865 pei->area);
866 fpes->param_exec = pei->param_exec;
867 }
868 }
869
870 /*
871 * Give parallel-aware nodes a chance to initialize their shared data.
872 * This also initializes the elements of instrumentation->ps_instrument,
873 * if it exists.
874 */
875 d.pcxt = pcxt;
876 d.instrumentation = instrumentation;
877 d.nnodes = 0;
878
879 /* Install our DSA area while initializing the plan. */
880 estate->es_query_dsa = pei->area;
881 ExecParallelInitializeDSM(planstate, &d);
882 estate->es_query_dsa = NULL;
883
884 /*
885 * Make sure that the world hasn't shifted under our feet. This could
886 * probably just be an Assert(), but let's be conservative for now.
887 */
888 if (e.nnodes != d.nnodes)
889 elog(ERROR, "inconsistent count of PlanState nodes");
890
891 /* OK, we're ready to rock and roll. */
892 return pei;
893}
void InitializeParallelDSM(ParallelContext *pcxt)
Definition parallel.c:211
ParallelContext * CreateParallelContext(const char *library_name, const char *function_name, int nworkers)
Definition parallel.c:173
#define bms_is_empty(a)
Definition bitmapset.h:118
#define MAXALIGN(LEN)
Definition c.h:826
#define Assert(condition)
Definition c.h:873
size_t Size
Definition c.h:619
size_t dsa_minimum_size(void)
Definition dsa.c:1246
#define dsa_create_in_place(place, size, tranche_id, segment)
Definition dsa.h:122
#define InvalidDsaPointer
Definition dsa.h:78
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define PARALLEL_KEY_BUFFER_USAGE
#define PARALLEL_KEY_JIT_INSTRUMENTATION
#define PARALLEL_KEY_PARAMLISTINFO
#define PARALLEL_TUPLE_QUEUE_SIZE
static dsa_pointer SerializeParamExecParams(EState *estate, Bitmapset *params, dsa_area *area)
#define PARALLEL_KEY_INSTRUMENTATION
static shm_mq_handle ** ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize)
#define PARALLEL_KEY_PLANNEDSTMT
static bool ExecParallelEstimate(PlanState *planstate, ExecParallelEstimateContext *e)
#define GetInstrumentationArray(sei)
#define PARALLEL_KEY_DSA
#define PARALLEL_KEY_EXECUTOR_FIXED
static char * ExecSerializePlan(Plan *plan, EState *estate)
#define PARALLEL_KEY_QUERY_TEXT
#define PARALLEL_KEY_WAL_USAGE
static bool ExecParallelInitializeDSM(PlanState *planstate, ExecParallelInitializeDSMContext *d)
#define GetPerTupleExprContext(estate)
Definition executor.h:656
#define palloc0_object(type)
Definition fe_memutils.h:75
void InstrInit(Instrumentation *instr, int instrument_options)
Definition instrument.c:58
int i
Definition isn.c:77
#define PGJIT_NONE
Definition jit.h:19
void ExecSetParamPlanMulti(const Bitmapset *params, ExprContext *econtext)
Size EstimateParamListSpace(ParamListInfo paramLI)
Definition params.c:167
void SerializeParamList(ParamListInfo paramLI, char **start_address)
Definition params.c:228
e
static int fb(int x)
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition shm_toc.c:171
#define shm_toc_estimate_chunk(e, sz)
Definition shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition shm_toc.h:53
Size mul_size(Size s1, Size s2)
Definition shmem.c:510
Snapshot GetActiveSnapshot(void)
Definition snapmgr.c:800
struct dsa_area * es_query_dsa
Definition execnodes.h:754
int es_top_eflags
Definition execnodes.h:721
int es_instrument
Definition execnodes.h:722
ParamListInfo es_param_list_info
Definition execnodes.h:706
int es_jit_flags
Definition execnodes.h:765
const char * es_sourceText
Definition execnodes.h:679
Snapshot es_snapshot
Definition execnodes.h:662
SharedExecutorInstrumentation * instrumentation
dsm_segment * seg
Definition parallel.h:42
shm_toc_estimator estimator
Definition parallel.h:41
shm_toc * toc
Definition parallel.h:44
PlanState * planstate
struct SharedJitInstrumentation * jit_instrumentation
BufferUsage * buffer_usage
dsa_pointer param_exec
ParallelContext * pcxt
shm_mq_handle ** tqueue
SharedExecutorInstrumentation * instrumentation
struct TupleQueueReader ** reader
Plan * plan
Definition execnodes.h:1167
JitInstrumentation jit_instr[FLEXIBLE_ARRAY_MEMBER]
Definition jit.h:54

References ParallelExecutorInfo::area, Assert, bms_is_empty, ParallelExecutorInfo::buffer_usage, CreateParallelContext(), dsa_create_in_place, dsa_minimum_size(), elog, ERROR, EState::es_instrument, EState::es_jit_flags, EState::es_param_list_info, EState::es_query_dsa, EState::es_snapshot, EState::es_sourceText, EState::es_top_eflags, EstimateParamListSpace(), ParallelContext::estimator, ExecParallelEstimate(), ExecParallelInitializeDSM(), ExecParallelSetupTupleQueues(), ExecSerializePlan(), ExecSetParamPlanMulti(), fb(), ParallelExecutorInfo::finished, GetActiveSnapshot(), GetInstrumentationArray, GetPerTupleExprContext, i, InitializeParallelDSM(), InstrInit(), SharedExecutorInstrumentation::instrument_offset, SharedExecutorInstrumentation::instrument_options, ExecParallelInitializeDSMContext::instrumentation, ParallelExecutorInfo::instrumentation, InvalidDsaPointer, SharedJitInstrumentation::jit_instr, ParallelExecutorInfo::jit_instrumentation, MAXALIGN, mul_size(), ExecParallelInitializeDSMContext::nnodes, SharedExecutorInstrumentation::num_plan_nodes, SharedExecutorInstrumentation::num_workers, SharedJitInstrumentation::num_workers, ParallelContext::nworkers, palloc0_object, PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_DSA, PARALLEL_KEY_EXECUTOR_FIXED, PARALLEL_KEY_INSTRUMENTATION, PARALLEL_KEY_JIT_INSTRUMENTATION, PARALLEL_KEY_PARAMLISTINFO, PARALLEL_KEY_PLANNEDSTMT, PARALLEL_KEY_QUERY_TEXT, PARALLEL_KEY_WAL_USAGE, PARALLEL_TUPLE_QUEUE_SIZE, ParallelExecutorInfo::param_exec, ExecParallelInitializeDSMContext::pcxt, ParallelExecutorInfo::pcxt, PGJIT_NONE, PlanState::plan, ParallelExecutorInfo::planstate, ParallelExecutorInfo::reader, ParallelContext::seg, SerializeParamExecParams(), SerializeParamList(), shm_toc_allocate(), shm_toc_estimate_chunk, shm_toc_estimate_keys, shm_toc_insert(), ParallelContext::toc, ParallelExecutorInfo::tqueue, and ParallelExecutorInfo::wal_usage.

Referenced by ExecGather(), and ExecGatherMerge().

◆ ExecParallelCleanup()

void ExecParallelCleanup ( ParallelExecutorInfo pei)
extern

Definition at line 1226 of file execParallel.c.

1227{
1228 /* Accumulate instrumentation, if any. */
1229 if (pei->instrumentation)
1231 pei->instrumentation);
1232
1233 /* Accumulate JIT instrumentation, if any. */
1234 if (pei->jit_instrumentation)
1236 pei->jit_instrumentation);
1237
1238 /* Free any serialized parameters. */
1239 if (DsaPointerIsValid(pei->param_exec))
1240 {
1241 dsa_free(pei->area, pei->param_exec);
1243 }
1244 if (pei->area != NULL)
1245 {
1246 dsa_detach(pei->area);
1247 pei->area = NULL;
1248 }
1249 if (pei->pcxt != NULL)
1250 {
1252 pei->pcxt = NULL;
1253 }
1254 pfree(pei);
1255}
void DestroyParallelContext(ParallelContext *pcxt)
Definition parallel.c:957
void dsa_detach(dsa_area *area)
Definition dsa.c:2002
void dsa_free(dsa_area *area, dsa_pointer dp)
Definition dsa.c:841
#define DsaPointerIsValid(x)
Definition dsa.h:106
static bool ExecParallelRetrieveInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
static void ExecParallelRetrieveJitInstrumentation(PlanState *planstate, SharedJitInstrumentation *shared_jit)
void pfree(void *pointer)
Definition mcxt.c:1616

References ParallelExecutorInfo::area, DestroyParallelContext(), dsa_detach(), dsa_free(), DsaPointerIsValid, ExecParallelRetrieveInstrumentation(), ExecParallelRetrieveJitInstrumentation(), fb(), ParallelExecutorInfo::instrumentation, InvalidDsaPointer, ParallelExecutorInfo::jit_instrumentation, ParallelExecutorInfo::param_exec, ParallelExecutorInfo::pcxt, pfree(), and ParallelExecutorInfo::planstate.

Referenced by ExecShutdownGather(), and ExecShutdownGatherMerge().

◆ ExecParallelCreateReaders()

void ExecParallelCreateReaders ( ParallelExecutorInfo pei)
extern

Definition at line 902 of file execParallel.c.

903{
904 int nworkers = pei->pcxt->nworkers_launched;
905 int i;
906
907 Assert(pei->reader == NULL);
908
909 if (nworkers > 0)
910 {
911 pei->reader = (TupleQueueReader **)
912 palloc(nworkers * sizeof(TupleQueueReader *));
913
914 for (i = 0; i < nworkers; i++)
915 {
917 pei->pcxt->worker[i].bgwhandle);
918 pei->reader[i] = CreateTupleQueueReader(pei->tqueue[i]);
919 }
920 }
921}
void * palloc(Size size)
Definition mcxt.c:1387
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition shm_mq.c:319
ParallelWorkerInfo * worker
Definition parallel.h:45
int nworkers_launched
Definition parallel.h:37
BackgroundWorkerHandle * bgwhandle
Definition parallel.h:27
TupleQueueReader * CreateTupleQueueReader(shm_mq_handle *handle)
Definition tqueue.c:139

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

Referenced by ExecGather(), and ExecGatherMerge().

◆ ExecParallelFinish()

void ExecParallelFinish ( ParallelExecutorInfo pei)
extern

Definition at line 1173 of file execParallel.c.

1174{
1175 int nworkers = pei->pcxt->nworkers_launched;
1176 int i;
1177
1178 /* Make this be a no-op if called twice in a row. */
1179 if (pei->finished)
1180 return;
1181
1182 /*
1183 * Detach from tuple queues ASAP, so that any still-active workers will
1184 * notice that no further results are wanted.
1185 */
1186 if (pei->tqueue != NULL)
1187 {
1188 for (i = 0; i < nworkers; i++)
1189 shm_mq_detach(pei->tqueue[i]);
1190 pfree(pei->tqueue);
1191 pei->tqueue = NULL;
1192 }
1193
1194 /*
1195 * While we're waiting for the workers to finish, let's get rid of the
1196 * tuple queue readers. (Any other local cleanup could be done here too.)
1197 */
1198 if (pei->reader != NULL)
1199 {
1200 for (i = 0; i < nworkers; i++)
1202 pfree(pei->reader);
1203 pei->reader = NULL;
1204 }
1205
1206 /* Now wait for the workers to finish. */
1208
1209 /*
1210 * Next, accumulate buffer/WAL usage. (This must wait for the workers to
1211 * finish, or we might get incomplete data.)
1212 */
1213 for (i = 0; i < nworkers; i++)
1215
1216 pei->finished = true;
1217}
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition parallel.c:803
void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition instrument.c:215
void shm_mq_detach(shm_mq_handle *mqh)
Definition shm_mq.c:843
void DestroyTupleQueueReader(TupleQueueReader *reader)
Definition tqueue.c:155

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

Referenced by ExecShutdownGatherMergeWorkers(), and ExecShutdownGatherWorkers().

◆ ExecParallelReinitialize()

void ExecParallelReinitialize ( PlanState planstate,
ParallelExecutorInfo pei,
Bitmapset sendParams 
)
extern

Definition at line 928 of file execParallel.c.

931{
932 EState *estate = planstate->state;
934
935 /* Old workers must already be shut down */
936 Assert(pei->finished);
937
938 /*
939 * Force any initplan outputs that we're going to pass to workers to be
940 * evaluated, if they weren't already (see comments in
941 * ExecInitParallelPlan).
942 */
944
946 pei->tqueue = ExecParallelSetupTupleQueues(pei->pcxt, true);
947 pei->reader = NULL;
948 pei->finished = false;
949
951
952 /* Free any serialized parameters from the last round. */
953 if (DsaPointerIsValid(fpes->param_exec))
954 {
955 dsa_free(pei->area, fpes->param_exec);
956 fpes->param_exec = InvalidDsaPointer;
957 }
958
959 /* Serialize current parameter values if required. */
961 {
963 pei->area);
964 fpes->param_exec = pei->param_exec;
965 }
966
967 /* Traverse plan tree and let each child node reset associated state. */
968 estate->es_query_dsa = pei->area;
969 ExecParallelReInitializeDSM(planstate, pei->pcxt);
970 estate->es_query_dsa = NULL;
971}
void ReinitializeParallelDSM(ParallelContext *pcxt)
Definition parallel.c:509
static bool ExecParallelReInitializeDSM(PlanState *planstate, ParallelContext *pcxt)
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition shm_toc.c:232
EState * state
Definition execnodes.h:1169

References ParallelExecutorInfo::area, Assert, bms_is_empty, dsa_free(), DsaPointerIsValid, EState::es_query_dsa, ExecParallelReInitializeDSM(), ExecParallelSetupTupleQueues(), ExecSetParamPlanMulti(), fb(), ParallelExecutorInfo::finished, GetPerTupleExprContext, InvalidDsaPointer, PARALLEL_KEY_EXECUTOR_FIXED, ParallelExecutorInfo::param_exec, ParallelExecutorInfo::pcxt, ParallelExecutorInfo::reader, ReinitializeParallelDSM(), SerializeParamExecParams(), shm_toc_lookup(), PlanState::state, ParallelContext::toc, and ParallelExecutorInfo::tqueue.

Referenced by ExecGather(), and ExecGatherMerge().

◆ ParallelQueryMain()

void ParallelQueryMain ( dsm_segment seg,
shm_toc toc 
)
extern

Definition at line 1451 of file execParallel.c.

1452{
1454 BufferUsage *buffer_usage;
1455 WalUsage *wal_usage;
1457 QueryDesc *queryDesc;
1458 SharedExecutorInstrumentation *instrumentation;
1459 SharedJitInstrumentation *jit_instrumentation;
1460 int instrument_options = 0;
1461 void *area_space;
1462 dsa_area *area;
1464
1465 /* Get fixed-size state. */
1467
1468 /* Set up DestReceiver, SharedExecutorInstrumentation, and QueryDesc. */
1470 instrumentation = shm_toc_lookup(toc, PARALLEL_KEY_INSTRUMENTATION, true);
1471 if (instrumentation != NULL)
1472 instrument_options = instrumentation->instrument_options;
1473 jit_instrumentation = shm_toc_lookup(toc, PARALLEL_KEY_JIT_INSTRUMENTATION,
1474 true);
1475 queryDesc = ExecParallelGetQueryDesc(toc, receiver, instrument_options);
1476
1477 /* Setting debug_query_string for individual workers */
1478 debug_query_string = queryDesc->sourceText;
1479
1480 /* Report workers' query for monitoring purposes */
1482
1483 /* Attach to the dynamic shared memory area. */
1485 area = dsa_attach_in_place(area_space, seg);
1486
1487 /* Start up the executor */
1488 queryDesc->plannedstmt->jitFlags = fpes->jit_flags;
1489 ExecutorStart(queryDesc, fpes->eflags);
1490
1491 /* Special executor initialization steps for parallel workers */
1492 queryDesc->planstate->state->es_query_dsa = area;
1493 if (DsaPointerIsValid(fpes->param_exec))
1494 {
1495 char *paramexec_space;
1496
1497 paramexec_space = dsa_get_address(area, fpes->param_exec);
1499 }
1500 pwcxt.toc = toc;
1501 pwcxt.seg = seg;
1503
1504 /* Pass down any tuple bound */
1505 ExecSetTupleBound(fpes->tuples_needed, queryDesc->planstate);
1506
1507 /*
1508 * Prepare to track buffer/WAL usage during query execution.
1509 *
1510 * We do this after starting up the executor to match what happens in the
1511 * leader, which also doesn't count buffer accesses and WAL activity that
1512 * occur during executor startup.
1513 */
1515
1516 /*
1517 * Run the plan. If we specified a tuple bound, be careful not to demand
1518 * more tuples than that.
1519 */
1520 ExecutorRun(queryDesc,
1522 fpes->tuples_needed < 0 ? (int64) 0 : fpes->tuples_needed);
1523
1524 /* Shut down the executor */
1525 ExecutorFinish(queryDesc);
1526
1527 /* Report buffer/WAL usage during parallel execution. */
1528 buffer_usage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
1529 wal_usage = shm_toc_lookup(toc, PARALLEL_KEY_WAL_USAGE, false);
1531 &wal_usage[ParallelWorkerNumber]);
1532
1533 /* Report instrumentation data if any instrumentation options are set. */
1534 if (instrumentation != NULL)
1536 instrumentation);
1537
1538 /* Report JIT instrumentation data if any */
1539 if (queryDesc->estate->es_jit && jit_instrumentation != NULL)
1540 {
1542 jit_instrumentation->jit_instr[ParallelWorkerNumber] =
1543 queryDesc->estate->es_jit->instr;
1544 }
1545
1546 /* Must do this after capturing instrumentation. */
1547 ExecutorEnd(queryDesc);
1548
1549 /* Cleanup. */
1550 dsa_detach(area);
1551 FreeQueryDesc(queryDesc);
1552 receiver->rDestroy(receiver);
1553}
int ParallelWorkerNumber
Definition parallel.c:115
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
int64_t int64
Definition c.h:543
dsa_area * dsa_attach_in_place(void *place, dsm_segment *segment)
Definition dsa.c:560
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition dsa.c:957
void ExecutorEnd(QueryDesc *queryDesc)
Definition execMain.c:466
void ExecutorFinish(QueryDesc *queryDesc)
Definition execMain.c:406
void ExecutorStart(QueryDesc *queryDesc, int eflags)
Definition execMain.c:122
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
Definition execMain.c:297
static QueryDesc * ExecParallelGetQueryDesc(shm_toc *toc, DestReceiver *receiver, int instrument_options)
static DestReceiver * ExecParallelGetReceiver(dsm_segment *seg, shm_toc *toc)
static bool ExecParallelInitializeWorker(PlanState *planstate, ParallelWorkerContext *pwcxt)
static bool ExecParallelReportInstrumentation(PlanState *planstate, SharedExecutorInstrumentation *instrumentation)
static void RestoreParamExecParams(char *start_address, EState *estate)
void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node)
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition instrument.c:205
void InstrStartParallelQuery(void)
Definition instrument.c:197
const char * debug_query_string
Definition postgres.c:89
void FreeQueryDesc(QueryDesc *qdesc)
Definition pquery.c:106
@ ForwardScanDirection
Definition sdir.h:28
struct JitContext * es_jit
Definition execnodes.h:766
JitInstrumentation instr
Definition jit.h:62
const char * sourceText
Definition execdesc.h:38
EState * estate
Definition execdesc.h:48
PlannedStmt * plannedstmt
Definition execdesc.h:37
PlanState * planstate
Definition execdesc.h:49

References Assert, debug_query_string, dsa_attach_in_place(), dsa_detach(), dsa_get_address(), DsaPointerIsValid, EState::es_jit, EState::es_query_dsa, QueryDesc::estate, ExecParallelGetQueryDesc(), ExecParallelGetReceiver(), ExecParallelInitializeWorker(), ExecParallelReportInstrumentation(), ExecSetTupleBound(), ExecutorEnd(), ExecutorFinish(), ExecutorRun(), ExecutorStart(), fb(), ForwardScanDirection, FreeQueryDesc(), JitContext::instr, InstrEndParallelQuery(), InstrStartParallelQuery(), SharedExecutorInstrumentation::instrument_options, SharedJitInstrumentation::jit_instr, PlannedStmt::jitFlags, PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_DSA, PARALLEL_KEY_EXECUTOR_FIXED, PARALLEL_KEY_INSTRUMENTATION, PARALLEL_KEY_JIT_INSTRUMENTATION, PARALLEL_KEY_WAL_USAGE, ParallelWorkerNumber, pgstat_report_activity(), QueryDesc::plannedstmt, QueryDesc::planstate, RestoreParamExecParams(), shm_toc_lookup(), QueryDesc::sourceText, PlanState::state, and STATE_RUNNING.