PostgreSQL Source Code  git master
nodeAppend.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
Include dependency graph for nodeAppend.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

AppendStateExecInitAppend (Append *node, EState *estate, int eflags)
 
void ExecEndAppend (AppendState *node)
 
void ExecReScanAppend (AppendState *node)
 
void ExecAppendEstimate (AppendState *node, ParallelContext *pcxt)
 
void ExecAppendInitializeDSM (AppendState *node, ParallelContext *pcxt)
 
void ExecAppendReInitializeDSM (AppendState *node, ParallelContext *pcxt)
 
void ExecAppendInitializeWorker (AppendState *node, ParallelWorkerContext *pwcxt)
 
void ExecAsyncAppendResponse (AsyncRequest *areq)
 

Function Documentation

◆ ExecAppendEstimate()

void ExecAppendEstimate ( AppendState node,
ParallelContext pcxt 
)

Definition at line 484 of file nodeAppend.c.

486 {
487  node->pstate_len =
488  add_size(offsetof(ParallelAppendState, pa_finished),
489  sizeof(bool) * node->as_nplans);
490 
492  shm_toc_estimate_keys(&pcxt->estimator, 1);
493 }
#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 add_size(Size s1, Size s2)
Definition: shmem.c:493
Size pstate_len
Definition: execnodes.h:1450
shm_toc_estimator estimator
Definition: parallel.h:41

References add_size(), AppendState::as_nplans, ParallelContext::estimator, AppendState::pstate_len, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

◆ ExecAppendInitializeDSM()

void ExecAppendInitializeDSM ( AppendState node,
ParallelContext pcxt 
)

Definition at line 503 of file nodeAppend.c.

505 {
506  ParallelAppendState *pstate;
507 
508  pstate = shm_toc_allocate(pcxt->toc, node->pstate_len);
509  memset(pstate, 0, node->pstate_len);
511  shm_toc_insert(pcxt->toc, node->ps.plan->plan_node_id, pstate);
512 
513  node->as_pstate = pstate;
515 }
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:708
@ LWTRANCHE_PARALLEL_APPEND
Definition: lwlock.h:201
static bool choose_next_subplan_for_leader(AppendState *node)
Definition: nodeAppend.c:620
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
bool(* choose_next_subplan)(AppendState *)
Definition: execnodes.h:1455
PlanState ps
Definition: execnodes.h:1431
ParallelAppendState * as_pstate
Definition: execnodes.h:1449
shm_toc * toc
Definition: parallel.h:44
Plan * plan
Definition: execnodes.h:1116
int plan_node_id
Definition: plannodes.h:151

References AppendState::as_pstate, AppendState::choose_next_subplan, choose_next_subplan_for_leader(), LWLockInitialize(), LWTRANCHE_PARALLEL_APPEND, ParallelAppendState::pa_lock, PlanState::plan, Plan::plan_node_id, AppendState::ps, AppendState::pstate_len, shm_toc_allocate(), shm_toc_insert(), and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

◆ ExecAppendInitializeWorker()

void ExecAppendInitializeWorker ( AppendState node,
ParallelWorkerContext pwcxt 
)

Definition at line 540 of file nodeAppend.c.

541 {
542  node->as_pstate = shm_toc_lookup(pwcxt->toc, node->ps.plan->plan_node_id, false);
544 }
static bool choose_next_subplan_for_worker(AppendState *node)
Definition: nodeAppend.c:702
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

References AppendState::as_pstate, AppendState::choose_next_subplan, choose_next_subplan_for_worker(), PlanState::plan, Plan::plan_node_id, AppendState::ps, shm_toc_lookup(), and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecAppendReInitializeDSM()

void ExecAppendReInitializeDSM ( AppendState node,
ParallelContext pcxt 
)

Definition at line 524 of file nodeAppend.c.

525 {
526  ParallelAppendState *pstate = node->as_pstate;
527 
528  pstate->pa_next_plan = 0;
529  memset(pstate->pa_finished, 0, sizeof(bool) * node->as_nplans);
530 }
bool pa_finished[FLEXIBLE_ARRAY_MEMBER]
Definition: nodeAppend.c:80

