PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 
)
extern

Definition at line 500 of file nodeAppend.c.

502{
503 node->pstate_len =
505 sizeof(bool) * node->as_nplans);
506
509}
static int fb(int x)
#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:482
Size pstate_len
Definition execnodes.h:1518
shm_toc_estimator estimator
Definition parallel.h:43

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

Referenced by ExecParallelEstimate().

◆ ExecAppendInitializeDSM()

void ExecAppendInitializeDSM ( AppendState node,
ParallelContext pcxt 
)
extern

Definition at line 519 of file nodeAppend.c.

521{
522 ParallelAppendState *pstate;
523
524 pstate = shm_toc_allocate(pcxt->toc, node->pstate_len);
525 memset(pstate, 0, node->pstate_len);
527 shm_toc_insert(pcxt->toc, node->ps.plan->plan_node_id, pstate);
528
529 node->as_pstate = pstate;
531}
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition lwlock.c:698
static bool choose_next_subplan_for_leader(AppendState *node)
Definition nodeAppend.c:636
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
bool(* choose_next_subplan)(AppendState *)
Definition execnodes.h:1523
PlanState ps
Definition execnodes.h:1499
ParallelAppendState * as_pstate
Definition execnodes.h:1517
shm_toc * toc
Definition parallel.h:46
Plan * plan
Definition execnodes.h:1168
int plan_node_id
Definition plannodes.h:233

References AppendState::as_pstate, AppendState::choose_next_subplan, choose_next_subplan_for_leader(), fb(), LWLockInitialize(), 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 
)
extern

Definition at line 556 of file nodeAppend.c.

557{
558 node->as_pstate = shm_toc_lookup(pwcxt->toc, node->ps.plan->plan_node_id, false);
560}
static bool choose_next_subplan_for_worker(AppendState *node)
Definition nodeAppend.c:718
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(), fb(), PlanState::plan, Plan::plan_node_id, AppendState::ps, and shm_toc_lookup().

Referenced by ExecParallelInitializeWorker().

◆ ExecAppendReInitializeDSM()

void ExecAppendReInitializeDSM ( AppendState node,
ParallelContext pcxt 
)
extern

Definition at line 540 of file nodeAppend.c.

541{
542 ParallelAppendState *pstate = node->as_pstate;
543
544 pstate->pa_next_plan = 0;
545 memset(pstate->pa_finished, 0, sizeof(bool) * node->as_nplans);
546}
bool pa_finished[FLEXIBLE_ARRAY_MEMBER]
Definition nodeAppend.c:81

References AppendState::as_nplans, AppendState::as_pstate, fb(), ParallelAppendState::pa_finished, and ParallelAppendState::pa_next_plan.

Referenced by ExecParallelReInitializeDSM().

◆ ExecAsyncAppendResponse()

void ExecAsyncAppendResponse ( AsyncRequest areq)
extern

Definition at line 1143 of file nodeAppend.c.

1144{
1145 AppendState *node = (AppendState *) areq->requestor;
1146 TupleTableSlot *slot = areq->result;
1147
1148 /* The result should be a TupleTableSlot or NULL. */
1149 Assert(slot == NULL || IsA(slot, TupleTableSlot));
1150
1151 /* Nothing to do if the request is pending. */
1152 if (!areq->request_complete)
1153 {
1154 /* The request would have been pending for a callback. */
1155 Assert(areq->callback_pending);
1156 return;
1157 }
1158
1159 /* If the result is NULL or an empty slot, there's nothing more to do. */
1160 if (TupIsNull(slot))
1161 {
1162 /* The ending subplan wouldn't have been pending for a callback. */
1163 Assert(!areq->callback_pending);
1164 --node->as_nasyncremain;
1165 return;
1166 }
1167
1168 /* Save result so we can return it. */
1169 Assert(node->as_nasyncresults < node->as_nasyncplans);
1170 node->as_asyncresults[node->as_nasyncresults++] = slot;
1171
1172 /*
1173 * Mark the subplan that returned a result as ready for a new request. We
1174 * don't launch another one here immediately because it might complete.
1175 */
1176 node->as_needrequest = bms_add_member(node->as_needrequest,
1177 areq->request_index);
1178}
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:799
#define Assert(condition)
Definition c.h:885
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define TupIsNull(slot)
Definition tuptable.h:309

