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 653 of file execParallel.c.

656{
658 ParallelContext *pcxt;
662 char *pstmt_data;
663 char *pstmt_space;
667 SharedExecutorInstrumentation *instrumentation = NULL;
668 SharedJitInstrumentation *jit_instrumentation = NULL;
669 int pstmt_len;
671 int instrumentation_len = 0;
673 int instrument_offset = 0;
675 char *query_string;
676 int query_len;
677
678 /*
679 * Force any initplan outputs that we're going to pass to workers to be
680 * evaluated, if they weren't already.
681 *
682 * For simplicity, we use the EState's per-output-tuple ExprContext here.
683 * That risks intra-query memory leakage, since we might pass through here
684 * many times before that ExprContext gets reset; but ExecSetParamPlan
685 * doesn't normally leak any memory in the context (see its comments), so
686 * it doesn't seem worth complicating this function's API to pass it a
687 * shorter-lived ExprContext. This might need to change someday.
688 */
690
691 /* Allocate object for return value. */
693 pei->finished = false;
694 pei->planstate = planstate;
695
696 /* Fix up and serialize plan to be sent to workers. */
697 pstmt_data = ExecSerializePlan(planstate->plan, estate);
698
699 /* Create a parallel context. */
700 pcxt = CreateParallelContext("postgres", "ParallelQueryMain", nworkers);
701 pei->pcxt = pcxt;
702
703 /*
704 * Before telling the parallel context to create a dynamic shared memory
705 * segment, we need to figure out how big it should be. Estimate space
706 * for the various things we need to store.
707 */
708
709 /* Estimate space for fixed-size state. */
713
714 /* Estimate space for query text. */
715 query_len = strlen(estate->es_sourceText);
716 shm_toc_estimate_chunk(&pcxt->estimator, query_len + 1);
718
719 /* Estimate space for serialized PlannedStmt. */
723
724 /* Estimate space for serialized ParamListInfo. */
728
729 /*
730 * Estimate space for BufferUsage.
731 *
732 * If EXPLAIN is not in use and there are no extensions loaded that care,
733 * we could skip this. But we have no way of knowing whether anyone's
734 * looking at pgBufferUsage, so do it unconditionally.
735 */
737 mul_size(sizeof(BufferUsage), pcxt->nworkers));
739
740 /*
741 * Same thing for WalUsage.
742 */
744 mul_size(sizeof(WalUsage), pcxt->nworkers));
746
747 /* Estimate space for tuple queues. */
751
752 /*
753 * Give parallel-aware nodes a chance to add to the estimates, and get a
754 * count of how many PlanState nodes there are.
755 */
756 e.pcxt = pcxt;
757 e.nnodes = 0;
758 ExecParallelEstimate(planstate, &e);
759
760 /* Estimate space for instrumentation, if required. */
761 if (estate->es_instrument)
762 {
765 sizeof(int) * e.nnodes;
767 instrument_offset = instrumentation_len;
770 mul_size(e.nnodes, nworkers));
773
774 /* Estimate space for JIT instrumentation, if required. */
775 if (estate->es_jit_flags != PGJIT_NONE)
776 {
779 sizeof(JitInstrumentation) * nworkers;
782 }
783 }
784
785 /* Estimate space for DSA area. */
788
789 /*
790 * InitializeParallelDSM() passes the active snapshot to the parallel
791 * worker, which uses it to set es_snapshot. Make sure we don't set
792 * es_snapshot differently in the child.
793 */
795
796 /* Everyone's had a chance to ask for space, so now create the DSM. */
798
799 /*
800 * OK, now we have a dynamic shared memory segment, and it should be big
801 * enough to store all of the data we estimated we would want to put into
802 * it, plus whatever general stuff (not specifically executor-related) the
803 * ParallelContext itself needs to store there. None of the space we
804 * asked for has been allocated or initialized yet, though, so do that.
805 */
806
807 /* Store fixed-size state. */
809 fpes->tuples_needed = tuples_needed;
810 fpes->param_exec = InvalidDsaPointer;
811 fpes->eflags = estate->es_top_eflags;
812 fpes->jit_flags = estate->es_jit_flags;
814
815 /* Store query string */
816 query_string = shm_toc_allocate(pcxt->toc, query_len + 1);
817 memcpy(query_string, estate->es_sourceText, query_len + 1);
818 shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, query_string);
819
820 /* Store serialized PlannedStmt. */
824
825 /* Store serialized ParamListInfo. */
829
830 /* Allocate space for each worker's BufferUsage; no need to initialize. */
832 mul_size(sizeof(BufferUsage), pcxt->nworkers));
835
836 /* Same for WalUsage. */
838 mul_size(sizeof(WalUsage), pcxt->nworkers));
841
842 /* Set up the tuple queues that the workers will write into. */
843 pei->tqueue = ExecParallelSetupTupleQueues(pcxt, false);
844
845 /* We don't need the TupleQueueReaders yet, though. */
846 pei->reader = NULL;
847
848 /*
849 * If instrumentation options were supplied, allocate space for the data.
850 * It only gets partially initialized here; the rest happens during
851 * ExecParallelInitializeDSM.
852 */
853 if (estate->es_instrument)
854 {
855 NodeInstrumentation *instrument;
856 int i;
857
858 instrumentation = shm_toc_allocate(pcxt->toc, instrumentation_len);
859 instrumentation->instrument_options = estate->es_instrument;
860 instrumentation->instrument_offset = instrument_offset;
861 instrumentation->num_workers = nworkers;
862 instrumentation->num_plan_nodes = e.nnodes;
863 instrument = GetInstrumentationArray(instrumentation);
864 for (i = 0; i < nworkers * e.nnodes; ++i)
865 InstrInitNode(&instrument[i], estate->es_instrument, false);
867 instrumentation);
868 pei->instrumentation = instrumentation;
869
870 if (estate->es_jit_flags != PGJIT_NONE)
871 {
872 jit_instrumentation = shm_toc_allocate(pcxt->toc,
874 jit_instrumentation->num_workers = nworkers;
875 memset(jit_instrumentation->jit_instr, 0,
876 sizeof(JitInstrumentation) * nworkers);
878 jit_instrumentation);
879 pei->jit_instrumentation = jit_instrumentation;
880 }
881 }
882
883 /*
884 * Create a DSA area that can be used by the leader and all workers.
885 * (However, if we failed to create a DSM and are using private memory
886 * instead, then skip this.)
887 */
888 if (pcxt->seg != NULL)
889 {
890 char *area_space;
891
896 pcxt->seg);
897
898 /*
899 * Serialize parameters, if any, using DSA storage. We don't dare use
900 * the main parallel query DSM for this because we might relaunch
901 * workers after the values have changed (and thus the amount of
902 * storage required has changed).
903 */
905 {
907 pei->area);
908 fpes->param_exec = pei->param_exec;
909 }
910 }
911
912 /*
913 * Give parallel-aware nodes a chance to initialize their shared data.
914 * This also initializes the elements of instrumentation->ps_instrument,
915 * if it exists.
916 */
917 d.pcxt = pcxt;
918 d.instrumentation = instrumentation;
919 d.nnodes = 0;
920
921 /* Install our DSA area while initializing the plan. */
922 estate->es_query_dsa = pei->area;
923 ExecParallelInitializeDSM(planstate, &d);
924 estate->es_query_dsa = NULL;
925
926 /*
927 * Make sure that the world hasn't shifted under our feet. This could
928 * probably just be an Assert(), but let's be conservative for now.
929 */
930 if (e.nnodes != d.nnodes)
931 elog(ERROR, "inconsistent count of PlanState nodes");
932
933 /* OK, we're ready to rock and roll. */
934 return pei;
935}
void InitializeParallelDSM(ParallelContext *pcxt)
Definition parallel.c:213
ParallelContext * CreateParallelContext(const char *library_name, const char *function_name, int nworkers)
Definition parallel.c:175
#define bms_is_empty(a)
Definition bitmapset.h:118
#define MAXALIGN(LEN)
Definition c.h:896
#define Assert(condition)
Definition c.h:943
size_t Size
Definition c.h:689
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
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:40
#define elog(elevel,...)
Definition elog.h:228
#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:667
#define palloc0_object(type)
Definition fe_memutils.h:75
void InstrInitNode(NodeInstrumentation *instr, int instrument_options, bool async_mode)
Definition instrument.c:123
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:1063
Snapshot GetActiveSnapshot(void)
Definition snapmgr.c:800
struct dsa_area * es_query_dsa
Definition execnodes.h:788
int es_top_eflags
Definition execnodes.h:755
int es_instrument
Definition execnodes.h:756
ParamListInfo es_param_list_info
Definition execnodes.h:740
int es_jit_flags
Definition execnodes.h:799
const char * es_sourceText
Definition execnodes.h:713
Snapshot es_snapshot
Definition execnodes.h:696
SharedExecutorInstrumentation * instrumentation
dsm_segment * seg
Definition parallel.h:44
shm_toc_estimator estimator
Definition parallel.h:43
shm_toc * toc
Definition parallel.h:46
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:1201
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(), InstrInitNode(), SharedExecutorInstrumentation::instrument_offset, SharedExecutorInstrumentation::instrument_options, ExecParallelInitializeDSMContext::instrumentation, ParallelExecutorInfo::instrumentation, InvalidDsaPointer, SharedJitInstrumentation::jit_instr, ParallelExecutorInfo::jit_instrumentation, MAXALIGN, memcpy(), 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 1274 of file execParallel.c.