References AppendState::as_nplans, AppendState::as_pstate, ParallelAppendState::pa_finished, and ParallelAppendState::pa_next_plan.

Referenced by ExecParallelReInitializeDSM().

◆ ExecAsyncAppendResponse()

void ExecAsyncAppendResponse ( AsyncRequest areq)

Definition at line 1105 of file nodeAppend.c.

1106 {
1107  AppendState *node = (AppendState *) areq->requestor;
1108  TupleTableSlot *slot = areq->result;
1109 
1110  /* The result should be a TupleTableSlot or NULL. */
1111  Assert(slot == NULL || IsA(slot, TupleTableSlot));
1112 
1113  /* Nothing to do if the request is pending. */
1114  if (!areq->request_complete)
1115  {
1116  /* The request would have been pending for a callback. */
1117  Assert(areq->callback_pending);
1118  return;
1119  }
1120 
1121  /* If the result is NULL or an empty slot, there's nothing more to do. */
1122  if (TupIsNull(slot))
1123  {
1124  /* The ending subplan wouldn't have been pending for a callback. */
1125  Assert(!areq->callback_pending);
1126  --node->as_nasyncremain;
1127  return;
1128  }
1129 
1130  /* Save result so we can return it. */
1131  Assert(node->as_nasyncresults < node->as_nasyncplans);
1132  node->as_asyncresults[node->as_nasyncresults++] = slot;
1133 
1134  /*
1135  * Mark the subplan that returned a result as ready for a new request. We
1136  * don't launch another one here immediately because it might complete.
1137  */
1139  areq->request_index);
1140 }
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
Bitmapset * as_needrequest
Definition: execnodes.h:1444
int as_nasyncresults
Definition: execnodes.h:1440
int as_nasyncremain
Definition: execnodes.h:1443
TupleTableSlot ** as_asyncresults
Definition: execnodes.h:1439
int as_nasyncplans
Definition: execnodes.h:1437
struct PlanState * requestor
Definition: execnodes.h:601
TupleTableSlot * result
Definition: execnodes.h:606
bool request_complete
Definition: execnodes.h:605
int request_index
Definition: execnodes.h:603
bool callback_pending
Definition: execnodes.h:604
#define TupIsNull(slot)
Definition: tuptable.h:306

References AppendState::as_asyncresults, AppendState::as_nasyncplans, AppendState::as_nasyncremain, AppendState::as_nasyncresults, AppendState::as_needrequest, Assert(), bms_add_member(), AsyncRequest::callback_pending, IsA, AsyncRequest::request_complete, AsyncRequest::request_index, AsyncRequest::requestor, AsyncRequest::result, and TupIsNull.

Referenced by ExecAsyncResponse().

◆ ExecEndAppend()

void ExecEndAppend ( AppendState node)

Definition at line 386 of file nodeAppend.c.