References AppendState::as_asyncresults, AppendState::as_nasyncplans, AppendState::as_nasyncremain, AppendState::as_nasyncresults, AppendState::as_needrequest, Assert, bms_add_member(), fb(), IsA, and TupIsNull.

Referenced by ExecAsyncResponse().

◆ ExecEndAppend()

void ExecEndAppend ( AppendState node)
extern

Definition at line 402 of file nodeAppend.c.

403{
404 PlanState **appendplans;
405 int nplans;
406 int i;
407
408 /*
409 * get information from the node
410 */
411 appendplans = node->appendplans;
412 nplans = node->as_nplans;
413
414 /*
415 * shut down each of the subscans
416 */
417 for (i = 0; i < nplans; i++)
418 ExecEndNode(appendplans[i]);
419}
void ExecEndNode(PlanState *node)
int i
Definition isn.c:77
PlanState ** appendplans
Definition execnodes.h:1500

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

Referenced by ExecEndNode().

◆ ExecInitAppend()

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

Definition at line 110 of file nodeAppend.c.

111{
117 int nplans;
118 int nasyncplans;
119 int firstvalid;
120 int i,
121 j;
122
123 /* check for unsupported flags */
124 Assert(!(eflags & EXEC_FLAG_MARK));
125
126 /*
127 * create new AppendState for our append node
128 */
129 appendstate->ps.plan = (Plan *) node;
130 appendstate->ps.state = estate;
131 appendstate->ps.ExecProcNode = ExecAppend;
132
133 /* Let choose_next_subplan_* function handle setting the first subplan */
134 appendstate->as_whichplan = INVALID_SUBPLAN_INDEX;
135 appendstate->as_syncdone = false;
136 appendstate->as_begun = false;
137
138 /* If run-time partition pruning is enabled, then set that up now */
139 if (node->part_prune_index >= 0)
140 {
142
143 /*
144 * Set up pruning data structure. This also initializes the set of
145 * subplans to initialize (validsubplans) by taking into account the
146 * result of performing initial pruning if any.
147 */
150 node->part_prune_index,
151 node->apprelids,
153 appendstate->as_prune_state = prunestate;
155
156 /*
157 * When no run-time pruning is required and there's at least one
158 * subplan, we can fill as_valid_subplans immediately, preventing
159 * later calls to ExecFindMatchingSubPlans.
160 */
161 if (!prunestate->do_exec_prune && nplans > 0)
162 {
163 appendstate->as_valid_subplans = bms_add_range(NULL, 0, nplans - 1);
164 appendstate->as_valid_subplans_identified = true;
165 }
166 }
167 else
168 {
169 nplans = list_length(node->appendplans);
170
171 /*
172 * When run-time partition pruning is not enabled we can just mark all
173 * subplans as valid; they must also all be initialized.
174 */
175 Assert(nplans > 0);
176 appendstate->as_valid_subplans = validsubplans =
177 bms_add_range(NULL, 0, nplans - 1);
178 appendstate->as_valid_subplans_identified = true;
179 appendstate->as_prune_state = NULL;
180 }
181
182 appendplanstates = (PlanState **) palloc(nplans *
183 sizeof(PlanState *));
184
185 /*
186 * call ExecInitNode on each of the valid plans to be executed and save
187 * the results into the appendplanstates array.
188 *
189 * While at it, find out the first valid partial plan.
190 */
191 j = 0;
193 nasyncplans = 0;
194 firstvalid = nplans;
195 i = -1;
196 while ((i = bms_next_member(validsubplans, i)) >= 0)
197 {
198 Plan *initNode = (Plan *) list_nth(node->appendplans, i);
199
200 /*
201 * Record async subplans. When executing EvalPlanQual, we treat them
202 * as sync ones; don't do this when initializing an EvalPlanQual plan
203 * tree.
204 */
205 if (initNode->async_capable && estate->es_epq_active == NULL)
206 {
208 nasyncplans++;
209 }
210
211 /*
212 * Record the lowest appendplans index which is a valid partial plan.
213 */
214 if (i >= node->first_partial_plan && j < firstvalid)
215 firstvalid = j;
216
217 appendplanstates[j++] = ExecInitNode(initNode, estate, eflags);
218 }
219
220 appendstate->as_first_partial_plan = firstvalid;
221 appendstate->appendplans = appendplanstates;
222 appendstate->as_nplans = nplans;
223
224 /*
225 * Initialize Append's result tuple type and slot. If the child plans all
226 * produce the same fixed slot type, we can use that slot type; otherwise
227 * make a virtual slot. (Note that the result slot itself is used only to
228 * return a null tuple at end of execution; real tuples are returned to
229 * the caller in the children's own result slots. What we are doing here
230 * is allowing the parent plan node to optimize if the Append will return
231 * only one kind of slot.)
232 */
234 if (appendops != NULL)
235 {
237 }
238 else
239 {
241 /* show that the output slot type is not fixed */
242 appendstate->ps.resultopsset = true;
243 appendstate->ps.resultopsfixed = false;
244 }
245
246 /* Initialize async state */
247 appendstate->as_asyncplans = asyncplans;
248 appendstate->as_nasyncplans = nasyncplans;
249 appendstate->as_asyncrequests = NULL;
250 appendstate->as_asyncresults = NULL;
251 appendstate->as_nasyncresults = 0;
252 appendstate->as_nasyncremain = 0;
253 appendstate->as_needrequest = NULL;
254 appendstate->as_eventset = NULL;
255 appendstate->as_valid_asyncplans = NULL;
256
257 if (nasyncplans > 0)
258 {
259 appendstate->as_asyncrequests = (AsyncRequest **)
260 palloc0(nplans * sizeof(AsyncRequest *));
261
262 i = -1;
263 while ((i = bms_next_member(asyncplans, i)) >= 0)
264 {
266
268 areq->requestor = (PlanState *) appendstate;
269 areq->requestee = appendplanstates[i];
270 areq->request_index = i;
271 areq->callback_pending = false;
272 areq->request_complete = false;
273 areq->result = NULL;
274
275 appendstate->as_asyncrequests[i] = areq;
276 }
277
278 appendstate->as_asyncresults = (TupleTableSlot **)
279 palloc0(nasyncplans * sizeof(TupleTableSlot *));
280
281 if (appendstate->as_valid_subplans_identified)
283 }
284
285 /*
286 * Miscellaneous initialization
287 */
288
289 appendstate->ps.ps_ProjInfo = NULL;
290
291 /* For parallel query, this will be overridden later. */
292 appendstate->choose_next_subplan = choose_next_subplan_locally;
293
294 return appendstate;
295}
int bms_next_member(const Bitmapset *a, int prevbit)
Definition bitmapset.c:1290
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Definition bitmapset.c:1003
int bms_num_members(const Bitmapset *a)
Definition bitmapset.c:744
PartitionPruneState * ExecInitPartitionExecPruning(PlanState *planstate, int n_total_subplans, int part_prune_index, Bitmapset *relids, Bitmapset **initially_valid_subplans)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
const TupleTableSlotOps * ExecGetCommonSlotOps(PlanState **planstates, int nplans)
Definition execUtils.c:536
#define EXEC_FLAG_MARK
Definition executor.h:70
#define palloc_object(type)
Definition fe_memutils.h:74
int j
Definition isn.c:78
void * palloc0(Size size)
Definition mcxt.c:1417
void * palloc(Size size)
Definition mcxt.c:1387
static void classify_matching_subplans(AppendState *node)
static TupleTableSlot * ExecAppend(PlanState *pstate)
Definition nodeAppend.c:304
#define INVALID_SUBPLAN_INDEX
Definition nodeAppend.c:84
static bool choose_next_subplan_locally(AppendState *node)
Definition nodeAppend.c:570
#define makeNode(_type_)
Definition nodes.h:161
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
int first_partial_plan
Definition plannodes.h:416
int part_prune_index
Definition plannodes.h:423
Bitmapset * apprelids
Definition plannodes.h:401
List * appendplans
Definition plannodes.h:407
struct EPQState * es_epq_active
Definition execnodes.h:745