1275{
1276 /* Accumulate instrumentation, if any. */
1277 if (pei->instrumentation)
1279 pei->instrumentation);
1280
1281 /* Accumulate JIT instrumentation, if any. */
1282 if (pei->jit_instrumentation)
1284 pei->jit_instrumentation);
1285
1286 /* Free any serialized parameters. */
1287 if (DsaPointerIsValid(pei->param_exec))
1288 {
1289 dsa_free(pei->area, pei->param_exec);
1291 }
1292 if (pei->area != NULL)
1293 {
1294 dsa_detach(pei->area);
1295 pei->area = NULL;
1296 }
1297 if (pei->pcxt != NULL)
1298 {
1300 pei->pcxt = NULL;
1301 }
1302 pfree(pei);
1303}
void DestroyParallelContext(ParallelContext *pcxt)
Definition parallel.c:959
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 944 of file execParallel.c.

945{
946 int nworkers = pei->pcxt->nworkers_launched;
947 int i;
948
949 Assert(pei->reader == NULL);
950
951 if (nworkers > 0)
952 {
953 pei->reader = (TupleQueueReader **)
954 palloc(nworkers * sizeof(TupleQueueReader *));
955
956 for (i = 0; i < nworkers; i++)
957 {
959 pei->pcxt->worker[i].bgwhandle);
960 pei->reader[i] = CreateTupleQueueReader(pei->tqueue[i]);
961 }
962 }
963}
void * palloc(Size size)
Definition mcxt.c:1387
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition shm_mq.c:321
ParallelWorkerInfo * worker
Definition parallel.h:47
int nworkers_launched
Definition parallel.h:39
BackgroundWorkerHandle * bgwhandle
Definition parallel.h:29
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 1221 of file execParallel.c.