387 {
388  PlanState **appendplans;
389  int nplans;
390  int i;
391 
392  /*
393  * get information from the node
394  */
395  appendplans = node->appendplans;
396  nplans = node->as_nplans;
397 
398  /*
399  * shut down each of the subscans
400  */
401  for (i = 0; i < nplans; i++)
402  ExecEndNode(appendplans[i]);
403 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
int i
Definition: isn.c:73
PlanState ** appendplans
Definition: execnodes.h:1432

References AppendState::appendplans, AppendState::as_nplans, ExecEndNode(), and i.

Referenced by ExecEndNode().

◆ ExecInitAppend()

AppendState* ExecInitAppend ( Append node,
EState estate,
int  eflags 
)

Definition at line 109 of file nodeAppend.c.

110 {
111  AppendState *appendstate = makeNode(AppendState);
112  PlanState **appendplanstates;
113  Bitmapset *validsubplans;
114  Bitmapset *asyncplans;
115  int nplans;
116  int nasyncplans;
117  int firstvalid;
118  int i,
119  j;
120 
121  /* check for unsupported flags */
122  Assert(!(eflags & EXEC_FLAG_MARK));
123 
124  /*
125  * create new AppendState for our append node
126  */
127  appendstate->ps.plan = (Plan *) node;
128  appendstate->ps.state = estate;
129  appendstate->ps.ExecProcNode = ExecAppend;
130 
131  /* Let choose_next_subplan_* function handle setting the first subplan */
132  appendstate->as_whichplan = INVALID_SUBPLAN_INDEX;
133  appendstate->as_syncdone = false;
134  appendstate->as_begun = false;
135 
136  /* If run-time partition pruning is enabled, then set that up now */
137  if (node->part_prune_info != NULL)
138  {
139  PartitionPruneState *prunestate;
140 
141  /*
142  * Set up pruning data structure. This also initializes the set of
143  * subplans to initialize (validsubplans) by taking into account the
144  * result of performing initial pruning if any.
145  */
146  prunestate = ExecInitPartitionPruning(&appendstate->ps,
147  list_length(node->appendplans),
148  node->part_prune_info,
149  &validsubplans);
150  appendstate->as_prune_state = prunestate;
151  nplans = bms_num_members(validsubplans);
152 
153  /*
154  * When no run-time pruning is required and there's at least one
155  * subplan, we can fill as_valid_subplans immediately, preventing
156  * later calls to ExecFindMatchingSubPlans.
157  */
158  if (!prunestate->do_exec_prune && nplans > 0)
159  {
160  appendstate->as_valid_subplans = bms_add_range(NULL, 0, nplans - 1);
161  appendstate->as_valid_subplans_identified = true;
162  }
163  }
164  else
165  {
166  nplans = list_length(node->appendplans);
167 
168  /*
169  * When run-time partition pruning is not enabled we can just mark all
170  * subplans as valid; they must also all be initialized.
171  */
172  Assert(nplans > 0);
173  appendstate->as_valid_subplans = validsubplans =
174  bms_add_range(NULL, 0, nplans - 1);
175  appendstate->as_valid_subplans_identified = true;
176  appendstate->as_prune_state = NULL;
177  }
178 
179  /*
180  * Initialize result tuple type and slot.
181  */
182  ExecInitResultTupleSlotTL(&appendstate->ps, &TTSOpsVirtual);
183 
184  /* node returns slots from each of its subnodes, therefore not fixed */
185  appendstate->ps.resultopsset = true;
186  appendstate->ps.resultopsfixed = false;
187 
188  appendplanstates = (PlanState **) palloc(nplans *
189  sizeof(PlanState *));
190 
191  /*
192  * call ExecInitNode on each of the valid plans to be executed and save
193  * the results into the appendplanstates array.
194  *
195  * While at it, find out the first valid partial plan.
196  */
197  j = 0;
198  asyncplans = NULL;
199  nasyncplans = 0;
200  firstvalid = nplans;
201  i = -1;
202  while ((i = bms_next_member(validsubplans, i)) >= 0)
203  {
204  Plan *initNode = (Plan *) list_nth(node->appendplans, i);
205 
206  /*
207  * Record async subplans. When executing EvalPlanQual, we treat them
208  * as sync ones; don't do this when initializing an EvalPlanQual plan
209  * tree.
210  */
211  if (initNode->async_capable && estate->es_epq_active == NULL)
212  {
213  asyncplans = bms_add_member(asyncplans, j);
214  nasyncplans++;
215  }
216 
217  /*
218  * Record the lowest appendplans index which is a valid partial plan.
219  */
220  if (i >= node->first_partial_plan && j < firstvalid)
221  firstvalid = j;
222 
223  appendplanstates[j++] = ExecInitNode(initNode, estate, eflags);
224  }
225 
226  appendstate->as_first_partial_plan = firstvalid;
227  appendstate->appendplans = appendplanstates;
228  appendstate->as_nplans = nplans;
229 
230  /* Initialize async state */
231  appendstate->as_asyncplans = asyncplans;
232  appendstate->as_nasyncplans = nasyncplans;
233  appendstate->as_asyncrequests = NULL;
234  appendstate->as_asyncresults = NULL;
235  appendstate->as_nasyncresults = 0;
236  appendstate->as_nasyncremain = 0;
237  appendstate->as_needrequest = NULL;
238  appendstate->as_eventset = NULL;
239  appendstate->as_valid_asyncplans = NULL;
240 
241  if (nasyncplans > 0)
242  {
243  appendstate->as_asyncrequests = (AsyncRequest **)
244  palloc0(nplans * sizeof(AsyncRequest *));
245 
246  i = -1;
247  while ((i = bms_next_member(asyncplans, i)) >= 0)
248  {
249  AsyncRequest *areq;
250 
251  areq = palloc(sizeof(AsyncRequest));
252  areq->requestor = (PlanState *) appendstate;
253  areq->requestee = appendplanstates[i];
254  areq->request_index = i;
255  areq->callback_pending = false;
256  areq->request_complete = false;
257  areq->result = NULL;
258 
259  appendstate->as_asyncrequests[i] = areq;
260  }
261 
262  appendstate->as_asyncresults = (TupleTableSlot **)
263  palloc0(nasyncplans * sizeof(TupleTableSlot *));
264 
265  if (appendstate->as_valid_subplans_identified)
266  classify_matching_subplans(appendstate);
267  }
268 
269  /*
270  * Miscellaneous initialization
271  */
272 
273  appendstate->ps.ps_ProjInfo = NULL;
274 
275  /* For parallel query, this will be overridden later. */
277 
278  return appendstate;
279 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1306
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:751
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Definition: bitmapset.c:1019
PartitionPruneState * ExecInitPartitionPruning(PlanState *planstate, int n_total_subplans, PartitionPruneInfo *pruneinfo, Bitmapset **initially_valid_subplans)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1886
#define EXEC_FLAG_MARK
Definition: executor.h:69
int j
Definition: isn.c:74
void * palloc0(Size size)
Definition: mcxt.c:1334
void * palloc(Size size)
Definition: mcxt.c:1304
static void classify_matching_subplans(AppendState *node)
Definition: nodeAppend.c:1151
static TupleTableSlot * ExecAppend(PlanState *pstate)
Definition: nodeAppend.c:288
#define INVALID_SUBPLAN_INDEX
Definition: nodeAppend.c:83
static bool choose_next_subplan_locally(AppendState *node)
Definition: nodeAppend.c:554
#define makeNode(_type_)
Definition: nodes.h:155
static int list_length(const List *l)
Definition: pg_list.h:152
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
struct PartitionPruneState * as_prune_state
Definition: execnodes.h:1451
Bitmapset * as_valid_asyncplans
Definition: execnodes.h:1454
bool as_syncdone
Definition: execnodes.h:1441
AsyncRequest ** as_asyncrequests
Definition: execnodes.h:1438
bool as_begun
Definition: execnodes.h:1435
Bitmapset * as_asyncplans
Definition: execnodes.h:1436
int as_whichplan
Definition: execnodes.h:1434
struct WaitEventSet * as_eventset
Definition: execnodes.h:1445
int as_first_partial_plan
Definition: execnodes.h:1447
Bitmapset * as_valid_subplans
Definition: execnodes.h:1453
bool as_valid_subplans_identified
Definition: execnodes.h:1452
int first_partial_plan
Definition: plannodes.h:274
struct PartitionPruneInfo * part_prune_info
Definition: plannodes.h:277
List * appendplans
Definition: plannodes.h:267
struct PlanState * requestee
Definition: execnodes.h:602
struct EPQState * es_epq_active
Definition: execnodes.h:697
bool resultopsset
Definition: execnodes.h:1201
EState * state
Definition: execnodes.h:1118
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1156
bool resultopsfixed
Definition: execnodes.h:1197
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1122
bool async_capable
Definition: plannodes.h:146

References AppendState::appendplans, Append::appendplans, AppendState::as_asyncplans, AppendState::as_asyncrequests, AppendState::as_asyncresults, AppendState::as_begun, AppendState::as_eventset, AppendState::as_first_partial_plan, AppendState::as_nasyncplans, AppendState::as_nasyncremain, AppendState::as_nasyncresults, AppendState::as_needrequest, AppendState::as_nplans, AppendState::as_prune_state, AppendState::as_syncdone, AppendState::as_valid_asyncplans, AppendState::as_valid_subplans, AppendState::as_valid_subplans_identified, AppendState::as_whichplan, Assert(), Plan::async_capable, bms_add_member(), bms_add_range(), bms_next_member(), bms_num_members(), AsyncRequest::callback_pending, AppendState::choose_next_subplan, choose_next_subplan_locally(), classify_matching_subplans(), PartitionPruneState::do_exec_prune, EState::es_epq_active, EXEC_FLAG_MARK, ExecAppend(), ExecInitNode(), ExecInitPartitionPruning(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, Append::first_partial_plan, i, INVALID_SUBPLAN_INDEX, j, list_length(), list_nth(), makeNode, palloc(), palloc0(), Append::part_prune_info, PlanState::plan, AppendState::ps, PlanState::ps_ProjInfo, AsyncRequest::request_complete, AsyncRequest::request_index, AsyncRequest::requestee, AsyncRequest::requestor, AsyncRequest::result, PlanState::resultopsfixed, PlanState::resultopsset, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanAppend()

void ExecReScanAppend ( AppendState node)

Definition at line 406 of file nodeAppend.c.

407 {
408  int nasyncplans = node->as_nasyncplans;
409  int i;
410 
411  /*
412  * If any PARAM_EXEC Params used in pruning expressions have changed, then
413  * we'd better unset the valid subplans so that they are reselected for
414  * the new parameter values.
415  */
416  if (node->as_prune_state &&
417  bms_overlap(node->ps.chgParam,
419  {
420  node->as_valid_subplans_identified = false;
422  node->as_valid_subplans = NULL;
424  node->as_valid_asyncplans = NULL;
425  }
426 
427  for (i = 0; i < node->as_nplans; i++)
428  {
429  PlanState *subnode = node->appendplans[i];
430 
431  /*
432  * ExecReScan doesn't know about my subplans, so I have to do
433  * changed-parameter signaling myself.
434  */
435  if (node->ps.chgParam != NULL)
436  UpdateChangedParamSet(subnode, node->ps.chgParam);
437 
438  /*
439  * If chgParam of subnode is not null then plan will be re-scanned by
440  * first ExecProcNode or by first ExecAsyncRequest.
441  */
442  if (subnode->chgParam == NULL)
443  ExecReScan(subnode);
444  }
445 
446  /* Reset async state */
447  if (nasyncplans > 0)
448  {
449  i = -1;
450  while ((i = bms_next_member(node->as_asyncplans, i)) >= 0)
451  {
452  AsyncRequest *areq = node->as_asyncrequests[i];
453 
454  areq->callback_pending = false;
455  areq->request_complete = false;
456  areq->result = NULL;
457  }
458 
459  node->as_nasyncresults = 0;
460  node->as_nasyncremain = 0;
461  bms_free(node->as_needrequest);
462  node->as_needrequest = NULL;
463  }
464 
465  /* Let choose_next_subplan_* function handle setting the first subplan */
467  node->as_syncdone = false;
468  node->as_begun = false;
469 }
void bms_free(Bitmapset *a)
Definition: bitmapset.c:239
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:582
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:844
Bitmapset * execparamids
Bitmapset * chgParam
Definition: execnodes.h:1148

References AppendState::appendplans, AppendState::as_asyncplans, AppendState::as_asyncrequests, AppendState::as_begun, AppendState::as_nasyncplans, AppendState::as_nasyncremain, AppendState::as_nasyncresults, AppendState::as_needrequest, AppendState::as_nplans, AppendState::as_prune_state, AppendState::as_syncdone, AppendState::as_valid_asyncplans, AppendState::as_valid_subplans, AppendState::as_valid_subplans_identified, AppendState::as_whichplan, bms_free(), bms_next_member(), bms_overlap(), AsyncRequest::callback_pending, PlanState::chgParam, PartitionPruneState::execparamids, ExecReScan(), i, INVALID_SUBPLAN_INDEX, AppendState::ps, AsyncRequest::request_complete, AsyncRequest::result, and UpdateChangedParamSet().

Referenced by ExecReScan().