References Append::appendplans, Append::apprelids, Assert, bms_add_member(), bms_add_range(), bms_next_member(), bms_num_members(), choose_next_subplan_locally(), classify_matching_subplans(), EState::es_epq_active, EXEC_FLAG_MARK, ExecAppend(), ExecGetCommonSlotOps(), ExecInitNode(), ExecInitPartitionExecPruning(), ExecInitResultTupleSlotTL(), fb(), Append::first_partial_plan, i, INVALID_SUBPLAN_INDEX, j, list_length(), list_nth(), makeNode, palloc(), palloc0(), palloc_object, Append::part_prune_index, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanAppend()

void ExecReScanAppend ( AppendState node)
extern

Definition at line 422 of file nodeAppend.c.

423{
424 int nasyncplans = node->as_nasyncplans;
425 int i;
426
427 /*
428 * If any PARAM_EXEC Params used in pruning expressions have changed, then
429 * we'd better unset the valid subplans so that they are reselected for
430 * the new parameter values.
431 */
432 if (node->as_prune_state &&
433 bms_overlap(node->ps.chgParam,
435 {
436 node->as_valid_subplans_identified = false;
438 node->as_valid_subplans = NULL;
441 }
442
443 for (i = 0; i < node->as_nplans; i++)
444 {
445 PlanState *subnode = node->appendplans[i];
446
447 /*
448 * ExecReScan doesn't know about my subplans, so I have to do
449 * changed-parameter signaling myself.
450 */
451 if (node->ps.chgParam != NULL)
453
454 /*
455 * If chgParam of subnode is not null then plan will be re-scanned by
456 * first ExecProcNode or by first ExecAsyncRequest.
457 */
458 if (subnode->chgParam == NULL)
460 }
461
462 /* Reset async state */
463 if (nasyncplans > 0)
464 {
465 i = -1;
466 while ((i = bms_next_member(node->as_asyncplans, i)) >= 0)
467 {
469
470 areq->callback_pending = false;
471 areq->request_complete = false;
472 areq->result = NULL;
473 }
474
475 node->as_nasyncresults = 0;
476 node->as_nasyncremain = 0;
478 node->as_needrequest = NULL;
479 }
480
481 /* Let choose_next_subplan_* function handle setting the first subplan */
483 node->as_syncdone = false;
484 node->as_begun = false;
485}
void bms_free(Bitmapset *a)
Definition bitmapset.c:239
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:575
void ExecReScan(PlanState *node)
Definition execAmi.c:77
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition execUtils.c:910
struct PartitionPruneState * as_prune_state
Definition execnodes.h:1519
Bitmapset * as_valid_asyncplans
Definition execnodes.h:1522
Bitmapset * as_needrequest
Definition execnodes.h:1512
bool as_syncdone
Definition execnodes.h:1509
AsyncRequest ** as_asyncrequests
Definition execnodes.h:1506
Bitmapset * as_asyncplans
Definition execnodes.h:1504
int as_nasyncresults
Definition execnodes.h:1508
int as_nasyncremain
Definition execnodes.h:1511
Bitmapset * as_valid_subplans
Definition execnodes.h:1521
int as_nasyncplans
Definition execnodes.h:1505
bool as_valid_subplans_identified
Definition execnodes.h:1520
bool callback_pending
Definition execnodes.h:645
Bitmapset * execparamids
Bitmapset * chgParam
Definition execnodes.h:1200

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(), fb(), i, INVALID_SUBPLAN_INDEX, AppendState::ps, and UpdateChangedParamSet().

Referenced by ExecReScan().