1222{
1223 int nworkers = pei->pcxt->nworkers_launched;
1224 int i;
1225
1226 /* Make this be a no-op if called twice in a row. */
1227 if (pei->finished)
1228 return;
1229
1230 /*
1231 * Detach from tuple queues ASAP, so that any still-active workers will
1232 * notice that no further results are wanted.
1233 */
1234 if (pei->tqueue != NULL)
1235 {
1236 for (i = 0; i < nworkers; i++)
1237 shm_mq_detach(pei->tqueue[i]);
1238 pfree(pei->tqueue);
1239 pei->tqueue = NULL;
1240 }
1241
1242 /*
1243 * While we're waiting for the workers to finish, let's get rid of the
1244 * tuple queue readers. (Any other local cleanup could be done here too.)
1245 */
1246 if (pei->reader != NULL)
1247 {
1248 for (i = 0; i < nworkers; i++)
1250 pfree(pei->reader);
1251 pei->reader = NULL;
1252 }
1253
1254 /* Now wait for the workers to finish. */
1256
1257 /*
1258 * Next, accumulate buffer/WAL usage. (This must wait for the workers to
1259 * finish, or we might get incomplete data.)
1260 */
1261 for (i = 0; i < nworkers; i++)
1263
1264 pei->finished = true;
1265}
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition parallel.c:805
void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition instrument.c:297
void shm_mq_detach(shm_mq_handle *mqh)
Definition shm_mq.c:845
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 970 of file execParallel.c.

973{
974 EState *estate = planstate->state;
976
977 /* Old workers must already be shut down */
978 Assert(pei->finished);
979
980 /*
981 * Force any initplan outputs that we're going to pass to workers to be
982 * evaluated, if they weren't already (see comments in
983 * ExecInitParallelPlan).
984 */
986
988 pei->tqueue = ExecParallelSetupTupleQueues(pei->pcxt, true);
989 pei->reader = NULL;
990 pei->finished = false;
991
993
994 /* Free any serialized parameters from the last round. */
995 if (DsaPointerIsValid(fpes->param_exec))
996 {
997 dsa_free(pei->area, fpes->param_exec);
998 fpes->param_exec = InvalidDsaPointer;
999 }
1000
1001 /* Serialize current parameter values if required. */
1003 {
1005 pei->area);
1006 fpes->param_exec = pei->param_exec;
1007 }
1008
1009 /* Traverse plan tree and let each child node reset associated state. */
1010 estate->es_query_dsa = pei->area;
1011 ExecParallelReInitializeDSM(planstate, pei->pcxt);
1012 estate->es_query_dsa = NULL;
1013}
void ReinitializeParallelDSM(ParallelContext *pcxt)
Definition parallel.c:511
static bool ExecParallelReInitializeDSM(PlanState *planstate, ParallelContext *pcxt)
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition shm_toc.c:239
EState * state
Definition execnodes.h:1203

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 1514 of file execParallel.c.

1515{
1517 BufferUsage *buffer_usage;
1518 WalUsage *wal_usage;
1520 QueryDesc *queryDesc;
1521 SharedExecutorInstrumentation *instrumentation;
1522 SharedJitInstrumentation *jit_instrumentation;
1523 int instrument_options = 0;
1524 void *area_space;
1525 dsa_area *area;
1527
1528 /* Get fixed-size state. */
1530
1531 /* Set up DestReceiver, SharedExecutorInstrumentation, and QueryDesc. */
1533 instrumentation = shm_toc_lookup(toc, PARALLEL_KEY_INSTRUMENTATION, true);
1534 if (instrumentation != NULL)
1535 instrument_options = instrumentation->instrument_options;
1536 jit_instrumentation = shm_toc_lookup(toc, PARALLEL_KEY_JIT_INSTRUMENTATION,
1537 true);
1538 queryDesc = ExecParallelGetQueryDesc(toc, receiver, instrument_options);
1539
1540 /* Setting debug_query_string for individual workers */
1541 debug_query_string = queryDesc->sourceText;
1542
1543 /* Report workers' query for monitoring purposes */
1545
1546 /* Attach to the dynamic shared memory area. */
1548 area = dsa_attach_in_place(area_space, seg);
1549
1550 /* Start up the executor */
1551 queryDesc->plannedstmt->jitFlags = fpes->jit_flags;
1552 ExecutorStart(queryDesc, fpes->eflags);
1553
1554 /* Special executor initialization steps for parallel workers */
1555 queryDesc->planstate->state->es_query_dsa = area;
1556 if (DsaPointerIsValid(fpes->param_exec))
1557 {
1558 char *paramexec_space;
1559
1560 paramexec_space = dsa_get_address(area, fpes->param_exec);
1562 }
1563 pwcxt.toc = toc;
1564 pwcxt.seg = seg;
1566
1567 /* Pass down any tuple bound */
1568 ExecSetTupleBound(fpes->tuples_needed, queryDesc->planstate);
1569
1570 /*
1571 * Prepare to track buffer/WAL usage during query execution.
1572 *
1573 * We do this after starting up the executor to match what happens in the
1574 * leader, which also doesn't count buffer accesses and WAL activity that
1575 * occur during executor startup.
1576 */
1578
1579 /*
1580 * Run the plan. If we specified a tuple bound, be careful not to demand
1581 * more tuples than that.
1582 */
1583 ExecutorRun(queryDesc,
1585 fpes->tuples_needed < 0 ? (int64) 0 : fpes->tuples_needed);
1586
1587 /* Shut down the executor */
1588 ExecutorFinish(queryDesc);
1589
1590 /* Report buffer/WAL usage during parallel execution. */
1591 buffer_usage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
1592 wal_usage = shm_toc_lookup(toc, PARALLEL_KEY_WAL_USAGE, false);
1594 &wal_usage[ParallelWorkerNumber]);
1595
1596 /* Report instrumentation data if any instrumentation options are set. */
1597 if (instrumentation != NULL)
1599 instrumentation);
1600
1601 /* Report JIT instrumentation data if any */
1602 if (queryDesc->estate->es_jit && jit_instrumentation != NULL)
1603 {
1605 jit_instrumentation->jit_instr[ParallelWorkerNumber] =
1606 queryDesc->estate->es_jit->instr;
1607 }
1608
1609 /* Must do this after capturing instrumentation. */
1610 ExecutorEnd(queryDesc);
1611
1612 /* Cleanup. */
1613 dsa_detach(area);
1614 FreeQueryDesc(queryDesc);
1615 receiver->rDestroy(receiver);
1616}
int ParallelWorkerNumber
Definition parallel.c:117
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
int64_t int64
Definition c.h:621
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:477
void ExecutorFinish(QueryDesc *queryDesc)
Definition execMain.c:417
void ExecutorStart(QueryDesc *queryDesc, int eflags)
Definition execMain.c:124
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
Definition execMain.c:308
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:287
void InstrStartParallelQuery(void)
Definition instrument.c:279
const char * debug_query_string
Definition postgres.c:94
void FreeQueryDesc(QueryDesc *qdesc)
Definition pquery.c:107
@ ForwardScanDirection
Definition sdir.h:28
struct JitContext * es_jit
Definition execnodes.h:800
JitInstrumentation instr
Definition jit.h:62
const char * sourceText
Definition execdesc.h:38
EState * estate
Definition execdesc.h:50
PlannedStmt * plannedstmt
Definition execdesc.h:37
PlanState * planstate
Definition execdesc.h:51

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.